From ed397dad28bbdd30811505cb6033fa2eeb8656d8 Mon Sep 17 00:00:00 2001 From: Moritz Bischof Date: Thu, 29 Feb 2024 15:59:36 +0100 Subject: [PATCH] Add tests for all impl_shadow! types --- ts-rs/tests/hashmap.rs | 35 ++++++++++++++++++++++++++++++++++- ts-rs/tests/hashset.rs | 33 +++++++++++++++++++++++++++++++++ ts-rs/tests/slices.rs | 10 ++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 ts-rs/tests/hashset.rs diff --git a/ts-rs/tests/hashmap.rs b/ts-rs/tests/hashmap.rs index c4d4c54..a67d75d 100644 --- a/ts-rs/tests/hashmap.rs +++ b/ts-rs/tests/hashmap.rs @@ -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, set: Array, };" ) } + +#[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, +} + +#[derive(TS)] +#[ts(export, export_to = "tests-out/hashmap/")] +struct BTreeMapWithCustomTypes { + map: BTreeMap, +} + +#[test] +fn with_custom_types() { + assert_eq!( + HashMapWithCustomTypes::inline(), + BTreeMapWithCustomTypes::inline() + ); + assert_eq!( + HashMapWithCustomTypes::decl(), + "type HashMapWithCustomTypes = { map: Record, };" + ); +} diff --git a/ts-rs/tests/hashset.rs b/ts-rs/tests/hashset.rs new file mode 100644 index 0000000..feeaa75 --- /dev/null +++ b/ts-rs/tests/hashset.rs @@ -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, +} + +#[derive(TS)] +#[ts(export, export_to = "tests-out/hashset/")] +struct BTreeSetWithCustomType { + set: BTreeSet, +} + +#[test] +fn with_custom_types() { + assert_eq!( + HashSetWithCustomType::inline(), + BTreeSetWithCustomType::inline() + ); + assert_eq!( + HashSetWithCustomType::decl(), + "type HashSetWithCustomType = { set: Array, };" + ); +} diff --git a/ts-rs/tests/slices.rs b/ts-rs/tests/slices.rs index deb762b..4ad938a 100644 --- a/ts-rs/tests/slices.rs +++ b/ts-rs/tests/slices.rs @@ -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") } + +#[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]);