Files
2026-11-27 06:03:56 +00:00

94 lines
3.6 KiB
Rust

use super::*;
#[test]
fn bundled_bytes_keep_normal_calls_navigation_and_project_only_writes() {
let root = directory("bytes-library");
let domain = root.join("module/demo/binary");
fs::create_dir_all(&domain).unwrap();
let app = domain.join("app/main.dever");
write_source(
&app,
"echo(text: Text) (out: Text) { out = domain.roundtrip(text) }",
)
.unwrap();
fs::write(domain.join("domain.dever"), "roundtrip(text: Text) (out: Text) { out = dever.bytes.toText(dever.bytes.fromText(text)) }").unwrap();
fs::write(domain.join("api.dever"), "cmd echo = app.echo").unwrap();
let library = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../lib/dever/bytes.dv")
.canonicalize()
.unwrap();
let before = fs::read(&library).unwrap();
let path = root.to_str().unwrap();
success(cli(&["fmt", path]));
success(cli(&["check", path]));
let (project, _) = analyze(&root);
assert_eq!(
project
.sources
.iter()
.filter(|source| source.path == library)
.count(),
1
);
let index: serde_json::Value =
serde_json::from_str(&success(cli(&["inspect", path, "--json"]))).unwrap();
assert!(index["diagnostics"].as_array().unwrap().is_empty());
let target = index["symbols"]
.as_array()
.unwrap()
.iter()
.find(|symbol| symbol["name"] == "dever.bytes.app.toText")
.unwrap();
let file = target["declarations"][0][0].as_u64().unwrap() as usize;
assert_eq!(index["files"][file]["path"], library.to_str().unwrap());
success(cli(&["inspect", path, "--links"]));
success(cli(&["inspect", path, "--links", "--check"]));
assert!(domain.join("link.md").is_file());
assert!(!root.join("module/dever").exists());
assert_eq!(fs::read(&library).unwrap(), before);
let output = cli(&["run", path, "--", "demo.binary.echo", r#"{"text":"中文"}"#]);
let value: serde_json::Value = serde_json::from_str(&success(output)).unwrap();
assert_eq!(value["data"], "中文");
}
#[test]
fn bytes_boundaries_reject_hidden_errors_wire_values_and_reserved_modules() {
let root = directory("bytes-invalid");
let source = root.join("main.dever");
for (text, code) in [
(
"f(values: List<Int>) (out: Int) { pending: dever.bytes.BufferResult = result(dever.bytes.fromInts(values))\nout = 1 }",
"C012",
),
(
"f(data: Bytes) (out: Bytes) { out = data }\ncmd f = app.f",
"C005",
),
(
"f(text: Text) (out: Bytes) { out = dever.system.bytesFromText(text) }",
"C003",
),
(
"f(text: Text) (out: Bytes) { out = dever.bytes.fromInts(text) }",
"C005",
),
(
"f(data: Bytes) (out: Int) { out = length(data) }\nloop g(data: Bytes) (out: List<Int>)\n| each value in data | result |\n| out | list f(value) |\n",
"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}");
}
let forged = root.join("module/dever/bytes");
fs::create_dir_all(&forged).unwrap();
write_source(forged.join("app/main.dever"), "f() (out: Int) { out = 1 }").unwrap();
let error = Project::load(&root).err().unwrap();
assert!(error.to_string().contains("reserved"));
}