Add bit operators, defer, list methods, rand, assert and rex test
- Bit operators & | ^ ~ << >> and their op= forms (Go precedence),
plus hex, binary and octal literals (0xff, 0b1010, 0o755)
- defer stmt / defer { ... }: runs when the block ends, last first,
also on return, ?, break and continue
- List methods insert, remove, clear, contains, index_of, reverse,
sort and sort_by (stable merge sort)
- rand module: int(a, b), float(), seed(n)
- assert(cond[, msg]) and `rex test`, which runs each test_ function
in its own process
- rex.toml marks a project's top folder: imports count from there
- Docs, formatter, LSP completions and editor grammars updated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
910bde692a
commit
300d767124
28 files changed
+1373
-65
No files matched your search
@@ -64,3 +64,51 @@ fn one_dot_is_not_an_import_path() {
|
||||
assert!(!o.status.success());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rex_toml_marks_the_project_root() {
|
||||
let dir = tree(&[
|
||||
("rex.toml", ""),
|
||||
("engine/engine.rex", "import engine.util\n\npub func hi(): int { return util.seven() }\n"),
|
||||
("engine/util.rex", "pub func seven(): int { return 7 }\n"),
|
||||
("game/app/main.rex", "import engine.engine\nimport game.common\n\nfunc main() {\n print(engine.hi(), common.two())\n}\n"),
|
||||
("game/common.rex", "pub func two(): int { return 2 }\n"),
|
||||
("game/deeper/x/main.rex", "import engine.engine\n\nfunc main() {\n print(engine.hi())\n}\n"),
|
||||
]);
|
||||
// the same import works from any depth, and from any folder the command is run in
|
||||
let o = rex(&dir, "game/app", "main.rex");
|
||||
assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stderr));
|
||||
assert_eq!(String::from_utf8_lossy(&o.stdout), "7 2\n");
|
||||
let o = rex(&dir, "game/deeper/x", "main.rex");
|
||||
assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stderr));
|
||||
assert_eq!(String::from_utf8_lossy(&o.stdout), "7\n");
|
||||
let o = Command::new(env!("CARGO_BIN_EXE_rex"))
|
||||
.args(["run", dir.join("game/app/main.rex").to_str().unwrap()])
|
||||
.current_dir(std::env::temp_dir())
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stderr));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_rex_toml_imports_count_from_the_main_file() {
|
||||
let dir = tree(&[
|
||||
("engine/engine.rex", "pub func hi(): int { return 7 }\n"),
|
||||
("game/main.rex", "import engine.engine\n\nfunc main() { }\n"),
|
||||
]);
|
||||
let o = rex(&dir, "game", "main.rex");
|
||||
assert!(!o.status.success());
|
||||
assert!(String::from_utf8_lossy(&o.stderr).contains("cannot find module `engine.engine`"));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_dir_finds_the_nearest_root() {
|
||||
use rex::loader::project_dir;
|
||||
let dir = tree(&[("rex.toml", ""), ("a/b/main.rex", ""), ("a/rex.toml", ""), ("c/d/main.rex", "")]);
|
||||
let canon = |p: PathBuf| std::fs::canonicalize(p).unwrap();
|
||||
assert_eq!(canon(project_dir(&dir.join("a/b/main.rex"))), canon(dir.join("a")));
|
||||
assert_eq!(canon(project_dir(&dir.join("c/d/main.rex"))), canon(dir.clone()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user