2017-01-29 18:53:20 -06:00
|
|
|
extern crate toml;
|
|
|
|
|
2018-05-14 09:59:24 -05:00
|
|
|
use toml::map::Map;
|
2019-05-08 19:45:39 -05:00
|
|
|
use toml::Value::{Array, Boolean, Float, Integer, String, Table};
|
2017-01-29 18:53:20 -06:00
|
|
|
|
|
|
|
macro_rules! map( ($($k:expr => $v:expr),*) => ({
|
2018-05-14 09:59:24 -05:00
|
|
|
let mut _m = Map::new();
|
2017-01-29 18:53:20 -06:00
|
|
|
$(_m.insert($k.to_string(), $v);)*
|
|
|
|
_m
|
|
|
|
}) );
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_show() {
|
2019-05-08 19:45:39 -05:00
|
|
|
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]");
|
2017-01-29 18:53:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn table() {
|
2019-05-08 19:45:39 -05:00
|
|
|
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"
|
|
|
|
);
|
2017-01-29 18:53:20 -06:00
|
|
|
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())])])
|
|
|
|
})])
|
|
|
|
});
|
2019-05-08 19:45:39 -05:00
|
|
|
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"
|
|
|
|
);
|
2017-01-29 18:53:20 -06:00
|
|
|
}
|