-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made the TS implementation for hashmap and hashset generic over all h…
…ashers (#173) * Made the TS implementation for hashmap and hashset generic over all hashers * Added hashmap tests * Change tests to expect type instead of interface --------- Co-authored-by: Victor Koenders <git@trang.ar> Co-authored-by: escritorio-gustavo <131818645+escritorio-gustavo@users.noreply.github.com>
- Loading branch information
1 parent
ac00146
commit d6b862f
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
"type 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(), | ||
"type Hashes = { map: Record<string, string>, set: Array<string>, }" | ||
) | ||
} |