Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,103 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn json_library_rejects_lost_errors_and_exposes_real_source_navigation() {
|
||||
let root = directory("json-library");
|
||||
let source = root.join("main.dever");
|
||||
for (text, code) in [
|
||||
(
|
||||
"type Hidden { private secret: Text }\nf(value: Hidden) (out: Json) { out = dever.json.encode(value) }",
|
||||
"C006",
|
||||
),
|
||||
(
|
||||
"type Hidden { private secret: Text }\nf(value: Json) (out: Hidden) { out = dever.json.decode(value) }",
|
||||
"C006",
|
||||
),
|
||||
(
|
||||
"f(value: Json) (out: Int) { decoded = dever.json.decode(value)\nout = 0 }",
|
||||
"C005",
|
||||
),
|
||||
(
|
||||
"f(text: Text) (out: Int) { pending: dever.json.JsonResult = result(dever.json.fromText(text))\nout = 1 }",
|
||||
"C012",
|
||||
),
|
||||
(
|
||||
"f(text: Text) (out: Int) { pending: dever.json.value.ParseResult = result(dever.json.parse(text))\nout = 1 }",
|
||||
"C012",
|
||||
),
|
||||
(
|
||||
"f(text: Text) (out: Json) { out = dever.system.jsonFromText(text) }",
|
||||
"C003",
|
||||
),
|
||||
(
|
||||
"f(text: Int) (out: Json) { out = dever.json.fromText(text) }",
|
||||
"C005",
|
||||
),
|
||||
(
|
||||
"f(text: Text) (out: Json) { out = dever.json.parse(text) }",
|
||||
"C005",
|
||||
),
|
||||
] {
|
||||
fs::write(&source, text).unwrap();
|
||||
let project = Project::load(&source).unwrap();
|
||||
assert!(project.diagnostics.is_empty(), "{:?}", project.diagnostics);
|
||||
let error = program::check(&project.declarations, &project.modules)
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_eq!(error.code, code, "{error}");
|
||||
}
|
||||
fs::write(&source, "f(text: Text) (out: Text) { out = dever.json.stringify(dever.json.parse(text)) }\ninspectValue(value: Json) (empty: Bool, body: Text) { empty = dever.json.isEmptyObject(value)\nbody = dever.json.stringify(dever.json.document(value)) }\ncmd f = app.f\ncmd inspectValue = app.inspectValue").unwrap();
|
||||
success(cli(&["fmt", source.to_str().unwrap()]));
|
||||
let index: serde_json::Value = serde_json::from_str(&success(cli(&[
|
||||
"inspect",
|
||||
source.to_str().unwrap(),
|
||||
"--json",
|
||||
])))
|
||||
.unwrap();
|
||||
assert!(index["diagnostics"].as_array().unwrap().is_empty());
|
||||
for name in [
|
||||
"dever.json.app.parse",
|
||||
"dever.json.app.document",
|
||||
"dever.json.app.isEmptyObject",
|
||||
"dever.json.app.value.Document",
|
||||
"dever.json.app.value.Value",
|
||||
] {
|
||||
assert!(
|
||||
index["symbols"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|symbol| symbol["name"] == name),
|
||||
"{name}"
|
||||
);
|
||||
}
|
||||
for (input, empty, body) in [
|
||||
(r#"{"value":{ }}"#, true, "{}"),
|
||||
(r#"{"value":{"a":[1e9999]}}"#, false, r#"{"a":[1e9999]}"#),
|
||||
(r#"{"value":[]}"#, false, "[]"),
|
||||
] {
|
||||
let output = success(cli(&[
|
||||
"run",
|
||||
source.to_str().unwrap(),
|
||||
"--",
|
||||
"main.main.inspectValue",
|
||||
input,
|
||||
]));
|
||||
let value = serde_json::from_str::<serde_json::Value>(&output).unwrap();
|
||||
assert_eq!(
|
||||
value["data"],
|
||||
serde_json::json!({"empty":empty,"body":body})
|
||||
);
|
||||
}
|
||||
let output = success(cli(&[
|
||||
"run",
|
||||
source.to_str().unwrap(),
|
||||
"--",
|
||||
"main.main.f",
|
||||
r#"{"text":"{\"number\":1e9999}"}"#,
|
||||
]));
|
||||
assert_eq!(
|
||||
serde_json::from_str::<serde_json::Value>(&output).unwrap()["data"],
|
||||
r#"{"number":1e9999}"#
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user