mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
FIX: Integration tests for the json and yaml mapping.
Fixed bug in the yaml key deserialization logic.
This commit is contained in:
parent
e2b843035e
commit
38e418a1d6
11
integration_tests/include_example.json
Normal file
11
integration_tests/include_example.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"one": 1,
|
||||||
|
"inner": {
|
||||||
|
"list": [
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
null
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
5
integration_tests/include_example.yaml
Normal file
5
integration_tests/include_example.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
foo: "bar"
|
||||||
|
one: 1
|
||||||
|
inner:
|
||||||
|
list: [1, true, null]
|
@ -1,3 +1,5 @@
|
|||||||
|
let t = import "std/testing.ucg".asserts{};
|
||||||
|
|
||||||
let script = include str "./include_example.sh";
|
let script = include str "./include_example.sh";
|
||||||
assert {
|
assert {
|
||||||
ok = script == "#!/usr/bin/env bash
|
ok = script == "#!/usr/bin/env bash
|
||||||
@ -15,3 +17,41 @@ assert {
|
|||||||
ok = base64safe == expected,
|
ok = base64safe == expected,
|
||||||
desc = "base64safe == expected",
|
desc = "base64safe == expected",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let json_conf = include json "./include_example.json";
|
||||||
|
|
||||||
|
assert t.equal{
|
||||||
|
left = json_conf.foo,
|
||||||
|
right = "bar",
|
||||||
|
};
|
||||||
|
|
||||||
|
assert t.equal{
|
||||||
|
left = json_conf.one,
|
||||||
|
right = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert t.equal{
|
||||||
|
left = json_conf.inner,
|
||||||
|
right = {
|
||||||
|
list = [1, true, NULL],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let yaml_conf = include yaml "./include_example.yaml";
|
||||||
|
|
||||||
|
assert t.equal{
|
||||||
|
left = yaml_conf.foo,
|
||||||
|
right = "bar",
|
||||||
|
};
|
||||||
|
|
||||||
|
assert t.equal{
|
||||||
|
left = yaml_conf.one,
|
||||||
|
right = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert t.equal{
|
||||||
|
left = yaml_conf.inner,
|
||||||
|
right = {
|
||||||
|
list = [1, true, NULL],
|
||||||
|
},
|
||||||
|
};
|
@ -100,13 +100,21 @@ impl YamlConverter {
|
|||||||
serde_yaml::Value::Mapping(m) => {
|
serde_yaml::Value::Mapping(m) => {
|
||||||
let mut fs = Vec::with_capacity(m.len());
|
let mut fs = Vec::with_capacity(m.len());
|
||||||
for (key, value) in m {
|
for (key, value) in m {
|
||||||
|
// This is a little gross but since yaml allows maps to be keyed
|
||||||
|
// by more than just a string it's necessary.
|
||||||
|
let key = match key {
|
||||||
|
serde_yaml::Value::Bool(b) => b.to_string(),
|
||||||
|
serde_yaml::Value::Null => "null".to_string(),
|
||||||
|
serde_yaml::Value::Number(n) => n.to_string(),
|
||||||
|
serde_yaml::Value::String(s) => s.clone(),
|
||||||
|
serde_yaml::Value::Sequence(_) | serde_yaml::Value::Mapping(_) => {
|
||||||
|
eprintln!("Unsupported key type in yaml import skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
eprintln!("yaml key is: {}", key);
|
||||||
fs.push((
|
fs.push((
|
||||||
ast::PositionedItem::new(
|
ast::PositionedItem::new(key, ast::Position::new(0, 0, 0)),
|
||||||
// This is a little gross but since yaml allows maps to be keyed
|
|
||||||
// by more than just a string it's necessary.
|
|
||||||
serde_yaml::to_string(key)?,
|
|
||||||
ast::Position::new(0, 0, 0),
|
|
||||||
),
|
|
||||||
Rc::new(self.convert_json_val(value)?),
|
Rc::new(self.convert_json_val(value)?),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user