feat(stdlib): Mid M2 path algebra and fs copy/move/temp

Add lib/path (EN/ZH) and thicken fs with sandboxed copy_file, move,
and make_temp, with golds and public demos.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-07 20:10:12 +08:00
1 parent 838a2b425a
commit 94ae6713aa
22 files changed
+618 -25

No files matched your search

+29
View File
@@ -1066,6 +1066,35 @@ fn lib_fs_read() {
assert_out("tests/lib/fs-read.mq.md", "exists\nhello-lib");
}
#[test]
fn lib_path_smoke() {
assert_out(
"tests/lib/path-smoke.mq.md",
"dir/sub/f.txt\nf.txt\ntxt\ndir/sub\na/c\nTrue\na|b|c",
);
}
#[test]
fn lib_path_smoke_zh() {
assert_out(
"tests/lib/路径-烟测.mq.md",
"dir/sub/f.txt\nf.txt\ntxt\na/c",
);
}
#[test]
fn lib_fs_copy_move() {
assert_out(
"tests/lib/fs-copy-move.mq.md",
"m2-body\nmoved\ntemp-ok",
);
}
#[test]
fn lib_fs_copy_zh() {
assert_out("tests/lib/文件-复制.mq.md", "zh-body");
}
#[test]
fn lib_re_smoke() {
assert_out(
+30
View File
@@ -0,0 +1,30 @@
---
title: fs copy/move/temp
import fs:lib/fs.mq.md
---
# main
> fs.write_text path="m2-src.txt" text="m2-body"
> fs.copy_file src="m2-src.txt" dest="m2-copy.txt"
*t = > fs.read_text path="m2-copy.txt"*
> print text=`t`
> fs.move src="m2-copy.txt" dest="m2-moved.txt"
*ok = > fs.exists path="m2-moved.txt"*
1. `ok`
> print text=moved
2. *
> print text=missing
*tmp = > fs.make_temp prefix="m2"*
> fs.write_text path=`tmp` text=temp-ok
*tt = > fs.read_text path=`tmp`*
> print text=`tt`
> fs.remove path="m2-src.txt"
> fs.remove path="m2-moved.txt"
> fs.remove path=`tmp`
+28
View File
@@ -0,0 +1,28 @@
---
title: lib/path smoke
import path:lib/path.mq.md
---
# main
*j = > path.join a="dir/sub" b="f.txt"*
> print text=`j`
*name = > path.file_name path=`j`*
> print text=`name`
*ext = > path.extension path=`j`*
> print text=`ext`
*par = > path.parent path=`j`*
> print text=`par`
*norm = > path.normalize path="a/./b/../c"*
> print text=`norm`
*abs = > path.is_absolute path="/tmp/x"*
> print text=`abs`
*parts = > path.split path="a/b/c"*
*pj = > join value=`parts` sep="|"*
> print text=`pj`
+13
View File
@@ -0,0 +1,13 @@
---
title: 文件 复制移动
导入 文件:lib/文件.mq.md
---
# main
> 文件.写文本 路径="m2-zh-src.txt" 内容="zh-body"
> 文件.复制文件 源="m2-zh-src.txt" 目标="m2-zh-copy.txt"
*t = > 文件.读文本 路径="m2-zh-copy.txt"*
> 打印 内容=`t`
> 文件.删除 路径="m2-zh-src.txt"
> 文件.删除 路径="m2-zh-copy.txt"
+18
View File
@@ -0,0 +1,18 @@
---
title: lib/路径 烟测
导入 路径:lib/路径.mq.md
---
# main
*j = > 路径.拼接 甲="dir/sub" 乙="f.txt"*
> 打印 内容=`j`
*name = > 路径.文件名 路径=`j`*
> 打印 内容=`name`
*ext = > 路径.扩展名 路径=`j`*
> 打印 内容=`ext`
*norm = > 路径.规范化 路径="a/./b/../c"*
> 打印 内容=`norm`