File: test.rs

package info (click to toggle)
rust-schemafy-lib 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use schemafy_lib::Expander;

#[test]
fn schema() {
    let json = std::fs::read_to_string("src/schema.json").expect("Read schema JSON file");

    let schema = serde_json::from_str(&json).unwrap_or_else(|err| panic!("{}", err));
    let mut expander = Expander::new(Some("Schema"), "UNUSED", &schema);

    expander.expand(&schema);
}

#[test]
fn test_str_to_ident() {
    use proc_macro2::Span;
    use schemafy_lib::str_to_ident;
    use syn::Ident;

    assert_eq!(
        str_to_ident("normalField"),
        Ident::new("normalField", Span::call_site())
    );

    assert_eq!(str_to_ident("ref"), Ident::new("ref_", Span::call_site()));

    assert_eq!(str_to_ident(""), Ident::new("empty_", Span::call_site()));
    assert_eq!(
        str_to_ident("_"),
        Ident::new("underscore_", Span::call_site())
    );
    assert_eq!(
        str_to_ident("__"),
        Ident::new("underscore_", Span::call_site())
    );

    assert_eq!(str_to_ident("_7_"), Ident::new("_7_", Span::call_site()));
    assert_eq!(
        str_to_ident("thieves' tools"),
        // only one underscore
        Ident::new("thieves_tools", Span::call_site())
    );
}