Skip to content

Commit

Permalink
add test for #70
Browse files Browse the repository at this point in the history
  • Loading branch information
NyxCode committed Feb 16, 2024
1 parent 83b9541 commit 61c9692
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions ts-rs/tests/issue-70.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![allow(unused)]

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

#[test]
fn issue_70() {
type TypeAlias = HashMap<String, String>;

#[derive(TS)]
enum Enum {
A(TypeAlias),
B(HashMap<String, String>),
}

#[derive(TS)]
struct Struct {
a: TypeAlias,
b: HashMap<String, String>
}

assert_eq!(Enum::decl(), "type Enum = { \"A\": Record<string, string> } | { \"B\": Record<string, string> };");
assert_eq!(Struct::decl(), "type Struct = { a: Record<string, string>, b: Record<string, string>, };");
}

#[test]
fn generic() {
type GenericAlias<A = String, B = String> = HashMap<(A, String), Vec<(B, i32)>>;

#[derive(TS)]
struct Container {
a: GenericAlias<Vec<i32>, Vec<String>>,
b: GenericAlias
}
assert_eq!(
Container::decl(),
"type Container = { \
a: Record<[Array<number>, string], Array<[Array<string>, number]>>, \
b: Record<[string, string], Array<[string, number]>>, \
};"
);

#[derive(TS)]
struct GenericContainer<A, B = i32> {
a: GenericAlias,
b: GenericAlias<A, B>,
c: GenericAlias<A, GenericAlias<A, B>>
}
assert_eq!(
GenericContainer::<(), ()>::decl(),
"type GenericContainer<A, B = number> = { \
a: Record<[string, string], Array<[string, number]>>, \
b: Record<[A, string], Array<[B, number]>>, \
c: Record<[A, string], Array<[Record<[A, string], Array<[B, number]>>, number]>>, \
};"
);
}

0 comments on commit 61c9692

Please sign in to comment.