#![allow(dead_code)] use std::{concat, fs}; use ts_rs::{Config, TS}; #[derive(TS)] #[ts(export_to = "export_manually/UserFile.ts")] struct User { name: String, age: i32, active: bool, } #[derive(TS)] #[ts(export_to = "export_manually/dir/")] struct UserDir { name: String, age: i32, active: bool, } #[test] fn export_manually() { let cfg = Config::from_env(); User::export(&cfg).unwrap(); let expected_content = if cfg!(feature = "format") { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", "export type User = { name: string; age: number; active: boolean };\n", ) } else { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "\nexport type User = { name: string, age: number, active: boolean, };", "\n", ) }; let actual_content = super::read_file::(&cfg); assert_eq!(actual_content, expected_content); } #[test] fn export_manually_dir() { let cfg = Config::from_env(); UserDir::export(&cfg).unwrap(); let expected_content = if cfg!(feature = "format") { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", "export type UserDir = { name: string; age: number; active: boolean };\n", ) } else { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "\nexport type UserDir = { name: string, age: number, active: boolean, };", "\n", ) }; let actual_content = super::read_file::(&cfg); assert_eq!(actual_content, expected_content); }