Add host stdlib modules and unify view/run capabilities.
Ship fs/time/sys/json/net L1 libs (plus existing text/table), default-on host caps with soft exit under view, bilingual public/stdlib docs, and design notes for deferred math/foreign. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a5d30c00b3
commit
a53ebb65ee
66 files changed
+2703
-45
No files matched your search
@@ -546,6 +546,48 @@ fn view_output_writes_html() {
|
||||
assert!(dir.join("pages").join("hello.mq.md.html").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_fs_read() {
|
||||
assert_out("tests/lib/fs-read.mq.md", "exists\nhello-lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_fs_read_zh() {
|
||||
assert_out("tests/lib/文件-读.mq.md", "存在\nhello-lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_time_format() {
|
||||
assert_out("tests/lib/time-format.mq.md", "1970-01-01\n0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_json_roundtrip() {
|
||||
assert_out(
|
||||
"tests/lib/json-roundtrip.mq.md",
|
||||
"map\n1\n{\"a\":1,\"b\":\"x\"}",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_sys_cwd() {
|
||||
assert_out("tests/lib/sys-cwd.mq.md", "cwd-ok");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_net_encode() {
|
||||
assert_out("tests/lib/net-encode.mq.md", "a+b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytecode_lib_json() {
|
||||
assert_out_backend(
|
||||
"tests/lib/json-roundtrip.mq.md",
|
||||
"bytecode",
|
||||
"map\n1\n{\"a\":1,\"b\":\"x\"}",
|
||||
);
|
||||
}
|
||||
|
||||
fn tempfile_dir(prefix: &str) -> std::path::PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"{prefix}-{}",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
hello-lib
|
||||
@@ -0,0 +1 @@
|
||||
{"a":1,"b":"x"}
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: fs read/exists
|
||||
> lib/fs.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`ok` = > exists path=hello.txt *
|
||||
|
||||
+ `ok`
|
||||
> print text=exists
|
||||
+ *
|
||||
> print text=missing
|
||||
|
||||
*`t` = > read_text path=hello.txt *
|
||||
|
||||
> print text=`t`
|
||||
@@ -0,0 +1 @@
|
||||
hello-lib
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
title: json roundtrip
|
||||
> lib/fs.mq.md
|
||||
> lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`raw` = > read_text path=sample.json *
|
||||
|
||||
*`obj` = > parse text=`raw` *
|
||||
|
||||
*`ty` = > type `obj` *
|
||||
|
||||
> print text=`ty`
|
||||
|
||||
*`a` = > get value=`obj` key=a *
|
||||
|
||||
> print text=`a`
|
||||
|
||||
*`out` = > stringify value=`obj` *
|
||||
|
||||
> print text=`out`
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
title: net url_encode
|
||||
> lib/net.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`e` = > url_encode text=a b *
|
||||
|
||||
> print text=`e`
|
||||
@@ -0,0 +1 @@
|
||||
{"a":1,"b":"x"}
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: sys cwd
|
||||
> lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`d` = > cwd *
|
||||
|
||||
*`n` = > len `d` *
|
||||
|
||||
+ `n` > 0
|
||||
> print text=cwd-ok
|
||||
+ *
|
||||
> print text=cwd-empty
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
title: time format/parse
|
||||
> lib/time.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`s` = > format unix=0 pattern=%Y-%m-%d *
|
||||
|
||||
> print text=`s`
|
||||
|
||||
*`u` = > parse text=1970-01-01 00:00:00 pattern=%Y-%m-%d %H:%M:%S *
|
||||
|
||||
> print text=`u`
|
||||
|
||||
> sleep_ms ms=0
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: 中文文件库
|
||||
> lib/文件.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`有` = > 存在 路径=hello.txt *
|
||||
|
||||
+ `有`
|
||||
> 打印 内容=存在
|
||||
+ *
|
||||
> 打印 内容=缺失
|
||||
|
||||
*`t` = > 读文本 路径=hello.txt *
|
||||
|
||||
> 打印 内容=`t`
|
||||
Reference in new issue
Block a user