Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert newline at end of generated files #321

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub(crate) fn export_to_string<T: TS + ?Sized + 'static>() -> Result<String, Exp
buffer.push_str(NOTE);
generate_imports::<T::WithoutGenerics>(&mut buffer, default_out_dir())?;
generate_decl::<T>(&mut buffer);
buffer.push('\n');
Ok(buffer)
}

Expand Down
27 changes: 17 additions & 10 deletions ts-rs/tests/integration/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ fn export_a() {
" *\n",
" * Testing\n",
" */\n",
"name: string, };"
"name: string, };",
"\n",
)
};

Expand Down Expand Up @@ -179,6 +180,7 @@ fn export_b() {
" * Testing\n",
" */\n",
"name: string, };",
"\n",
)
};

Expand All @@ -200,7 +202,7 @@ fn export_c() {
" *\n",
" * Testing\n",
" */\n",
"export type C = Record<string, never>;\n"
"export type C = Record<string, never>;\n",
)
} else {
concat!(
Expand All @@ -211,7 +213,8 @@ fn export_c() {
" *\n",
" * Testing\n",
" */\n",
"export type C = Record<string, never>;"
"export type C = Record<string, never>;",
"\n",
)
};

Expand All @@ -233,7 +236,7 @@ fn export_d() {
" *\n",
" * Testing\n",
" */\n",
"export type D = null;\n"
"export type D = null;\n",
)
} else {
concat!(
Expand All @@ -244,7 +247,8 @@ fn export_d() {
" *\n",
" * Testing\n",
" */\n",
"export type D = null;"
"export type D = null;",
"\n",
)
};
let actual_content = fs::read_to_string(D::default_output_path().unwrap()).unwrap();
Expand All @@ -265,7 +269,7 @@ fn export_e() {
" *\n",
" * Testing\n",
" */\n",
"export type E = never;\n"
"export type E = never;\n",
)
} else {
concat!(
Expand All @@ -276,7 +280,8 @@ fn export_e() {
" *\n",
" * Testing\n",
" */\n",
"export type E = never;"
"export type E = never;",
"\n",
)
};

Expand Down Expand Up @@ -307,7 +312,7 @@ fn export_f() {
" */\n",
" variant_field: number;\n",
" };\n",
"};\n"
"};\n",
)
} else {
concat!(
Expand All @@ -324,7 +329,8 @@ fn export_f() {
" *\n",
" * Testing\n",
" */\n",
"variant_field: number, } };"
"variant_field: number, } };",
"\n",
)
};

Expand Down Expand Up @@ -356,7 +362,7 @@ fn export_g() {
" */\n",
" variant_field: number;\n",
" };\n",
" });\n"
" });\n",
)
} else {
concat!(
Expand All @@ -373,6 +379,7 @@ fn export_g() {
" * Testing\n",
" */\n",
"variant_field: number, } });",
"\n",
)
};

Expand Down
10 changes: 6 additions & 4 deletions ts-rs/tests/integration/export_manually.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ fn export_manually() {
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"
"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, };"
"\nexport type User = { name: string, age: number, active: boolean, };",
"\n",
)
};

Expand All @@ -48,12 +49,13 @@ fn export_manually_dir() {
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"
"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, };"
"\nexport type UserDir = { name: string, age: number, active: boolean, };",
"\n",
)
};

Expand Down
12 changes: 6 additions & 6 deletions ts-rs/tests/integration/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ fn test_def() {
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number> } } | {\n",
" \"A1\": { value: TestTypeA<number> };\n",
"} | { \"A2\": { value: TestTypeA<number> } };\n"

"} | { \"A2\": { value: TestTypeA<number> } };\n",
),
(true, false) => concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
Expand All @@ -46,22 +45,23 @@ fn test_def() {
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number> } } | {\n",
" \"A1\": { value: TestTypeA<number> };\n",
"} | { \"A2\": { value: TestTypeA<number> } };\n"

"} | { \"A2\": { value: TestTypeA<number> } };\n",
),
(false, true) => concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"import type { TestTypeA } from \"./ts_rs_test_type_a.js\";\n",
"import type { TestTypeB } from \"./ts_rs_test_type_b.js\";\n",
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };"
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };",
"\n",
),
(false, false) => concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"import type { TestTypeA } from \"./ts_rs_test_type_a\";\n",
"import type { TestTypeB } from \"./ts_rs_test_type_b\";\n",
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };"
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };",
"\n",
),
};

Expand Down
4 changes: 2 additions & 2 deletions ts-rs/tests/integration/issue_168.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ fn issue_168() {
FooInlined::export_to_string().unwrap(),
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\
\n\
export type FooInlined = { map: { [key: number]: { map: { [key: number]: { map: { [key: number]: string }, } }, } }, };"
export type FooInlined = { map: { [key: number]: { map: { [key: number]: { map: { [key: number]: string }, } }, } }, };\n"
);
assert_eq!(
Foo::export_to_string().unwrap(),
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\
import type { Bar } from \"./Bar\";\n\
\n\
export type Foo = { map: { [key: number]: Bar }, };"
export type Foo = { map: { [key: number]: Bar }, };\n"
);
}
4 changes: 2 additions & 2 deletions ts-rs/tests/integration/issue_232.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn issue_232() {
export type StateInlined = { \
a: { Ok : { name: string, inner: Enum, } } | { Err : string }, \
b: { Ok : { name: string, inner: Enum, } } | { Err : string }, \
};"
};\n"
);
assert_eq!(
State::export_to_string().unwrap(),
Expand All @@ -63,6 +63,6 @@ fn issue_232() {
export type State = { \
a: { Ok : EnumWithName } | { Err : string }, \
b: { Ok : EnumWithName } | { Err : string }, \
};"
};\n"
);
}