1#[macro_use]
2extern crate typescriptify_derive;
3
4
5pub trait TypeScriptifyTrait {
6 fn type_script_ify() -> String;
7}
8
9
10#[cfg(test)]
11mod tests {
12 use std::collections::HashSet;
13 use std::collections::HashMap;
14 use TypeScriptifyTrait;
15
16 #[derive(TypeScriptify)]
17 struct FrenchToast {
18 pub i: u32,
19 pub v: Vec<u8>,
20 pub hashmap: HashMap<String, u16>,
21 pub hashset: HashSet<u32>,
22 pub optional: Option<bool>,
23 }
24
25 #[derive(TypeScriptify)]
26 struct Waffles {
27 pub t: i64,
28 pub s: usize,
29 pub x: bool,
30 pub subtoast: FrenchToast,
31 }
32
33 #[derive(TypeScriptify)]
34 pub enum Sweet {
35 Caroline {
36 x: i64,
37 b: bool,
38 hashmap: HashMap<String, u16>,
39 hashset: HashSet<u32>,
40 },
41 Sugar {
42 i: u32,
43 x: u64,
44 s: usize,
45 optional: Option<bool>,
46 v: Vec<u8>,
47 },
48 }
49
50
51 #[derive(TypeScriptify)]
52 pub enum Enum {
53 Created,
54 Finalized,
55 ExportedAtLeastOnce,
56 }
57
58
59 #[test]
60 fn test_works() {
61
62
63 let r = format!("Typescript output for Enum: \n{}", Enum::type_script_ify());
64 let x = format!("Typescript output for Waffles: \n{}", Waffles::type_script_ify());
65 let y = format!("Typescript output for FrenchToast: \n{}", FrenchToast::type_script_ify());
66 let z = format!("Typescript output for Sweet: \n{}", Sweet::type_script_ify());
67
68 println!("Typescript outputs:\n{}\n{}\n{}\n{}\n", r, x, y, z);
69
70 assert_eq!(x.contains("subtoast: FrenchToast"), true);
71 assert_eq!(y.contains("hashmap: Map<string, number>"), true);
72 assert_eq!(z.contains("export interface Caroline"), true);
73 }
74}