Skip to content

Commit

Permalink
add test for #168 and #232, expand e2e dependencies test
Browse files Browse the repository at this point in the history
  • Loading branch information
NyxCode committed Feb 23, 2024
1 parent 2b7d25b commit 9043961
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
11 changes: 11 additions & 0 deletions e2e/dependencies/consumer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ struct ConsumerType {
pub ty2_5: LibraryType2<LibraryType3>,
}

#[derive(TS)]
#[ts(export)]
struct T0;

#[derive(TS)]
#[ts(export)]
struct T1 {
t0: Option<T0>
}


fn main() {}
50 changes: 50 additions & 0 deletions ts-rs/tests/issue-168.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![allow(unused)]

use std::collections::HashMap;
use ts_rs::TS;

#[derive(TS)]
#[ts(export)]
pub struct Foo {
map: HashMap<usize, Bar>,
}

#[derive(TS)]
#[ts(export)]
pub struct FooInlined {
#[ts(inline)]
map: HashMap<usize, Bar>,
}

#[derive(TS)]
#[ts(export)]
struct Bar {
#[ts(inline)]
map: HashMap<usize, Baz>,
}

#[derive(TS)]
#[ts(export)]
struct Baz {
#[ts(inline)]
map: HashMap<usize, String>,
}


#[test]
#[ignore]
fn issue_168() {
assert_eq!(
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: Record<number, { map: Record<number, { map: Record<number, string>, }>, }>, };"
);
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: Record<number, Bar>, };"
);
}
67 changes: 67 additions & 0 deletions ts-rs/tests/issue-232.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#![allow(unused)]

use ts_rs::TS;

#[derive(TS)]
#[ts(export)]
struct State {
a: Result<EnumWithName, String>,
b: Result<EnumWithName, String>,
}

#[derive(TS)]
#[ts(export)]
struct StateInlined {
#[ts(inline)]
a: Result<EnumWithName, String>,
#[ts(inline)]
b: Result<EnumWithName, String>,
}

#[derive(TS)]
#[ts(export)]
struct StateInlinedVec {
#[ts(inline)]
a: Vec<Result<EnumWithName, String>>,
#[ts(inline)]
b: Vec<Result<EnumWithName, String>>,
}

#[derive(TS)]
#[ts(export)]
struct EnumWithName {
name: String,
inner: Enum
}

#[derive(TS)]
#[ts(export)]
enum Enum {
A,
B
}

#[test]
fn issue_232() {
println!("{}", StateInlinedVec::export_to_string().unwrap());
assert_eq!(
StateInlined::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 { Enum } from \"./Enum\";\n\
\n\
export type StateInlined = { \
a: { Ok : { name: string, inner: Enum, } } | { Err : string }, \
b: { Ok : { name: string, inner: Enum, } } | { Err : string }, \
};"
);
assert_eq!(
State::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 { EnumWithName } from \"./EnumWithName\";\n\
\n\
export type State = { \
a: { Ok : EnumWithName } | { Err : string }, \
b: { Ok : EnumWithName } | { Err : string }, \
};"
);
}

0 comments on commit 9043961

Please sign in to comment.