aboutsummaryrefslogtreecommitdiff
path: root/test-suite/tests/display.rs
blob: 5d9f44a53cf3d457f01d3f943cb477d35677e690 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
extern crate toml;

use toml::map::Map;
use toml::Value::{Array, Boolean, Float, Integer, String, Table};

macro_rules! map( ($($k:expr => $v:expr),*) => ({
    let mut _m = Map::new();
    $(_m.insert($k.to_string(), $v);)*
    _m
}) );

#[test]
fn simple_show() {
    assert_eq!(String("foo".to_string()).to_string(), "\"foo\"");
    assert_eq!(Integer(10).to_string(), "10");
    assert_eq!(Float(10.0).to_string(), "10.0");
    assert_eq!(Float(2.4).to_string(), "2.4");
    assert_eq!(Boolean(true).to_string(), "true");
    assert_eq!(Array(vec![]).to_string(), "[]");
    assert_eq!(Array(vec![Integer(1), Integer(2)]).to_string(), "[1, 2]");
}

#[test]
fn table() {
    assert_eq!(Table(map! {}).to_string(), "");
    assert_eq!(
        Table(map! {
        "test" => Integer(2),
        "test2" => Integer(3) })
        .to_string(),
        "test = 2\ntest2 = 3\n"
    );
    assert_eq!(
        Table(map! {
             "test" => Integer(2),
             "test2" => Table(map! {
                 "test" => String("wut".to_string())
             })
        })
        .to_string(),
        "test = 2\n\
         \n\
         [test2]\n\
         test = \"wut\"\n"
    );
    assert_eq!(
        Table(map! {
             "test" => Integer(2),
             "test2" => Table(map! {
                 "test" => String("wut".to_string())
             })
        })
        .to_string(),
        "test = 2\n\
         \n\
         [test2]\n\
         test = \"wut\"\n"
    );
    assert_eq!(
        Table(map! {
             "test" => Integer(2),
             "test2" => Array(vec![Table(map! {
                 "test" => String("wut".to_string())
             })])
        })
        .to_string(),
        "test = 2\n\
         \n\
         [[test2]]\n\
         test = \"wut\"\n"
    );
    assert_eq!(
        Table(map! {
             "foo.bar" => Integer(2),
             "foo\"bar" => Integer(2)
        })
        .to_string(),
        "\"foo\\\"bar\" = 2\n\
         \"foo.bar\" = 2\n"
    );
    assert_eq!(
        Table(map! {
             "test" => Integer(2),
             "test2" => Array(vec![Table(map! {
                 "test" => Array(vec![Integer(2)])
             })])
        })
        .to_string(),
        "test = 2\n\
         \n\
         [[test2]]\n\
         test = [2]\n"
    );
    let table = Table(map! {
        "test" => Integer(2),
        "test2" => Array(vec![Table(map! {
            "test" => Array(vec![Array(vec![Integer(2), Integer(3)]),
            Array(vec![String("foo".to_string()), String("bar".to_string())])])
        })])
    });
    assert_eq!(
        table.to_string(),
        "test = 2\n\
         \n\
         [[test2]]\n\
         test = [[2, 3], [\"foo\", \"bar\"]]\n"
    );
    assert_eq!(
        Table(map! {
             "test" => Array(vec![Integer(2)]),
             "test2" => Integer(2)
        })
        .to_string(),
        "test = [2]\n\
         test2 = 2\n"
    );
}