Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,129 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn standard_names_resolve_in_domains_and_navigation_opens_bundled_sources() {
|
||||
let root = directory("standard-library");
|
||||
let domain = root.join("module/demo/value");
|
||||
fs::create_dir_all(&domain).unwrap();
|
||||
fs::write(
|
||||
domain.join("domain.dever"),
|
||||
"clean(value: Text) (out: Text) { out = text.trim(value) }
|
||||
id(value: Text) (out: Uuid?) { out = uuid.parse(value) }",
|
||||
)
|
||||
.unwrap();
|
||||
write_source(
|
||||
domain.join("app/main.dever"),
|
||||
"clean(value: Text) (out: Text) { out = domain.clean(value) }",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(domain.join("api.dever"), "cmd clean = app.clean").unwrap();
|
||||
let library = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../lib/text.dv")
|
||||
.canonicalize()
|
||||
.unwrap();
|
||||
let original = fs::read(&library).unwrap();
|
||||
let uuid_library = library.parent().unwrap().join("uuid.dv");
|
||||
let uuid_original = fs::read(&uuid_library).unwrap();
|
||||
let path = root.to_str().unwrap();
|
||||
success(cli(&["fmt", path]));
|
||||
success(cli(&["check", path]));
|
||||
let index: serde_json::Value =
|
||||
serde_json::from_str(&success(cli(&["inspect", path, "--json"]))).unwrap();
|
||||
assert!(index["diagnostics"].as_array().unwrap().is_empty());
|
||||
let symbols = index["symbols"].as_array().unwrap();
|
||||
let trim = symbols
|
||||
.iter()
|
||||
.find(|value| value["name"] == "dever.text.app.trim")
|
||||
.unwrap();
|
||||
let file = trim["declarations"][0][0].as_u64().unwrap() as usize;
|
||||
assert_eq!(index["files"][file]["path"], library.to_str().unwrap());
|
||||
let parse_uuid = symbols
|
||||
.iter()
|
||||
.find(|value| value["name"] == "dever.uuid.app.parse")
|
||||
.unwrap();
|
||||
let file = parse_uuid["declarations"][0][0].as_u64().unwrap() as usize;
|
||||
assert_eq!(index["files"][file]["path"], uuid_library.to_str().unwrap());
|
||||
assert!(
|
||||
!symbols
|
||||
.iter()
|
||||
.any(|value| value["name"] == "dever.int.app.parse")
|
||||
);
|
||||
success(cli(&["inspect", path, "--links"]));
|
||||
success(cli(&["inspect", path, "--links", "--check"]));
|
||||
assert_eq!(fs::read(&library).unwrap(), original);
|
||||
assert_eq!(fs::read(&uuid_library).unwrap(), uuid_original);
|
||||
let output = success(cli(&[
|
||||
"run",
|
||||
path,
|
||||
"--",
|
||||
"demo.value.clean",
|
||||
r#"{"value":" 雪 \n"}"#,
|
||||
]));
|
||||
assert_eq!(
|
||||
serde_json::from_str::<serde_json::Value>(&output).unwrap()["data"],
|
||||
"雪"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_primitives_are_private_and_calls_keep_static_types() {
|
||||
let root = directory("standard-invalid");
|
||||
let source = root.join("main.dever");
|
||||
for (text, code) in [
|
||||
(
|
||||
"f(text: Text) (out: Int) { pending: dever.time.DateResult = result(dever.time.parseDate(text))\nout = 1 }",
|
||||
"C012",
|
||||
),
|
||||
("f(value: Date) (out: DateTime) { out = value }", "C005"),
|
||||
(
|
||||
"f(value: DateTime, offset: Int) (out: DateTime) { out = dever.time.add(value, offset) }",
|
||||
"C005",
|
||||
),
|
||||
(
|
||||
"f(text: Text) (out: Date) { out = dever.system.timeParseDate(text) }",
|
||||
"C003",
|
||||
),
|
||||
(
|
||||
"f(value: Time) (out: dever.time.TextResult) { out = result(dever.time.formatTime(value)) }",
|
||||
"C012",
|
||||
),
|
||||
(
|
||||
"f(value: Text) (out: Text) { out = dever.system.textTrim(value) }",
|
||||
"C003",
|
||||
),
|
||||
(
|
||||
"f(value: Int) (out: Text) { out = text.trim(value) }",
|
||||
"C005",
|
||||
),
|
||||
(
|
||||
"f(value: Text) (out: Int) { out = int.parse(value) }",
|
||||
"C005",
|
||||
),
|
||||
(
|
||||
"f(value: Decimal) (out: Decimal) { out = decimal.round(value) }",
|
||||
"C005",
|
||||
),
|
||||
(
|
||||
"f(value: Float) (out: Float) { out = math.missing(value) }",
|
||||
"C004",
|
||||
),
|
||||
("f(value: Uuid) (out: Bool) { out = value < value }", "C005"),
|
||||
(
|
||||
"loop f(values: List<Uuid>) (out: List<Uuid>)\n| each value in values | sort | result |\n| out | [value.asc] | list value |",
|
||||
"C005",
|
||||
),
|
||||
("f(value: Uuid) (out: Text) { out = value }", "C005"),
|
||||
(
|
||||
"f(value: Text) (out: Uuid) { out = uuid.parse(value) }",
|
||||
"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}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user