Add tests for all impl_shadow! types

This commit is contained in:
Moritz Bischof
2024-02-29 15:59:36 +01:00
parent 22a8edc5c2
commit ed397dad28
3 changed files with 77 additions and 1 deletions
+34 -1
View File
@@ -1,5 +1,6 @@
#![allow(dead_code)]
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use ts_rs::TS;
@@ -37,3 +38,35 @@ fn hashmap_with_custom_hasher() {
"type HashesHasher = { map: Record<string, string>, set: Array<string>, };"
)
}
#[derive(TS, Eq, PartialEq, Hash)]
#[ts(export, export_to = "tests-out/hashmap/")]
struct CustomKey;
#[derive(TS)]
#[ts(export, export_to = "tests-out/hashmap/")]
struct CustomValue;
#[derive(TS)]
#[ts(export, export_to = "tests-out/hashmap/")]
struct HashMapWithCustomTypes {
map: HashMap<CustomKey, CustomValue>,
}
#[derive(TS)]
#[ts(export, export_to = "tests-out/hashmap/")]
struct BTreeMapWithCustomTypes {
map: BTreeMap<CustomKey, CustomValue>,
}
#[test]
fn with_custom_types() {
assert_eq!(
HashMapWithCustomTypes::inline(),
BTreeMapWithCustomTypes::inline()
);
assert_eq!(
HashMapWithCustomTypes::decl(),
"type HashMapWithCustomTypes = { map: Record<CustomKey, CustomValue>, };"
);
}
+33
View File
@@ -0,0 +1,33 @@
#![allow(dead_code)]
use std::collections::{BTreeSet, HashSet};
use ts_rs::TS;
#[derive(TS, Eq, PartialEq, Hash)]
#[ts(export, export_to = "tests-out/hashset/")]
struct CustomValue;
#[derive(TS)]
#[ts(export, export_to = "tests-out/hashset/")]
struct HashSetWithCustomType {
set: HashSet<CustomValue>,
}
#[derive(TS)]
#[ts(export, export_to = "tests-out/hashset/")]
struct BTreeSetWithCustomType {
set: BTreeSet<CustomValue>,
}
#[test]
fn with_custom_types() {
assert_eq!(
HashSetWithCustomType::inline(),
BTreeSetWithCustomType::inline()
);
assert_eq!(
HashSetWithCustomType::decl(),
"type HashSetWithCustomType = { set: Array<CustomValue>, };"
);
}
+10
View File
@@ -1,3 +1,5 @@
#![allow(unused)]
use ts_rs::TS;
#[test]
@@ -66,3 +68,11 @@ struct NewtypeBoxed(#[allow(dead_code)] Box<[i32]>);
fn boxed_newtype() {
assert_eq!(NewtypeBoxed::inline(), "Array<number>")
}
#[derive(TS)]
#[ts(export, export_to = "tests-out/slices/nested/")]
struct InnerMost;
#[derive(TS)]
#[ts(export, export_to = "tests-out/slices/nested/")]
struct Nested<'a>(&'a [InnerMost]);