feat(stdlib): Mid M5 list algorithms and cli.parse
Thicken table with sort/unique/chunk/zip/flatten and add lib/cli flag parsing, with golds and public demos. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
506de65dae
commit
7d86ed1d9c
20 files changed
+608
-14
No files matched your search
@@ -1147,6 +1147,27 @@ fn lib_csv_smoke_zh() {
|
||||
assert_out("tests/lib/逗号表-烟测.mq.md", "1\n1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_table_list_mid() {
|
||||
assert_out(
|
||||
"tests/lib/table-list-mid.mq.md",
|
||||
"1,1,2,3\n1,2,3\n2\n2\na,b,1,2,3",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_cli_sort_smoke() {
|
||||
assert_out(
|
||||
"tests/lib/cli-sort-smoke.mq.md",
|
||||
"alice\ndata.csv\nTrue\nrest",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_cli_zh_smoke() {
|
||||
assert_out("tests/lib/表-命令行-烟测.mq.md", "a,b,c\n1\nTrue");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_re_smoke() {
|
||||
assert_out(
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: table sort_by + cli
|
||||
import table:lib/table.mq.md
|
||||
import csv:lib/csv.mq.md
|
||||
import cli:lib/cli.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*raw = "name,score\nbob,2\nalice,10\n"*
|
||||
*rows = > csv.parse text=`raw`*
|
||||
*rows = > table.sort_by list=`rows` key="name"*
|
||||
*r0 = > at value=`rows` index=0*
|
||||
> print text=`r0`[^name]
|
||||
|
||||
*args = > split value="--input,data.csv,rest,--verbose" sep=","*
|
||||
*flags = > cli.parse args=`args`*
|
||||
> print text=`flags`[^input]
|
||||
> print text=`flags`[^verbose]
|
||||
*pos = `flags`[^_]*
|
||||
*p0 = > at value=`pos` index=0*
|
||||
> print text=`p0`
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: table list mid smoke
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*xs = > split value="3,1,2,1" sep=","*
|
||||
*xs = > table.sort list=`xs`*
|
||||
*s = > join value=`xs` sep=","*
|
||||
> print text=`s`
|
||||
|
||||
*u = > table.unique list=`xs`*
|
||||
*uj = > join value=`u` sep=","*
|
||||
> print text=`uj`
|
||||
|
||||
*ch = > table.chunk list=`xs` size=2*
|
||||
*n = > len `ch`*
|
||||
> print text=`n`
|
||||
|
||||
*a = > split value="a,b" sep=","*
|
||||
*b = > split value="1,2,3" sep=","*
|
||||
*z = > table.zip a=`a` b=`b`*
|
||||
*zn = > len `z`*
|
||||
> print text=`zn`
|
||||
|
||||
*nested = > table.append list=None item=`a`*
|
||||
*nested = > table.append list=`nested` item=`b`*
|
||||
*flat = > table.flatten list=`nested`*
|
||||
*fj = > join value=`flat` sep=","*
|
||||
> print text=`fj`
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: 表与命令行 烟测
|
||||
导入 表:lib/表.mq.md
|
||||
导入 命令行:lib/命令行.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*xs = > split value="c,a,b" sep=","*
|
||||
*xs = > 表.排序 list=`xs`*
|
||||
*s = > join value=`xs` sep=","*
|
||||
> 打印 内容=`s`
|
||||
|
||||
*args = > split value="--x,1,--flag" sep=","*
|
||||
*flags = > 命令行.解析 参数=`args`*
|
||||
> 打印 内容=`flags`[^x]
|
||||
> 打印 内容=`flags`[^flag]
|
||||
Reference in new issue
Block a user