Rename the language from Dino to Rex
Files use .rex, the command is rex, and the crate, runtime prefixes, docs, editor files and examples all use the new name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f44f09b6a
commit
7cf9727bcd
94 files changed
+858
-858
No files matched your search
+22
-22
@@ -4,13 +4,13 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use dino::driver;
|
||||
use rex::driver;
|
||||
|
||||
/// A fresh folder with the given files in it.
|
||||
fn folder(files: &[(&str, &str)]) -> PathBuf {
|
||||
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
let n = N.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let dir = std::env::temp_dir().join(format!("dino-clib-{}-{n}", std::process::id()));
|
||||
let dir = std::env::temp_dir().join(format!("rex-clib-{}-{n}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
for (name, text) in files {
|
||||
@@ -19,10 +19,10 @@ fn folder(files: &[(&str, &str)]) -> PathBuf {
|
||||
dir
|
||||
}
|
||||
|
||||
/// Compile `main.dino` in a folder with these files and run it; returns what it printed.
|
||||
/// Compile `main.rex` in a folder with these files and run it; returns what it printed.
|
||||
fn run(files: &[(&str, &str)]) -> String {
|
||||
let dir = folder(files);
|
||||
let c = driver::compile_file(dir.join("main.dino").to_str().unwrap()).unwrap_or_else(|e| panic!("{e}"));
|
||||
let c = driver::compile_file(dir.join("main.rex").to_str().unwrap()).unwrap_or_else(|e| panic!("{e}"));
|
||||
let exe = dir.join("prog");
|
||||
let sanitized = driver::build_exe_with(&c, &exe, &["-std=c11", "-fwrapv", "-w", "-fsanitize=address", "-g"]);
|
||||
if let Err(e) = sanitized {
|
||||
@@ -40,7 +40,7 @@ fn run(files: &[(&str, &str)]) -> String {
|
||||
/// The error message for a program that should not compile.
|
||||
fn error(files: &[(&str, &str)]) -> String {
|
||||
let dir = folder(files);
|
||||
let r = driver::compile_file(dir.join("main.dino").to_str().unwrap());
|
||||
let r = driver::compile_file(dir.join("main.rex").to_str().unwrap());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
match r {
|
||||
Ok(_) => panic!("expected an error"),
|
||||
@@ -55,7 +55,7 @@ fn have_pkg(name: &str) -> bool {
|
||||
#[test]
|
||||
fn the_c_library() {
|
||||
let out = run(&[(
|
||||
"main.dino",
|
||||
"main.rex",
|
||||
"import \"math.h\" { cbrt, hypot }\nimport \"string.h\"\nimport \"stdlib.h\"\n\n\
|
||||
func main() {\n print(cbrt(27.0), hypot(3.0, 4.0))\n print(string.strlen(\"héllo\"), stdlib.abs(-4))\n print(stdlib.atoi(\"42abc\") + 1)\n}\n",
|
||||
)]);
|
||||
@@ -149,7 +149,7 @@ shapes.Box{size: shapes.Size{w: 2.0, h: 3.0}, id: 5} 7\n0 10 11\n10\n[97, 98, 99
|
||||
|
||||
#[test]
|
||||
fn your_own_c_file() {
|
||||
let out = run(&[("shapes.h", SHAPES_H), ("shapes.c", SHAPES_C), ("main.dino", SHAPES_MAIN)]);
|
||||
let out = run(&[("shapes.h", SHAPES_H), ("shapes.c", SHAPES_C), ("main.rex", SHAPES_MAIN)]);
|
||||
assert_eq!(out, SHAPES_OUT);
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ const char *counter_name(const Counter *c) { return c->name.c_str(); }
|
||||
void counter_free(Counter *c) { delete c; }
|
||||
}
|
||||
"#;
|
||||
let out = run(&[("shapes.h", SHAPES_H), ("shapes.cpp", cpp), ("main.dino", SHAPES_MAIN)]);
|
||||
let out = run(&[("shapes.h", SHAPES_H), ("shapes.cpp", cpp), ("main.rex", SHAPES_MAIN)]);
|
||||
assert_eq!(out, SHAPES_OUT);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ fn picked_names_are_used_bare() {
|
||||
("shapes.h", SHAPES_H),
|
||||
("shapes.c", SHAPES_C),
|
||||
(
|
||||
"main.dino",
|
||||
"main.rex",
|
||||
"import \"shapes.h\" { Size, area, MAX_SIDES }\n\nfunc main() {\n var s: Size = Size{1.5, 2.0}\n print(area(s), MAX_SIDES)\n}\n",
|
||||
),
|
||||
]);
|
||||
@@ -201,7 +201,7 @@ fn zlib_through_pkg_config() {
|
||||
return;
|
||||
}
|
||||
let out = run(&[(
|
||||
"main.dino",
|
||||
"main.rex",
|
||||
r#"import "zlib.h"
|
||||
|
||||
func main() {
|
||||
@@ -235,7 +235,7 @@ fn sqlite_fills_in_pointer_variables() {
|
||||
return;
|
||||
}
|
||||
let out = run(&[(
|
||||
"main.dino",
|
||||
"main.rex",
|
||||
r#"import "sqlite3.h"
|
||||
|
||||
func main() {
|
||||
@@ -260,7 +260,7 @@ fn raylib_structs_without_a_window() {
|
||||
return;
|
||||
}
|
||||
let out = run(&[(
|
||||
"main.dino",
|
||||
"main.rex",
|
||||
"import \"raylib.h\"\n\nfunc main() {\n var c = raylib.Fade(raylib.RED, 0.5)\n print(c, raylib.ColorToInt(raylib.Color{0, 0, 0, 255}))\n var p = raylib.Vector2{1.0, 1.0}\n print(raylib.CheckCollisionPointRec(p, raylib.Rectangle{0.0, 0.0, 2.0, 2.0}))\n}\n",
|
||||
)]);
|
||||
assert_eq!(out, "raylib.Color{r: 230, g: 41, b: 55, a: 127} 255\ntrue\n");
|
||||
@@ -268,32 +268,32 @@ fn raylib_structs_without_a_window() {
|
||||
|
||||
#[test]
|
||||
fn errors_name_the_problem() {
|
||||
let e = error(&[("main.dino", "import \"no_such_header.h\"\n\nfunc main() {}\n")]);
|
||||
let e = error(&[("main.rex", "import \"no_such_header.h\"\n\nfunc main() {}\n")]);
|
||||
assert!(e.contains("cannot find the C header `no_such_header.h`"), "{e}");
|
||||
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.dino", "import \"shapes.h\" { aera }\n\nfunc main() {}\n")]);
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.rex", "import \"shapes.h\" { aera }\n\nfunc main() {}\n")]);
|
||||
assert!(e.contains("`shapes.h` has no `aera` (did you mean `area`?)"), "{e}");
|
||||
|
||||
let e = error(&[("main.dino", "import \"stdio.h\"\n\nfunc main() {\n stdio.printf(\"hi\")\n}\n")]);
|
||||
assert!(e.contains("`printf` can't be called from Dino: it takes a variable number of arguments"), "{e}");
|
||||
let e = error(&[("main.rex", "import \"stdio.h\"\n\nfunc main() {\n stdio.printf(\"hi\")\n}\n")]);
|
||||
assert!(e.contains("`printf` can't be called from Rex: it takes a variable number of arguments"), "{e}");
|
||||
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.dino", "import \"shapes.h\"\n\nfunc main() {\n shapes.grow(shapes.Size{1.0, 1.0}, 2.0)\n}\n")]);
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.rex", "import \"shapes.h\"\n\nfunc main() {\n shapes.grow(shapes.Size{1.0, 1.0}, 2.0)\n}\n")]);
|
||||
assert!(e.contains("`grow` writes into `s`, so it must be a variable"), "{e}");
|
||||
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.dino", "import \"shapes.h\"\n\nfunc main() {\n var n = 3\n print(shapes.make_box(n))\n}\n")]);
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.rex", "import \"shapes.h\"\n\nfunc main() {\n var n = 3\n print(shapes.make_box(n))\n}\n")]);
|
||||
assert!(e.contains("expected `i32`, found `int` (convert it with `i32(...)`)"), "{e}");
|
||||
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.dino", "import \"shapes.h\"\n\nfunc main() {\n print(shapes.area())\n}\n")]);
|
||||
let e = error(&[("shapes.h", SHAPES_H), ("main.rex", "import \"shapes.h\"\n\nfunc main() {\n print(shapes.area())\n}\n")]);
|
||||
assert!(e.contains("`area` takes 1 argument (s: shapes.Size), but 0 were given"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_library_says_how_to_link() {
|
||||
let dir = folder(&[(
|
||||
"main.dino",
|
||||
"import \"math.h\" link \"dino_no_such_lib\"\n\nfunc main() {\n print(math.sqrt(4.0))\n}\n",
|
||||
"main.rex",
|
||||
"import \"math.h\" link \"rex_no_such_lib\"\n\nfunc main() {\n print(math.sqrt(4.0))\n}\n",
|
||||
)]);
|
||||
let c = driver::compile_file(dir.join("main.dino").to_str().unwrap()).unwrap();
|
||||
let c = driver::compile_file(dir.join("main.rex").to_str().unwrap()).unwrap();
|
||||
let e = driver::build_exe(&c, &dir.join("prog")).unwrap_err();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
assert!(e.contains("linking with the C library failed") && e.contains("link \"name\""), "{e}");
|
||||
|
||||
+10
-10
@@ -1,9 +1,9 @@
|
||||
//! Tests of `dino fmt`.
|
||||
//! Tests of `rex fmt`.
|
||||
|
||||
use dino::fmt::format;
|
||||
use rex::fmt::format;
|
||||
|
||||
fn fmt(src: &str) -> String {
|
||||
format(src).unwrap_or_else(|d| panic!("{}", d.render("test.dino", src)))
|
||||
format(src).unwrap_or_else(|d| panic!("{}", d.render("test.rex", src)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -59,12 +59,12 @@ fn broken_code_is_refused() {
|
||||
assert!(format("func main( {").is_err());
|
||||
}
|
||||
|
||||
fn dino_files(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) {
|
||||
fn rex_files(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) {
|
||||
for e in std::fs::read_dir(dir).unwrap() {
|
||||
let p = e.unwrap().path();
|
||||
if p.is_dir() {
|
||||
dino_files(&p, out);
|
||||
} else if p.extension().map_or(false, |x| x == "dino") {
|
||||
rex_files(&p, out);
|
||||
} else if p.extension().map_or(false, |x| x == "rex") {
|
||||
out.push(p);
|
||||
}
|
||||
}
|
||||
@@ -73,12 +73,12 @@ fn dino_files(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) {
|
||||
#[test]
|
||||
fn examples_are_formatted_and_formatting_is_stable() {
|
||||
let mut files = Vec::new();
|
||||
dino_files(&std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("examples"), &mut files);
|
||||
rex_files(&std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("examples"), &mut files);
|
||||
assert!(files.len() > 30);
|
||||
for f in files {
|
||||
let src = std::fs::read_to_string(&f).unwrap();
|
||||
let once = fmt(&src);
|
||||
assert_eq!(once, src, "{} is not formatted (run `dino fmt examples`)", f.display());
|
||||
assert_eq!(once, src, "{} is not formatted (run `rex fmt examples`)", f.display());
|
||||
assert_eq!(fmt(&once), once, "formatting {} twice differs", f.display());
|
||||
}
|
||||
}
|
||||
@@ -91,8 +91,8 @@ fn doc_examples_are_stable() {
|
||||
let p = e.unwrap().path();
|
||||
let text = std::fs::read_to_string(&p).unwrap();
|
||||
let mut rest = text.as_str();
|
||||
while let Some(start) = rest.find("```dino\n") {
|
||||
let after = &rest[start + 8..];
|
||||
while let Some(start) = rest.find("```rex\n") {
|
||||
let after = &rest[start + "```rex\n".len()..];
|
||||
let end = after.find("```").unwrap();
|
||||
let code = &after[..end];
|
||||
rest = &after[end + 3..];
|
||||
|
||||
+19
-19
@@ -1,7 +1,7 @@
|
||||
//! Tests of the language server: feed it editor messages, read what it answers.
|
||||
|
||||
use dino::json::{self, Json};
|
||||
use dino::lsp;
|
||||
use rex::json::{self, Json};
|
||||
use rex::lsp;
|
||||
|
||||
fn frame(v: &Json) -> Vec<u8> {
|
||||
let body = v.to_string();
|
||||
@@ -68,7 +68,7 @@ fn initialize_announces_features() {
|
||||
#[test]
|
||||
fn errors_show_up_as_diagnostics() {
|
||||
let src = "func main() {\n var x: int = \"no\"\n}\n";
|
||||
let mut msgs = vec![open("file:///tmp/dino-lsp-test/a.dino", src)];
|
||||
let mut msgs = vec![open("file:///tmp/rex-lsp-test/a.rex", src)];
|
||||
msgs.extend(exit_messages());
|
||||
let (out, _) = talk(msgs);
|
||||
let d = match out[0].path(&["params", "diagnostics"]) {
|
||||
@@ -83,7 +83,7 @@ fn errors_show_up_as_diagnostics() {
|
||||
|
||||
#[test]
|
||||
fn fixing_the_code_clears_the_diagnostics() {
|
||||
let uri = "file:///tmp/dino-lsp-test/b.dino";
|
||||
let uri = "file:///tmp/rex-lsp-test/b.rex";
|
||||
let change = notify(
|
||||
"textDocument/didChange",
|
||||
Json::obj(vec![
|
||||
@@ -102,7 +102,7 @@ fn fixing_the_code_clears_the_diagnostics() {
|
||||
fn error_columns_count_utf16_units() {
|
||||
// the emoji takes two units in the editor's counting
|
||||
let src = "func main() {\n print(\"😀\", nope)\n}\n";
|
||||
let mut msgs = vec![open("file:///tmp/dino-lsp-test/c.dino", src)];
|
||||
let mut msgs = vec![open("file:///tmp/rex-lsp-test/c.rex", src)];
|
||||
msgs.extend(exit_messages());
|
||||
let (out, _) = talk(msgs);
|
||||
let d = match out[0].path(&["params", "diagnostics"]) {
|
||||
@@ -117,7 +117,7 @@ fn error_columns_count_utf16_units() {
|
||||
|
||||
#[test]
|
||||
fn formatting_returns_the_tidy_text() {
|
||||
let uri = "file:///tmp/dino-lsp-test/d.dino";
|
||||
let uri = "file:///tmp/rex-lsp-test/d.rex";
|
||||
let fmt_req = request(
|
||||
2,
|
||||
"textDocument/formatting",
|
||||
@@ -136,10 +136,10 @@ fn formatting_returns_the_tidy_text() {
|
||||
|
||||
#[test]
|
||||
fn imports_are_read_next_to_the_file() {
|
||||
let dir = std::env::temp_dir().join(format!("dino-lsp-{}", std::process::id()));
|
||||
let dir = std::env::temp_dir().join(format!("rex-lsp-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::fs::write(dir.join("util.dino"), "pub func twice(x: int): int { return x * 2 }\n").unwrap();
|
||||
let uri = format!("file://{}/main.dino", dir.display());
|
||||
std::fs::write(dir.join("util.rex"), "pub func twice(x: int): int { return x * 2 }\n").unwrap();
|
||||
let uri = format!("file://{}/main.rex", dir.display());
|
||||
let src = "import util\nfunc main() {\n print(util.twice(2))\n}\n";
|
||||
let mut msgs = vec![open(&uri, src)];
|
||||
msgs.extend(exit_messages());
|
||||
@@ -159,7 +159,7 @@ fn unknown_requests_get_an_error() {
|
||||
#[test]
|
||||
fn editor_files_are_valid_json() {
|
||||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("editors/vscode");
|
||||
for f in ["package.json", "language-configuration.json", "syntaxes/dino.tmLanguage.json"] {
|
||||
for f in ["package.json", "language-configuration.json", "syntaxes/rex.tmLanguage.json"] {
|
||||
let text = std::fs::read_to_string(dir.join(f)).unwrap();
|
||||
json::parse(&text).unwrap_or_else(|e| panic!("{f}: {e}"));
|
||||
}
|
||||
@@ -177,7 +177,7 @@ fn at(uri: &str, line: i64, ch: i64) -> Json {
|
||||
}
|
||||
|
||||
fn ask(method: &str, params: Json) -> Json {
|
||||
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open("file:///x/a.dino", SRC), request(2, method, params)];
|
||||
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open("file:///x/a.rex", SRC), request(2, method, params)];
|
||||
msgs.extend(exit_messages());
|
||||
let (out, _) = talk(msgs);
|
||||
out.into_iter().find(|m| m.get("id") == Some(&Json::Num(2.0))).unwrap().get("result").cloned().unwrap_or(Json::Null)
|
||||
@@ -185,40 +185,40 @@ fn ask(method: &str, params: Json) -> Json {
|
||||
|
||||
#[test]
|
||||
fn outline_lists_top_level_names() {
|
||||
let r = ask("textDocument/documentSymbol", Json::obj(vec![("textDocument", Json::obj(vec![("uri", Json::str("file:///x/a.dino"))]))]));
|
||||
let r = ask("textDocument/documentSymbol", Json::obj(vec![("textDocument", Json::obj(vec![("uri", Json::str("file:///x/a.rex"))]))]));
|
||||
let text = r.to_string();
|
||||
assert!(text.contains("\"add\"") && text.contains("\"P\"") && text.contains("\"main\"") && text.contains("\"x\""), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn definition_jumps_to_the_function() {
|
||||
let r = ask("textDocument/definition", at("file:///x/a.dino", 11, 14));
|
||||
let r = ask("textDocument/definition", at("file:///x/a.rex", 11, 14));
|
||||
assert_eq!(r.path(&["range", "start", "line"]).and_then(Json::as_i64), Some(1), "{r:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn definition_finds_a_local() {
|
||||
let r = ask("textDocument/definition", at("file:///x/a.dino", 3, 12));
|
||||
let r = ask("textDocument/definition", at("file:///x/a.rex", 3, 12));
|
||||
assert_eq!(r.path(&["range", "start", "line"]).and_then(Json::as_i64), Some(2), "{r:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_shows_the_signature_and_comment() {
|
||||
let r = ask("textDocument/hover", at("file:///x/a.dino", 11, 14));
|
||||
let r = ask("textDocument/hover", at("file:///x/a.rex", 11, 14));
|
||||
let v = r.path(&["contents", "value"]).and_then(Json::as_str).unwrap_or("").to_string();
|
||||
assert!(v.contains("func add(a: int, b: int): int") && v.contains("Adds two numbers."), "{v}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completion_offers_names_and_keywords() {
|
||||
let r = ask("textDocument/completion", at("file:///x/a.dino", 12, 4)).to_string();
|
||||
let r = ask("textDocument/completion", at("file:///x/a.rex", 12, 4)).to_string();
|
||||
assert!(r.contains("\"add\"") && r.contains("\"t\"") && r.contains("\"func\"") && r.contains("\"string\""), "{r:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signature_help_marks_the_parameter() {
|
||||
let src = "func add(a: int, b: int): int {\n return a + b\n}\nfunc main() {\n add(1, \n}\n";
|
||||
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open("file:///x/b.dino", src), request(2, "textDocument/signatureHelp", at("file:///x/b.dino", 4, 11))];
|
||||
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open("file:///x/b.rex", src), request(2, "textDocument/signatureHelp", at("file:///x/b.rex", 4, 11))];
|
||||
msgs.extend(exit_messages());
|
||||
let (out, _) = talk(msgs);
|
||||
let r = out.into_iter().find(|m| m.get("id") == Some(&Json::Num(2.0))).unwrap().get("result").cloned().unwrap();
|
||||
@@ -229,10 +229,10 @@ fn signature_help_marks_the_parameter() {
|
||||
// ---------- C headers ----------
|
||||
|
||||
fn with_header(src: &str, method: &str, line: i64, ch: i64) -> Json {
|
||||
let dir = std::env::temp_dir().join(format!("dino-lsp-c-{}-{}", std::process::id(), method.replace('/', "_")));
|
||||
let dir = std::env::temp_dir().join(format!("rex-lsp-c-{}-{}", std::process::id(), method.replace('/', "_")));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::fs::write(dir.join("geo.h"), "typedef struct { double x, y; } Point;\n#define ORIGIN_NAME \"origin\"\n/* distance */\ndouble dist(Point a, Point b);\nint clamp(int v, int lo, int hi);\n").unwrap();
|
||||
let uri = format!("file://{}/main.dino", dir.display());
|
||||
let uri = format!("file://{}/main.rex", dir.display());
|
||||
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open(&uri, src), request(2, method, at(&uri, line, ch))];
|
||||
msgs.extend(exit_messages());
|
||||
let (out, _) = talk(msgs);
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
use dino::ast::*;
|
||||
use dino::parser::parse;
|
||||
use rex::ast::*;
|
||||
use rex::parser::parse;
|
||||
|
||||
fn body_of(src: &str) -> Vec<Stmt> {
|
||||
let p = parse(src).unwrap_or_else(|d| panic!("{}", d.render("test", src)));
|
||||
@@ -23,7 +23,7 @@ fn all_examples_parse() {
|
||||
let mut n = 0;
|
||||
for entry in std::fs::read_dir(dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.extension().map_or(false, |e| e == "dino") {
|
||||
if path.extension().map_or(false, |e| e == "rex") {
|
||||
let src = std::fs::read_to_string(&path).unwrap();
|
||||
parse(&src).unwrap_or_else(|d| panic!("{}", d.render(path.to_str().unwrap(), &src)));
|
||||
n += 1;
|
||||
@@ -190,7 +190,7 @@ fn semicolons_work() {
|
||||
|
||||
// ---------- error messages ----------
|
||||
|
||||
fn err(src: &str) -> dino::error::Diag {
|
||||
fn err(src: &str) -> rex::error::Diag {
|
||||
parse(src).unwrap_err()
|
||||
}
|
||||
|
||||
@@ -239,8 +239,8 @@ fn error_two_statements_on_one_line() {
|
||||
#[test]
|
||||
fn render_shows_caret() {
|
||||
let src = "func main() {\n var x = \n}";
|
||||
let out = err(src).render("t.dino", src);
|
||||
assert!(out.contains("t.dino:3:1"), "{out}");
|
||||
let out = err(src).render("t.rex", src);
|
||||
assert!(out.contains("t.rex:3:1"), "{out}");
|
||||
assert!(out.contains("^"), "{out}");
|
||||
}
|
||||
|
||||
|
||||
+17
-17
@@ -1,9 +1,9 @@
|
||||
//! End-to-end tests: compile Dino programs to C, build them with the system C
|
||||
//! End-to-end tests: compile Rex programs to C, build them with the system C
|
||||
//! compiler, run them, and compare the output.
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
use dino::driver;
|
||||
use rex::driver;
|
||||
|
||||
struct Output {
|
||||
stdout: String,
|
||||
@@ -12,7 +12,7 @@ struct Output {
|
||||
}
|
||||
|
||||
fn run_source(src: &str) -> Output {
|
||||
let c = driver::compile_to_c(src).unwrap_or_else(|d| panic!("{}", d.render("test.dino", src)));
|
||||
let c = driver::compile_to_c(src).unwrap_or_else(|d| panic!("{}", d.render("test.rex", src)));
|
||||
run_c(&c, src)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ fn golden_examples() {
|
||||
let mut n = 0;
|
||||
for entry in std::fs::read_dir(dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.extension().map_or(false, |e| e == "dino") {
|
||||
if path.extension().map_or(false, |e| e == "rex") {
|
||||
let src = std::fs::read_to_string(&path).unwrap();
|
||||
let want = std::fs::read_to_string(path.with_extension("out"))
|
||||
.unwrap_or_else(|_| panic!("missing .out file for {}", path.display()));
|
||||
@@ -285,7 +285,7 @@ fn generated_c_is_const_correct() {
|
||||
// wrong, the C compiler would complain about discarding `const`.
|
||||
let dir = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/basics");
|
||||
for name in ["structs", "value_semantics", "lists", "list_values", "sieve", "enums", "enum_data", "errors", "optionals", "sized", "own_strings", "own_structs", "own_flows"] {
|
||||
let src = std::fs::read_to_string(format!("{dir}/{name}.dino")).unwrap();
|
||||
let src = std::fs::read_to_string(format!("{dir}/{name}.rex")).unwrap();
|
||||
let c = driver::compile_to_c(&src).unwrap();
|
||||
let exe = driver::temp_exe();
|
||||
driver::build_exe_with(
|
||||
@@ -1125,7 +1125,7 @@ fn optional_as_struct_return_through_match() {
|
||||
fn generated_c_for_errors_is_clean() {
|
||||
let dir = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/basics");
|
||||
for name in ["errors", "optionals", "sized", "own_strings", "own_structs", "own_flows"] {
|
||||
let src = std::fs::read_to_string(format!("{dir}/{name}.dino")).unwrap();
|
||||
let src = std::fs::read_to_string(format!("{dir}/{name}.rex")).unwrap();
|
||||
let c = driver::compile_to_c(&src).unwrap();
|
||||
let exe = driver::temp_exe();
|
||||
driver::build_exe_with(&c, &exe, &["-std=c11", "-Wall", "-Werror=incompatible-pointer-types"])
|
||||
@@ -1314,8 +1314,8 @@ fn error_float_literal_for_integer_type() {
|
||||
// ---------- modules: `import utils` ----------
|
||||
|
||||
fn project_c(main: &str, modules: &[(&str, &str)]) -> Result<String, String> {
|
||||
driver::compile_project("main.dino", main, |key| {
|
||||
modules.iter().find(|(k, _)| *k == key).map(|(k, src)| (format!("{k}.dino"), src.to_string()))
|
||||
driver::compile_project("main.rex", main, |key| {
|
||||
modules.iter().find(|(k, _)| *k == key).map(|(k, src)| (format!("{k}.rex"), src.to_string()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1398,7 +1398,7 @@ fn project_err(main: &str, modules: &[(&str, &str)]) -> String {
|
||||
fn error_private_function() {
|
||||
let e = project_err("import utils\nfunc main() { print(utils.helper()) }", &[("utils", UTILS)]);
|
||||
assert!(e.contains("`helper` is private to `utils`"), "{e}");
|
||||
assert!(e.contains("main.dino:2"), "{e}");
|
||||
assert!(e.contains("main.rex:2"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1420,20 +1420,20 @@ fn error_private_type() {
|
||||
#[test]
|
||||
fn error_in_module_names_that_file() {
|
||||
let e = project_err("import bad\nfunc main() { print(bad.f()) }", &[("bad", "pub func f(): int { return \"x\" }")]);
|
||||
assert!(e.contains("bad.dino:1"), "{e}");
|
||||
assert!(e.contains("bad.rex:1"), "{e}");
|
||||
assert!(e.contains("expected `int`"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_syntax_error_in_module() {
|
||||
let e = project_err("import bad\nfunc main() {}", &[("bad", "func f( {")]);
|
||||
assert!(e.contains("bad.dino"), "{e}");
|
||||
assert!(e.contains("bad.rex"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_missing_module() {
|
||||
let e = project_err("import nope\nfunc main() {}", &[]);
|
||||
assert!(e.contains("cannot find module `nope`") && e.contains("nope.dino"), "{e}");
|
||||
assert!(e.contains("cannot find module `nope`") && e.contains("nope.rex"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1452,7 +1452,7 @@ fn error_unknown_name_in_module() {
|
||||
fn error_module_does_not_see_main_or_other_imports() {
|
||||
// `b` imports nothing, so it can't use `os`
|
||||
let e = project_err("import b\nfunc main() { print(b.f()) }", &[("b", "pub func f(): int { return os.exists(\"x\") }")]);
|
||||
assert!(e.contains("b.dino"), "{e}");
|
||||
assert!(e.contains("b.rex"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1468,7 +1468,7 @@ fn error_private_field() {
|
||||
// ---------- move on last use ----------
|
||||
|
||||
fn c_of(src: &str) -> String {
|
||||
driver::compile_to_c(src).unwrap_or_else(|d| panic!("{}", d.render("test.dino", src)))
|
||||
driver::compile_to_c(src).unwrap_or_else(|d| panic!("{}", d.render("test.rex", src)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2154,7 +2154,7 @@ fn string_slice_out_of_range_panics() {
|
||||
#[test]
|
||||
fn calc_example_session() {
|
||||
let dir = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/calc");
|
||||
let main = format!("{dir}/main.dino");
|
||||
let main = format!("{dir}/main.rex");
|
||||
let c = driver::compile_file(&main).unwrap_or_else(|e| panic!("{e}"));
|
||||
let exe = driver::temp_exe();
|
||||
driver::build_exe_with(&c, &exe, &["-std=c11", "-fwrapv", "-w", "-fsanitize=address", "-g"]).unwrap();
|
||||
@@ -2203,8 +2203,8 @@ fn docs_examples_run() {
|
||||
}
|
||||
let text = std::fs::read_to_string(&path).unwrap();
|
||||
let mut rest = text.as_str();
|
||||
while let Some(start) = rest.find("```dino\n") {
|
||||
let after = &rest[start + 8..];
|
||||
while let Some(start) = rest.find("```rex\n") {
|
||||
let after = &rest[start + "```rex\n".len()..];
|
||||
let end = after.find("```").unwrap();
|
||||
let code = &after[..end];
|
||||
rest = &after[end + 3..];
|
||||
|
||||
Reference in new issue
Block a user