Skip to content

Commit

Permalink
Added hashmap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Koenders committed Oct 14, 2023
1 parent 35fa135 commit 457addb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ts-rs/tests/hashmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::collections::{HashMap, HashSet};
use ts_rs::TS;

#[test]
fn hashmap() {
#[derive(TS)]
#[allow(dead_code)]
struct Hashes {
map: HashMap<String, String>,
set: HashSet<String>,
}

assert_eq!(
Hashes::decl(),
"interface Hashes { map: Record<string, string>, set: Array<string>, }"
)
}

#[test]
fn hashmap_with_custom_hasher() {
struct CustomHasher {}

type CustomHashMap<K, V> = HashMap<K, V, CustomHasher>;
type CustomHashSet<K> = HashSet<K, CustomHasher>;

#[derive(TS)]
#[allow(dead_code)]
struct Hashes {
map: CustomHashMap<String, String>,
set: CustomHashSet<String>,
}

assert_eq!(
Hashes::decl(),
"interface Hashes { map: Record<string, string>, set: Array<string>, }"
)
}

0 comments on commit 457addb

Please sign in to comment.