diff --git a/docs/tsl/index.md b/docs/tsl/index.md index 9d78627c..f1c372ad 100644 --- a/docs/tsl/index.md +++ b/docs/tsl/index.md @@ -4,7 +4,7 @@ 是否可直接用于生成代码:否 是否含可直接照写示例:否 是否含不可照写反例:否 -遇到不确定时:先按“按任务跳转”分层;语法问题看 [syntax/index.md](syntax/index.md),函数库查询看 [reference/index.md](reference/index.md),模块 / 集成看 [modules/index.md](modules/index.md),项目执行问题回项目自身文档、`scripts/*` 入口脚本和 CI 配置 +遇到不确定时:先按“按任务跳转”分层;语法问题看 [syntax/index.md](syntax/index.md),命名问题看 [naming.md](naming.md),函数库查询看 [reference/index.md](reference/index.md),模块 / 集成看 [modules/index.md](modules/index.md),项目执行问题回项目自身文档、`scripts/*` 入口脚本和 CI 配置 本页只决定第一跳。不要在这里生成代码,不要通读全部 TSL 文档,不要用相似语言补全 TSL 事实。 @@ -14,6 +14,7 @@ | ------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------ | | 写最短可运行骨架、核对语言核心事实 | [syntax/01_quickstart.md](syntax/01_quickstart.md) | `.tsl` / `.tsf` 文件模型不明 | | 判断语法能不能写、查语言写法 | [syntax/index.md](syntax/index.md) | 没有命中具体语法专题 | +| 给变量、函数、类型、unit 或 `.tsf` 文件取名 | [naming.md](naming.md) | 文件模型或顶层声明规则不明 | | 核对高频误写、反例、负向边界 | [syntax/11_pitfalls.md](syntax/11_pitfalls.md) | 反例没有指向正确专题 | | 查行情、财务、板块、选股等金融函数 | [reference/catalog/datawarehouse.md](reference/catalog/datawarehouse.md) | 没有命中带参数表的函数事实条目 | | 查通用函数库函数名、参数、返回值 | [reference/index.md](reference/index.md) | catalog 没有正式函数条目 | diff --git a/docs/tsl/naming.md b/docs/tsl/naming.md index 94b98bc7..385ae36c 100644 --- a/docs/tsl/naming.md +++ b/docs/tsl/naming.md @@ -46,6 +46,14 @@ `if`、`for`、`class`、`function`、`unit`、`return` 等。 - 调用内置/标准库/第三方 API 时,推荐保持对方官方大小写形式(`aaBBCC`/lowerCamelCase),例如 `getSysParams("xxx")`;自定义 wrapper 仍按本指南使用 `PascalCase`。 +- 常规自定义标识符不要使用 TSL 关键字、保留字或内置函数名。适用范围包括变量、 + 参数、函数/过程、类/类型、property、方法、字段、unit 名和文件基名。 +- 关键字和保留名清单以 + [16_lexical_structure_and_compile_options.md](syntax/16_lexical_structure_and_compile_options.md) + 为准;例如 `label` 是控制流保留名,不要作为普通变量、函数或属性名。 +- 如果业务术语与关键字或内置名冲突,优先换成语义清楚的替代名称。只有明确需要 + 演示同名遮蔽、绑定外部接口或保持协议兼容时,才允许使用冲突名。 +- 函数参数场景可以使用 5.1 中的前导下划线例外。 ## 3. 类型命名(Type Names) diff --git a/docs/tsl/syntax/00_agent_index.json b/docs/tsl/syntax/00_agent_index.json index dd5d780b..d1ba365a 100644 --- a/docs/tsl/syntax/00_agent_index.json +++ b/docs/tsl/syntax/00_agent_index.json @@ -1,8 +1,9 @@ { - "version": "2.0", + "version": "2.1", "description": "Agent-optimized quick index for TSL syntax - read this FIRST", "total_tokens_saved_per_query": "~2000-3000", "changelog": { + "2.1": "Added naming/style routing for identifiers and TSF filename alignment", "2.0": "Extended coverage from 7 to 14 scenarios, added understand_code and optimize_code decision paths", "1.0": "Initial version with 7 high-frequency scenarios" }, @@ -62,6 +63,12 @@ "token_cost": 80, "example": "var a;\na := 1;" }, + "identifier_naming": { + "file": "../naming.md", + "line": 42, + "token_cost": 120, + "example": "UserAccount, LoadData, max_retry_count" + }, "class_basic": { "file": "08_objects_and_classes.md", "line": 98, @@ -122,6 +129,11 @@ "tsl_file_structure": { "order": ["statements first", "declarations after"], "wrong": "declarations before statements or after declarations" + }, + "identifier_naming": { + "doc": "../naming.md#L42", + "avoid": "ordinary custom identifiers should not use TSL keywords, reserved words, or builtin function names", + "tsf_filename_rule": "02_core_model.md#L38" } }, @@ -159,6 +171,7 @@ "simple_script": "01_quickstart.md#L182", "function": "05_functions_and_calls.md#L103", "procedure": "05_functions_and_calls.md#L130", + "naming": "../naming.md#L42", "class": "08_objects_and_classes.md#L98", "loop": "07_control_flow.md#L89", "condition": "07_control_flow.md#L54", diff --git a/docs/tsl/syntax/index.md b/docs/tsl/syntax/index.md index 60e6684f..a6eff0b6 100644 --- a/docs/tsl/syntax/index.md +++ b/docs/tsl/syntax/index.md @@ -7,6 +7,8 @@ "hello_world": "01_quickstart.md#L182", "function": "05_functions_and_calls.md#L103", "class": "08_objects_and_classes.md#L98", + "naming": "../naming.md#L42", + "tsf_filename": "02_core_model.md#L38", "loop": "07_control_flow.md#L89", "if": "07_control_flow.md#L54", "fix_a=1_error": "11_pitfalls.md#L45", @@ -30,6 +32,7 @@ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------------------------ | | 写最短骨架、核对语言核心事实 | [01_quickstart.md](01_quickstart.md) | 文件模型不明 | | 判断 `.tsl` / `.tsf`、顶层语句区、声明区、文件模型 | [02_core_model.md](02_core_model.md) | 用户交付目标不足以判断后缀 | +| 给变量、函数、类型、unit 或 `.tsf` 文件取名 | [../naming.md](../naming.md) | 文件模型或顶层声明规则不明 | | 写值、数组、字符串、字符串编码边界 | [03_values_and_literals.md](03_values_and_literals.md) | 需要未记录的字面量或编码写法 | | 写变量、常量、显式声明 | [04_variables_and_constants.md](04_variables_and_constants.md) | 变量生命周期或作用域不明 | | 写 `function` / `procedure`、参数、默认参数、命名参数、变参 | [05_functions_and_calls.md](05_functions_and_calls.md) | 需要未记录的调用外形 | diff --git a/test/README.md b/test/README.md index 5b07f5ef..fe55669f 100644 --- a/test/README.md +++ b/test/README.md @@ -13,6 +13,7 @@ test/ ├── test_no_backup_flags.py # no_backup 行为测试 ├── test_sync_directory_actions.py # sync_memory_bank/sync_prompts 行为测试 ├── test_main_loop_cli.py # main_loop CLI 测试 +├── agent/ # Agent 题面/运行时验证测试定义 ├── test_thirdparty_skills_pipeline.py # thirdparty skills 流水线配置与同步产物测试 ├── test_sync_templates_placeholders.py # 占位符替换测试(sync_rules/sync_standards) ├── test_toml_edge_cases.py # TOML 解析边界测试 diff --git a/test/agent/README.md b/test/agent/README.md index de3ff0cf..0a2f5718 100644 --- a/test/agent/README.md +++ b/test/agent/README.md @@ -1,300 +1,304 @@ # TSL Agent 测试定义 -这个目录包含 TSL 语法的 agent 测试用例定义,**支持测试任何 agent**。 +你是 TSL agent 测试执行方。 ---- +阅读本 README 后,先向用户询问本机 `tsl` 可执行文件路径。 +用户提供路径后,优先自动识别被测 agent 名称;无法可靠识别时,向用户确认一次 +agent 短名。随后严格按本文的标准测试流程执行。 -## 🎯 多 Agent 支持 +轮次边界必须严格执行: -### 测试定义(通用) +- 第一轮只允许生成首答、落盘、运行验证和记录评分;禁止修复,禁止把运行错误回传给被测 agent,禁止修改第一轮结果文件,也禁止测试执行方在命令失败后自动编辑文件。 +- 本轮计划测试的所有 case 完成第一轮评分后,才允许进入第二轮修复。 +- 第二轮只修复第一轮已经记录为 `fail` 的 case;每修复某个 case 一次,只增加该 case 的 `repair_count`。 -- **`test_cases.md`** - 100+ 测试用例定义(英文完整版) +这个目录包含 TSL 语法的 agent 测试用例定义。当前评分以运行时验证为准: +生成的 `.tsl` 或 `.tsf` 能按标准流程执行通过即为通过,执行报错、超时或文件类型错误即为失败。 - - 适用于所有 agent(Claude, GPT-4, Gemini, 等) - - 包含提示词、评分标准、预期代码 - - 与具体 agent 无关 +## 测试定义 -- **`test_cases_zh.md`** - 100+ 测试用例定义(中文完整版) - - 完整翻译版本,包含所有测试用例 - - 适合中文环境下的 agent 评估 +- `prompts_zh.md`:给被测 agent 的题面文件。 + - 包含 100 个唯一测试用例。 + - 只包含题面,不包含答案、评分细则或 source docs 映射。 + - 除非题面明确要求 `.tsf`,默认都要求生成 `.tsl`。 -### 测试结果(按 Agent 分类) +不再维护单独的 rubric 文件。不要用人工答案表给被测 agent 提供额外线索。 -- **`result/results__.md`** - 特定 agent 的测试结果 - - 存放目录:`test/agent/result/`(已加入 `.gitignore`) - - 命名格式:`results_{agent}_{YYYYMMDD}.md` - - 示例: - - `result/results_claude_20260610.md` - Claude 的测试结果 - - `result/results_gpt4_20240617.md` - GPT-4 的测试结果 - - `result/results_gemini_20240617.md` - Gemini 的测试结果 +## 测试产物 ---- +所有测试结果都落盘为 `.tsl` 或 `.tsf` 文件,不保存 agent 回答 markdown。 -## 📁 目录结构 +- 存放目录:`test/agent/result///` + - `` 由测试执行方优先自动识别。 + - 识别来源优先使用被测 agent 的产品名、命令名、SDK provider 名或当前运行器已知的 agent 身份。 + - 无法从运行器上下文、命令名或已知 provider 可靠识别时,向用户确认一次 agent 短名;不要猜测。 + - 目录名统一转成小写短名,只使用 ASCII 字母、数字、短横线、下划线或点。 +- 命名格式: + - `.tsl`:`tsl-001.tsl` + - `.tsf`:`tsl-037/.tsf` + - `.tsf` 调用验证脚本:`tsl-037/verify.tsl` +- 修复轮次按 case 计数:`repair-1/tsl-001.tsl`、`repair-1/tsl-037/.tsf` +- 示例: + - `result/claude/20260610/tsl-001.tsl` + - `result/claude/20260610/tsl-037/.tsf` + - `result/claude/20260610/tsl-037/verify.tsl` -### 当前文件 +被测 agent 禁止读取、请求、搜索或引用 `result/`。 + +## 目录结构 ```text test/agent/ -├── README.md # 本文件 -├── test_cases.md # 通用测试定义(英文完整版)⭐ -├── test_cases_zh.md # 通用测试定义(中文完整版)⭐ -└── result/ # 测试结果目录(gitignore) - ├── results_claude_20260610.md - ├── results_gpt4_20240617.md - └── results_gemini_20240617.md -``` - -### 添加新 Agent 的测试结果 - -```text -test/agent/ -├── test_cases.md # 通用(不变) -├── test_cases_zh.md # 中文版(不变) +├── README.md +├── prompts_zh.md └── result/ - ├── results_claude_20260610.md # Claude - ├── results_gpt4_20240617.md # GPT-4(新增) - └── results_gemini_20240617.md # Gemini(新增) + └── claude/ + └── 20260610/ + ├── tsl-001.tsl + ├── tsl-037/ + │ ├── .tsf + │ └── verify.tsl + └── repair-1/ + ├── tsl-001.tsl + └── tsl-037/ + ├── .tsf + └── verify.tsl ``` ---- - -## 🎯 使用方式 - -### 测试不同的 Agent - -1. **使用相同的测试定义** - - ```bash - # 所有 agent 都使用 test_cases.md 中的测试用例 - cat test_cases.md - ``` - -2. **为每个 Agent 记录结果** - - ```bash - # 创建结果目录 - mkdir -p test/agent/result - - # 测试 GPT-4 - # 结果保存为:test/agent/result/results_gpt4_20240617.md - - # 测试 Gemini - # 结果保存为:test/agent/result/results_gemini_20240617.md - - # 测试 Claude - # 结果保存为:test/agent/result/results_claude_20240617.md - ``` - -3. **对比不同 Agent 的表现** - - ```bash - # 对比通过率、得分、常见错误等 - diff test/agent/result/results_claude_20240617.md \ - test/agent/result/results_gpt4_20240617.md - ``` - ---- - -## 📊 测试流程 +## 标准测试流程 ### 1. 准备测试 -```bash -# 查看测试用例 -cat test_cases.md +阅读本 README 后,测试执行方必须在开始执行用例前询问并记录本机 `tsl` +可执行文件路径。该路径不写入配置文件,只在本轮运行时验证中使用。 -# 选择要测试的 agent -AGENT="gpt4" # 或 claude, gemini, 等 -DATE=$(date +%Y%m%d) +将 `TSL_HOME` 记为 `tsl` 可执行文件所在目录;如果用户提供的是 TSL 根目录, +则以用户提供的目录作为 `TSL_HOME`。 + +```text +TSL executable path: /path/to/tsl ``` -### 2. 执行测试 +优先自动识别被测 agent 名称并记为 `AGENT`。`AGENT` 不是普通配置项;如果无法从 +当前运行器上下文、命令名或已知 provider 可靠识别,则在开始执行用例前向用户确认一次 +agent 短名;不要猜测。 + +```bash +AGENT="" +DATE=$(date +%Y%m%d) +mkdir -p "test/agent/result/$AGENT/$DATE" +``` + +### 2. 逐题生成文件 + +阅读 `prompts_zh.md`,然后按 case 逐题执行测试。 对于每个测试用例: -1. 复制提示词(Prompt) -2. 发送给目标 agent -3. 记录生成的代码 -4. 根据评分标准打分(0/1/2) +1. 为当前 case 启动全新的被测 agent 会话。测试执行方可以保持同一个会话, + 但被测 agent 不能在同一个会话里连续回答多个 case。 +2. 只发送 `prompts_zh.md` 中的 `Runner Setup`、`Answer Rules` 加单个题面, + 或只暴露 `prompts_zh.md` 加 `docs/index.md` 及其路由到的 `docs/` 子页。 +3. 允许 agent 从 `docs/index.md` 自动路由并阅读相关文档。 +4. 记录 agent 生成的第一次完整代码并立即落盘。 +5. 落盘后冻结该 case 的第一轮结果文件;第一轮不允许 agent 根据运行结果或评分反馈修订答案。 +6. 被测 agent 不得主动读取、请求、搜索或引用任何评分材料。 -### 3. 保存结果 +Codex 作为被测 agent 时: -```bash -# 创建结果目录 -mkdir -p test/agent/result +- CLI 自动化:每个 case 单独执行一次 `codex exec`,不要使用 `codex exec resume`。 +- CLI 自动化如果不想保留会话记录,可使用 `codex exec --ephemeral`。 +- Codex App 或 IDE:每个 case 新建一个 thread,不要在同一个 thread 里继续下一个 case。 +- Codex SDK/MCP:每个 case 调用一次新的 thread/start;不要用同一个 thread 连续 run 多个 case。 -# 创建结果文件 -# 格式:result/results_{agent}_{YYYYMMDD}.md +任何被测 agent 都一样:第一轮运行时验证输出不能回传给被测 agent。第一轮发现错误时, +只记录 `fail`,不得修复当前文件,不得让被测 agent 重新回答,不得把修改后的文件计入 +第一轮成绩。测试执行方自己的自动修复/纠错行为在第一轮也必须关闭。如果工具在看到 +第一轮运行错误后自动修改结果文件,必须按首次落盘文件评分;无法恢复首次落盘文件时, +该 case 标记为 `invalid`。第二轮修复阶段是例外,见“自动修复轮次”。 -test/agent/result/results_gpt4_20240617.md -test/agent/result/results_claude_20240617.md -test/agent/result/results_gemini_20240617.md +评分材料包括: + +- `result/` +- 运行时验证日志 +- 其他 agent 的输出文件 +- 对比报告或人工备注 + +若被测 agent 主动接触评分材料,该 case 或本轮测试应标记为 `invalid`, +不计入有效成绩。 + +推荐的运行器设置: + +```text +You are in this repository. The documentation entry point is docs/index.md. +When asked to write TSL, start from docs/index.md and follow its routing to the +relevant TSL pages. Do not infer syntax from Pascal, TypeScript, JavaScript, +Python, or SQL. ``` -### 4. 对比分析 +文件落盘规则: + +- 默认每个 case 保存为 `.tsl`,例如 `test/agent/result///tsl-001.tsl`。 +- 只有题面明确要求输出 `.tsf` 时,才保存为 `.tsf`,并放入对应 case 目录, + 例如 `test/agent/result///tsl-037/.tsf`。 +- `.tsf` 文件名不能使用 case 编号;文件基名必须与第一个顶层声明同名。 + 测试执行方应按被测 agent 代码中的第一个顶层声明命名文件,不为了凑文件名改写代码。 +- 任何 `unit ... end.` 文件只能保存为 `.tsf`,不能保存为 `.tsl`。 +- 如果 agent 输出 markdown code fence,测试执行方只提取代码内容保存到文件,不保存回答 markdown。 + +### 3. 运行时验证 + +运行时验证是标准测试流程的一部分。保存 `.tsl` 和 `.tsf` 文件后,由测试执行方 +逐个验证。第一轮验证必须在被测 agent 会话之外执行,不要把 stdout/stderr 或错误日志 +发送回被测 agent;即使第一轮发现错误,也只记录评分,不修复文件。第二轮自动修复阶段 +按“自动修复轮次”规则处理。 + +`.tsl` 验证规则: + +```bash +cd test/agent/result// +tsl tsl-001.tsl +tsl tsl-002.tsl +``` + +`.tsf` 验证规则: + +1. 将 case 目录中的 `.tsf` 文件复制到 `TSL_HOME/funcext/tmp/`。 +2. 在同一个 case 目录中编写 `verify.tsl` 调用脚本。 + 调用脚本应按被测 agent 实际生成的函数名、unit 名或类型名来调用。 + 验证脚本必须实际调用 `.tsf` 暴露的功能,不能只输出成功标记。 +3. 调用脚本在所有验证调用成功后,用 TSL 输出语句最后输出一行 `__TSL__AGENT__OK__`。 +4. 执行 `tsl verify.tsl`。 +5. 验证完成后删除 `TSL_HOME/funcext/tmp/`。 + +```bash +cd test/agent/result///tsl-037 +mkdir -p "$TSL_HOME/funcext/tmp" +cp ./*.tsf "$TSL_HOME/funcext/tmp/" +tsl verify.tsl +rm -rf "$TSL_HOME/funcext/tmp" +``` + +`funcext/tmp` 由本流程独占。开始验证前不要在该目录保留人工文件;结束后必须清理。 + +### 4. 第一轮评分规则 + +- `pass`:按标准流程执行,最后一个非空输出行是 `__TSL__AGENT__OK__`。 +- `fail`:超时、缺少文件、文件类型错误、`.tsf` 调用脚本失败, + `.tsf` 文件名与第一个顶层声明不一致,`.tsf` 无法被 TSL 加载/编译, + 或最后一个非空输出行不是 `__TSL__AGENT__OK__`。 +- `invalid`:被测 agent 主动读取、请求、搜索或引用评分材料。 + +TSL 可能在打印错误后仍返回退出码 0,因此不能只看 `$LASTEXITCODE`。 +运行时评分以成功标记为准:脚本没有正常执行到最后,就不会输出最后的 +`__TSL__AGENT__OK__`。 + +最终成绩只统计有效 case: + +```text +pass_rate = pass / (pass + fail) +``` + +不由被测 agent 自评。 + +### 5. 自动修复轮次 + +本轮计划测试的所有 case 完成第一轮评分后,可以对 `fail` 的 case 启动第二轮自动修复。 + +修复规则: + +1. 第一轮期间禁止修复;只有进入第二轮后,第一轮已经记录为 `fail` 的 case 才可以修复。 +2. 修复阶段可以把当前文件内容和运行时验证输出发给被测 agent。 +3. 每次 agent 产出修复版本,都保存到新的修复目录,不覆盖第一轮文件。 +4. 第一次修复保存到 `repair-1/`,第二次修复保存到 `repair-2/`,依此类推。 +5. `repair_count` 按 case/file 单独记录;修复 `tsl-019.tsl` 只增加 `tsl-019` 的次数, + 不影响其他失败 case。 +6. 修复版本仍按同样的运行时验证规则执行,最后一个非空输出行必须是 `__TSL__AGENT__OK__`。 + +示例: + +```text +test/agent/result/opencode/20260623/ +├── tsl-019.tsl # 第一轮原始输出 +├── repair-1/ +│ └── tsl-019.tsl # 第 1 次修复 +└── repair-2/ + └── tsl-019.tsl # 第 2 次修复 +``` + +修复统计: + +```text +case_id = tsl-019 +first_pass = 第一轮是否 pass +repair_pass = 修复后是否 pass +repair_count = 该 case 的修复版本数量 +``` + +如果第一轮已经 `pass`,`repair_count = 0`。如果多次修复仍失败, +该 case 的 `repair_count` 记录实际修复次数,`repair_pass = false`。 + +### 6. 对比分析 + +不同 agent 的输出直接按目录对比: + +```bash +diff -r test/agent/result/claude/20260617 \ + test/agent/result/gpt4/20260617 +``` + +建议人工记录汇总表,但不要把汇总表放入被测 agent 可读上下文。 ```markdown -# 示例对比报告 - -| Agent | 测试日期 | 通过率 | 平均分 | 常见错误 | -|-------|---------|-------|--------|---------| -| Claude | 2026-06-10 | 100% (10/10) | 2.0 | 无 | -| GPT-4 | 2024-06-17 | 90% (9/10) | 1.8 | 赋值语法 | -| Gemini | 2024-06-17 | 85% (8.5/10) | 1.7 | 类定义 | +| Agent | 测试日期 | 有效用例 | Pass | Fail | Invalid | Pass rate | +|-------|---------|---------:|-----:|-----:|--------:|----------:| +| Claude | 2026-06-17 | 100 | 96 | 4 | 0 | 96% | +| GPT-4 | 2026-06-17 | 100 | 88 | 12 | 0 | 88% | ``` ---- +## 版本控制策略 -## 📝 结果文件命名规范 - -### 格式 +提交到 git: ```text -test/agent/result/results_{agent}_{YYYYMMDD}.md +test/agent/README.md +test/agent/prompts_zh.md ``` -**说明**: - -- `result/`: 测试结果统一存放目录(已加入 `.gitignore`) -- `{agent}`: agent 名称(小写,如 claude, gpt4, gemini) -- `{YYYYMMDD}`: 测试日期(如 20240617) - -### 示例 +不提交: ```text -test/agent/result/results_claude_20260610.md # Claude 在 2026-06-10 的测试 -test/agent/result/results_claude_20240617.md # Claude 在 2024-06-17 的测试 -test/agent/result/results_gpt4_20240617.md # GPT-4 在 2024-06-17 的测试 -test/agent/result/results_gpt4o_20240617.md # GPT-4o 在 2024-06-17 的测试 -test/agent/result/results_gemini_20240617.md # Gemini 在 2024-06-17 的测试 -test/agent/result/results_gemini15_20240617.md # Gemini 1.5 在 2024-06-17 的测试 +test/agent/result/ ``` ---- +## 测试用例覆盖 -## 🎯 .gitignore 配置 +`prompts_zh.md` 包含 100 个测试用例,覆盖: -### 版本控制策略 +| 语法点 | 测试用例数 | +| ----------- | ---------- | +| 基础脚本 | 10+ | +| 控制流 | 10+ | +| 函数调用 | 10+ | +| `.tsf`/Unit | 4+ | +| 集合与查询 | 10+ | +| 表达式 | 10+ | +| 类与对象 | 15+ | +| 运行时特性 | 10+ | +| 高级边界 | 10+ | -**提交到 git**: +## 相关文档 -```text -✅ test/agent/test_cases.md # 测试定义(英文完整版) -✅ test/agent/test_cases_zh.md # 测试定义(中文完整版) -✅ test/agent/README.md # 说明文档 -``` +- 文档总入口:`docs/index.md` -**不提交**(已加入 `.gitignore`): +## 最佳实践 -```text -❌ test/agent/result/ # 测试结果目录 -``` +- 测试用例应该对所有 agent 都适用。 +- 不要添加特定 agent 的专属测试。 +- 关注 TSL 语法本身,而非 agent 特性。 +- 每轮测试使用独立日期目录。 +- 保留第一次输出作为基线,不根据运行反馈让同一个 agent 修订答案。 +- 定期对比不同 agent 的通过率和常见运行错误。 ---- - -## 📊 测试用例覆盖 - -`test_cases.md` 包含 100+ 测试用例,覆盖: - -| 语法点 | 测试用例数 | -| ---------- | ---------- | -| 函数定义 | 15+ | -| 类与对象 | 10+ | -| 控制流 | 10+ | -| 变量与赋值 | 8+ | -| Unit 模块 | 5+ | -| 参数传递 | 8+ | -| 类型系统 | 6+ | -| 错误边界 | 10+ | -| 其他 | 30+ | - -**总计**:100+ 测试用例 - ---- - -## 🔗 相关文档 - -### TSL 文档 - -- TSL 语法文档:`docs/tsl/syntax/` -- TSL 快速索引:`docs/tsl/syntax/00_agent_index.json` -- TSL 语法入口:`docs/tsl/syntax/index.md` - -### Agent 优化 - -- Agent 快速索引:`docs/tsl/syntax/00_agent_index.json` - - 为 agent 优化,减少 75% token 消耗 - - 包含精确行号和示例代码 - ---- - -## 💡 最佳实践 - -### 1. 保持测试定义的通用性 - -- ✅ 测试用例应该对所有 agent 都适用 -- ✅ 不要添加特定 agent 的专属测试 -- ✅ 关注 TSL 语法本身,而非 agent 特性 - -### 2. 结果命名规范 - -- ✅ 使用统一的命名格式 -- ✅ 包含 agent 名称和日期 -- ✅ 便于排序和查找 - -### 3. 定期对比 - -- 建议每季度测试一次所有 agent -- 追踪 agent 的改进趋势 -- 发现不同 agent 的优势和劣势 - -### 4. 基线管理 - -- 保留第一次测试结果作为基线 -- 新结果与基线对比 -- 追踪质量变化 - ---- - -## 🎉 示例:测试新 Agent - -### 步骤 - -```bash -# 1. 选择测试用例 -cat test_cases.md | grep "### TSL-001" - -# 2. 复制提示词发送给新 agent(如 GPT-4) - -# 3. 记录结果 -cat > results_gpt4_20240617.md << 'EOF' -# TSL Codegen Test Results - GPT-4 - -Date: 2024-06-17 -Agent: GPT-4 (gpt-4-turbo) - -## Summary -- Cases run: 10 -- Cases passed: 9 -- First-pass score: 18 / 20 -- Pass rate: 90% - -## Results -| Case | Score | Notes | -|------|-------|-------| -| TSL-001 | 2 | Correct | -| TSL-002 | 2 | Correct | -| TSL-003 | 1 | Minor issue | -... -EOF - -# 4. 对比 Claude 和 GPT-4 -diff results_claude_20260610.md results_gpt4_20240617.md -``` - ---- - -**维护者**:TSL Team -**最后更新**:2024-06-17 +**维护者**:TSL Team **支持的 Agent**:所有支持 TSL 的 agent diff --git a/test/agent/prompts_zh.md b/test/agent/prompts_zh.md new file mode 100644 index 00000000..15b1cf77 --- /dev/null +++ b/test/agent/prompts_zh.md @@ -0,0 +1,881 @@ +# TSL Agent Prompt Set (ZH) + +本文件只包含发送给被测 agent 的题面。 + +## Runner Setup + +```text +You are in this repository. The documentation entry point is docs/index.md. +When asked to write TSL, start from docs/index.md and follow its routing to the +relevant TSL pages. Do not infer syntax from Pascal, TypeScript, JavaScript, +Python, or SQL. +``` + +## Answer Rules + +```text +每个 case 独立作答。 +除非题面明确要求输出 .tsf,否则默认输出可执行 .tsl 文件内容。 +题面模拟普通用户的需求,不要复制文档中的样例代码。 +请按题面里的名称、数据和业务动作重新编写。 +如果输出 .tsl,请在题面要求的业务输出全部完成后,用 TSL 输出语句最后输出一行 __TSL__AGENT__OK__。 +如果输出 .tsf,必须是 TSL 能从 funcext 加载的有效函数扩展或 unit 文件; +不要在 .tsf 中加入成功标记,成功标记由验证脚本输出。 +只输出代码,不要解释。 +``` + +## Prompts + +### TSL-001: 订单折后金额 + +```text +请写一份 .tsl 代码: +一个订单里,单价是 19,数量是 6,优惠金额是 14。 +请算出这行订单最后要收多少钱,并输出结果。 +``` + +### TSL-002: 分页信息 + +```text +请写一份 .tsl 代码: +一共有 47 条记录,每页放 10 条。 +请输出能装满的页数,以及最后一页还剩多少条。 +``` + +### TSL-003: 订单编号 + +```text +请写一份 .tsl 代码: +把文字 "Order" 和编号 "42" 合成一个订单编号,然后输出它。 +``` + +### TSL-004: 简单扣费 + +```text +请写一份 .tsl 代码: +账户余额是 12,本次扣费是 3。 +请输出扣费后的余额。不要提前列出额外的变量清单。 +``` + +### TSL-005: 固定单价 + +```text +请写一份 .tsl 代码: +某个商品固定单价是 9,本次买了 4 个。 +请把固定单价作为常量保存,再输出总价。 +``` + +### TSL-006: 严格模式库存 + +```text +请写一份 .tsl 代码: +这份脚本要开启显式变量模式。 +请准备一个库存数 stock,把它设为 18,然后输出它。 +``` + +### TSL-007: 读取分数 + +```text +请写一份 .tsl 代码: +有一组分数:15、30、45。 +请输出第一项和最后一项。 +``` + +### TSL-008: 读取编码字符 + +```text +请写一份 .tsl 代码: +编码是 "ZX9"。 +请输出第一个字符和第三个字符。 +``` + +### TSL-009: 空列表检查 + +```text +请写一份 .tsl 代码: +准备一个空列表 bucket。 +请检查 bucket 的第一个位置是不是 nil,并输出检查结果。 +``` + +### TSL-010: 文本数字参与计算 + +```text +请写一份 .tsl 代码: +有一个文本形式的数字 "58"。 +请先把它变成整数,再减去 8,并输出结果。 +``` + +### TSL-011: 温度标签 + +```text +请写一份 .tsl 代码: +temperature 是 32。 +如果温度大于等于 30,level 就是 "hot";否则 level 是 "normal"。 +请最后输出 level。 +``` + +### TSL-012: 余额审核 + +```text +请写一份 .tsl 代码: +balance 是 80。 +如果 balance 大于 50,请先输出 "allow",再扣掉 10; +否则输出 "deny"。最后输出 balance。 +``` + +### TSL-013: 偶数累加 + +```text +请写一份 .tsl 代码: +请把 2、4、6、8 加起来并输出。 +要求用带步长的循环完成。 +``` + +### TSL-014: 权重检查 + +```text +请写一份 .tsl 代码: +weights 里有 3、5、9。 +请逐个处理,每行输出“当前位置”和“这个位置的值”的乘积。 +``` + +### TSL-015: 累加到上限 + +```text +请写一份 .tsl 代码: +从 n = 1 开始累加。 +当 n 大于 4 时停止,最后输出累计结果。 +``` + +### TSL-016: 跳过指定数字 + +```text +请写一份 .tsl 代码: +处理 1 到 5。 +遇到 3 时跳过它,只累加其他数字,最后输出结果。 +``` + +### TSL-017: 倒计时 + +```text +请写一份 .tsl 代码: +从 countdown = 4 开始倒数,一直到 0 停止。 +请使用 repeat until,并输出最后的 countdown。 +``` + +### TSL-018: 状态码 + +```text +请写一份 .tsl 代码: +status_code 是 2。 +如果是 1,输出 "new";如果是 2 或 3,输出 "active"; +其他情况输出 "closed"。 +``` + +### TSL-019: 等级文字 + +```text +请写一份 .tsl 代码: +grade 是 3。 +请用 case 表达式得到一段等级文字:1 是 "low",2 到 4 是 "mid",其他是 "high"。 +最后输出这段等级文字。 +``` + +### TSL-020: 捕获错误信息 + +```text +请写一份 .tsl 代码: +故意抛出 "network" 这个错误。 +捕获它后,请输出错误对象里的错误信息。 +``` + +### TSL-021: 清理动作 + +```text +请写一份 .tsl 代码: +先输出 "open"。 +无论前面是否正常结束,最后都要输出 "close"。 +请用 try/finally 完成。 +``` + +### TSL-022: 计算数量乘积 + +```text +请写一份 .tsl 代码: +请做一个“计算两个整数乘积”的功能,名字由你自己取。 +脚本里请用 6 和 8 调用它,并输出结果。 +``` + +### TSL-023: 调整额度 + +```text +请写一份 .tsl 代码: +请做一个“把额度增加 5”的动作,名字由你自己取。 +脚本里 quota 一开始是 10,调用后输出 quota。 +``` + +### TSL-024: 默认手续费 + +```text +请写一份 .tsl 代码: +请做一个“计算手续费后金额”的功能,名字由你自己取。 +如果没有传金额,就按 100 处理;最后结果是金额加 6。 +请分别输出不传金额和传 20 时的结果。 +``` + +### TSL-025: 下一批编号 + +```text +请写一份 .tsl 代码: +请做一个“取得下一批编号”的功能,名字由你自己取。 +起始编号是整数,默认是 10,结果也是整数。 +它要返回起始编号加 1。请输出默认情况下的结果。 +``` + +### TSL-026: 区间组装 + +```text +请写一份 .tsl 代码: +请做一个“组装左右边界”的功能,名字由你自己取,把两个边界值组成一个两项列表。 +调用时请用命名方式传入:right 是 90,left 是 40。 +最后输出这两项。 +``` + +### TSL-027: 跳过中间值 + +```text +请写一份 .tsl 代码: +请做一个“检查中间位置”的功能,名字由你自己取,里面要输出第二个位置 b 是不是 nil。 +调用时只给第一个和第三个位置传值,故意跳过 b。 +``` + +### TSL-028: 按名字调用功能 + +```text +请写一份 .tsl 代码: +请做一个“三位数字编码”的功能,名字由你自己取。 +它把三个输入算成 a * 100 + b * 10 + c。 +脚本里请通过 call 按这个名字调用它,并输出结果。 +``` + +### TSL-029: 多个数字相乘 + +```text +请写一份 .tsl 代码: +请做一个“多个数字相乘”的功能,名字由你自己取。 +它可以接收任意多个数字,并把它们全部相乘。 +请用 2、3、4 调用,并输出结果。 +``` + +### TSL-030: 看到多少输入 + +```text +请写一份 .tsl 代码: +请做一个“统计收到多少输入”的功能,名字由你自己取。 +前两个位置是固定的,后面还能继续接收更多值。 +它要输出 ParamCount * 100 + RealParamCount 的结果。 +请用 5、6、7 调用。 +``` + +### TSL-031: 保存一个小计算 + +```text +请写一份 .tsl 代码: +把一个“小计算”保存到你自己命名的变量里。这个小计算接收两个值,结果是两者相乘。 +请通过 call 调用这个变量,并用 4 和 9 输出结果。 +``` + +### TSL-032: 把计算交给别人执行 + +```text +请写一份 .tsl 代码: +请做一个“执行后再翻倍”的功能,名字由你自己取,它接收另一个计算。 +这个功能要先用 3 调用收到的计算,再把得到的结果乘以 2。 +调用它时,直接给它一个“把输入加 5”的匿名计算,并输出结果。 +``` + +### TSL-033: 查找已有功能 + +```text +请写一份 .tsl 代码: +请做一个“把输入乘以 3”的功能,名字由你自己取。 +脚本里找到这个名字对应的函数值,再用支持的函数值调用方式处理 7,并输出结果。 +``` + +### TSL-034: 传递当前功能 + +```text +请写一份 .tsl 代码: +请做一个“把输入平方”的功能,名字由你自己取。 +再做一个“调用传入计算”的功能,名字也由你自己取,它接收一个计算和一个值,并通过 call 执行。 +脚本里取得平方功能的函数值,并输出调用结果。 +``` + +### TSL-035: 函数里使用规则包 + +```text +请写一份 .tsl 代码: +请做一个“读取远程费率”的功能,名字由你自己取。 +这个功能一进入函数体就要使用一个费率相关的 unit,然后返回该 unit 中读取费率动作的结果。 +``` + +### TSL-036: 脚本开头使用规则包 + +```text +请写一份 .tsl 代码: +脚本需要先使用两个你自己命名的规则包:一个处理价格,一个处理税费。 +之后调用一个“计算最终金额”的动作,并输出结果。 +``` + +### TSL-037: 手续费扩展 + +```text +请写一份 .tsf 代码: +提供一个“计算服务费”的功能,名字由你自己取,接收金额。 +金额大于 1000 时,费用是 amount div 20;否则费用是 30。 +不要写可直接运行的脚本入口。 +``` + +### TSL-038: 发票规则包 + +```text +请写一份 .tsf 代码: +请做一个“发票规则”unit,unit 名由你自己取。 +外部只需要能调用一个“默认额度”功能,并得到 500。 +请写成完整的 unit 文件。 +``` + +### TSL-039: 运费规则包 + +```text +请写一份 .tsf 代码: +请做一个“运费规则”unit,unit 名由你自己取。 +外部只能调用一个“计算可计费重量”的功能。 +内部可以有一个不对外公开的小工具,用来把负数修正为 0。 +可计费重量要返回修正后的毛重减去皮重。 +``` + +### TSL-040: 会员积分规则包 + +```text +请写一份 .tsf 代码: +请做一个“会员积分规则”unit,unit 名由你自己取。 +外部可以调用“基础分”和“最终积分”两个功能。 +level 大于等于 3 时基础分是 20,否则是 5。 +最终积分的结果是金额 div 10 加上基础分。 +``` + +### TSL-041: 商品信息表 + +```text +请写一份 .tsl 代码: +准备一条商品信息,里面有 sku = "B17",qty = 12。 +请输出 sku 和 qty。 +``` + +### TSL-042: 只取第一个成绩 + +```text +请写一份 .tsl 代码: +有一组成绩 88、99、100。 +请只取第一个值放到 first_mark,然后输出 first_mark。 +``` + +### TSL-043: 读取两行数据 + +```text +请写一份 .tsl 代码: +有两行数据:(8, 1) 和 (9, 2)。 +请把两行分别取出来,再输出每行的两个值。 +``` + +### TSL-044: 检查是否存在 + +```text +请写一份 .tsl 代码: +先检查 5 是否在 2、5、8 这一组数字里,并输出结果。 +再检查整行 (2, 5) 是否在两行数据 (1, 1)、(2, 5) 里面,并输出结果。 +``` + +### TSL-045: 两组行数据对比 + +```text +请写一份 .tsl 代码: +left_rows 是 (1, "a")、(2, "b")。 +right_rows 是 (2, "b")、(3, "c")。 +请分别算出合并、交集、左边独有、两边不重叠的结果,并输出每个结果的大小。 +``` + +### TSL-046: 只保留允许状态 + +```text +请写一份 .tsl 代码: +有一批订单,每行包含订单号和状态。 +再准备一份允许状态列表。 +请只保留状态命中的订单,并输出保留下来的行数。 +``` + +### TSL-047: 排除禁止状态 + +```text +请写一份 .tsl 代码: +有一批任务,每行包含任务号和状态。 +再准备一份禁止状态列表。 +请排除命中的任务,并输出剩余行数。 +``` + +### TSL-048: 查询商品数量 + +```text +请写一份 .tsl 代码: +有一批商品数据,每行包含商品编号和数量。 +请用 TS-SQL 只取数量大于 3 的行,并输出结果行数。 +``` + +### TSL-049: 筛选并排序成绩 + +```text +请写一份 .tsl 代码: +有一批姓名和分数。 +请用 TS-SQL 只保留分数大于等于 60 的人,并按分数从高到低排序。 +最后输出第一行的姓名。 +``` + +### TSL-050: 部门金额汇总 + +```text +请写一份 .tsl 代码: +有一批部门和金额数据。 +请用 TS-SQL 按部门汇总金额,并输出汇总后的行数。 +``` + +### TSL-051: 客户订单关联 + +```text +请写一份 .tsl 代码: +有一组客户数据和一组订单数据,它们通过客户编号关联。 +请用 TS-SQL 得到客户名称和订单金额,并输出关联后的行数。 +``` + +### TSL-052: 多种数字写法 + +```text +请写一份 .tsl 代码: +有几个配置值:0x2A、0b1010、0o12、200L、6E2。 +请分别输出它们对应的类型判断结果。 +``` + +### TSL-053: 日期和时间 + +```text +请写一份 .tsl 代码: +有一个日期 20240618T,还有一个带时间的值 20240618.1530T。 +请分别输出日期字符串和时间字符串。 +``` + +### TSL-054: 数字真假判断 + +```text +请写一份 .tsl 代码: +先输出 true 和 false。 +再分别判断 4、0、-2 在 if 里会走哪个分支,并输出分支标记。 +``` + +### TSL-055: Nil 参与计算 + +```text +请写一份 .tsl 代码: +请输出 ifNil(nil) 的结果。 +再输出 nil + 5、5 + nil,并检查 nil + nil 是不是 nil。 +``` + +### TSL-056: 复数信息 + +```text +请写一份 .tsl 代码: +准备两个复数:8 + 6j 和 complex(3, -4)。 +请输出第一个复数的实部、虚部,并输出第二个值是不是复数。 +``` + +### TSL-057: 批次报告 + +```text +请写一份 .tsl 代码: +一批货有 17 件,每箱装 5 件;优先级是 3;距离是 9,基准是 4;ratio_base 是 7。 +请输出完整箱数、剩余件数、优先级的四次方、距离与基准的按位关系结果, +以及 ratio_base 与 3 的左除计算结果。 +``` + +### TSL-058: 补货数量 + +```text +请写一份 .tsl 代码: +最低库存是 20,当前库存是 14。 +如果库存不足,reorder_count 就是最低库存减当前库存;否则是 0。 +请用条件表达式得到 reorder_count,并输出它。 +``` + +### TSL-059: 候补分数 + +```text +请写一份 .tsl 代码: +primary_score 是 12,missing_score 是 0,候补值是 99。 +请用省略真值的条件表达式分别得到两个最终分数,并输出。 +``` + +### TSL-060: 发货判断 + +```text +请写一份 .tsl 代码: +paid 是 true,blocked 是 false,amount 是 120。 +请用 and、or、not 判断是否允许发货,并输出结果。 +``` + +### TSL-061: 权限掩码 + +```text +请写一份 .tsl 代码: +read_write 是 6,audit_exec 是 3。 +请输出共同权限、合并权限、差异权限,以及 read_write 取反后的结果。 +``` + +### TSL-062: 计数调整 + +```text +请写一份 .tsl 代码: +counter 一开始是 5。 +先加 4,再自增一次,最后输出 counter。 +``` + +### TSL-063: 安全读取订单金额 + +```text +请写一份 .tsl 代码: +maybe_order 是 nil。 +请安全读取 maybe_order.total,并输出读取结果是不是 nil。 +``` + +### TSL-064: 阈值范围 + +```text +请写一份 .tsl 代码: +请判断 3、8、20 是否满足从小到大的连续比较,并输出结果。 +``` + +### TSL-065: 三组指标逐项比较 + +```text +请写一份 .tsl 代码: +有三组指标:2、4、6;3、5、7;4、6、8。 +请逐项判断第一组是否小于第二组、第二组是否小于第三组, +并输出得到的三个结果。 +``` + +### TSL-066: 发票号格式 + +```text +请写一份 .tsl 代码: +发票号是 "INV-2024-07"。 +请判断它是不是以 "INV-" 开头,并且后面包含数字,然后输出结果。 +``` + +### TSL-067: 带注释的小脚本 + +```text +请写一份 .tsl 代码: +请包含两种 TSL 支持的注释写法。 +然后把 daily_total 设为 31,并输出它。 +``` + +### TSL-068: 编译时模式选择 + +```text +请写一份 .tsl 代码: +如果定义了 FAST_MODE,就输出 "fast";否则输出 "safe"。 +请用条件编译完成。 +``` + +### TSL-069: 临时上下文 + +```text +请写一份 .tsl 代码: +请使用运行时 with 单星块。 +在临时上下文里设置一个字段,并在块内输出这个字段。 +``` + +### TSL-070: 嵌套上下文 + +```text +请写一份 .tsl 代码: +请使用运行时 with 双星块。 +在嵌套上下文里读取外层字段,并输出组合结果。 +``` + +### TSL-071: 带超时的远程式调用 + +```text +请写一份 .tsl 代码: +准备一个“慢速评分”的功能,名字由你自己取,它返回 12。 +请用网格调用方式调用它,并设置超时时间,然后输出得到的结果。 +``` + +### TSL-072: 全局缓存 + +```text +请写一份 .tsl 代码: +把 "session_limit" 这个全局缓存设为 300。 +再读取它并输出,同时输出这个缓存是否存在。 +``` + +### TSL-073: 调试结果 + +```text +请写一份 .tsl 代码: +请做一个“检查金额”的功能,名字由你自己取。 +如果输入小于 0,请用 debugReturn 返回调试值;否则返回原值。 +请用 -1 调用它并输出结果。 +``` + +### TSL-074: 简单计时 + +```text +请写一份 .tsl 代码: +请用内置计时开始和结束功能包住一个小循环,并输出计时结果。 +``` + +### TSL-075: 兜底跳转 + +```text +请写一份 .tsl 代码: +flag 是 false。 +如果 flag 为 false,就跳到 fallback 标签。 +fallback 里输出 "fallback"。 +``` + +### TSL-076: 账户卡片 + +```text +请写一份 .tsl 代码: +我需要一种“账户卡片”对象,类型名由你自己取。 +它要有一个公开字段,用来保存持有人姓名,字段名也由你自己取。 +脚本里创建一张卡,把持有人设为 "Lina",然后输出这个字段。 +``` + +### TSL-077: 仪表盒 + +```text +请写一份 .tsl 代码: +我需要一种“仪表盒”对象,类型名由你自己取。 +创建它时传入初始读数,保存到 reading。 +它有一个“前进一步”的动作,动作名由你自己取,每次让读数增加 2,并给出新的读数。 +脚本里创建一个初始读数为 10 的对象,输出调用这个动作后的结果。 +``` + +### TSL-078: 设备总数 + +```text +请写一份 .tsl 代码: +我需要一种“设备计数器”类型,类型名由你自己取,它有一个所有对象共享的 total_count。 +脚本里把 total_count 设为 77,然后输出它。 +``` + +### TSL-079: 汇率工具 + +```text +请写一份 .tsl 代码: +我需要一种“汇率计算”类型,类型名由你自己取,上面直接提供一个“倍率相乘”的功能。 +它返回 a * b。 +脚本里通过类型本身调用这个功能处理 4 和 5,并输出结果。 +``` + +### TSL-080: 货架编码 + +```text +请写一份 .tsl 代码: +我需要一种“货架盒”对象,类型名由你自己取。 +它内部有一个保存货架编码的字段,字段名由你自己取。 +对外通过一个属性读写这个编码,属性名也由你自己取。 +脚本里创建对象,把编码设为 "S-8",然后通过属性输出编码。 +``` + +### TSL-081: 客户显示名 + +```text +请写一份 .tsl 代码: +我需要一种“客户名称”对象,类型名由你自己取。 +它内部有一个 string 类型字段,用来保存原始姓名,字段名由你自己取。 +对外通过一个带类型的属性访问显示姓名,属性名也由你自己取。 +脚本里设置并输出这个显示姓名属性。 +``` + +### TSL-082: 两种渲染方式 + +```text +请写一份 .tsl 代码: +我需要一种“格式化工具”对象,类型名由你自己取。 +它有两个同名动作,动作名由你自己取:一个接收一个值,一个接收两个值。 +脚本里分别调用这两种动作,并输出结果。 +``` + +### TSL-083: 自行车对象 + +```text +请写一份 .tsl 代码: +我需要一种“交通工具基础对象”,类型名由你自己取。 +它有一个说明类别的动作,动作名由你自己取,结果是 "vehicle"。 +再做一种“自行车对象”,类型名也由你自己取,继承前面的基础对象, +并增加一个说明轮子数量的动作,动作名由你自己取,结果是 2。 +脚本里创建自行车对象,输出类别和轮子数量。 +``` + +### TSL-084: 折扣价格标签 + +```text +请写一份 .tsl 代码: +我需要一种“价格基础对象”,类型名由你自己取。 +它有一个可被子类型改写的标签动作,动作名由你自己取,默认结果是 "base"。 +再做一种“折扣价格对象”,类型名也由你自己取,把这个标签动作的结果改成 "discount"。 +脚本里创建折扣价格对象并输出标签。 +``` + +### TSL-085: 追加消息 + +```text +请写一份 .tsl 代码: +我需要一种“基础消息对象”,类型名由你自己取。 +它有一个给出文字的动作,动作名由你自己取,结果是 "base"。 +再做一种“提醒消息对象”,类型名也由你自己取。 +它的文字动作要先调用父级同名动作,再追加 "-alert"。 +脚本里输出提醒消息对象的文字。 +``` + +### TSL-086: 类外补充方法 + +```text +请写一份 .tsl 代码: +我需要一种“票据打印器”,类型名由你自己取。 +类型里面只先写出一个“打印编号”动作的名字,动作名由你自己取。 +请在类型外面补上这个动作的内容,让它给出 "T-100"。 +脚本里创建对象并输出结果。 +``` + +### TSL-087: 按名称创建对象 + +```text +请写一份 .tsl 代码: +我需要一种“动态盒子”对象,类型名由你自己取。 +它有一个给出数值的动作,动作名由你自己取,结果是 64。 +脚本里请通过字符串里的类型名创建这个对象,并输出这个数值。 +``` + +### TSL-088: 临时句柄清理 + +```text +请写一份 .tsl 代码: +我需要一种“临时句柄”对象,类型名由你自己取。 +它被销毁时要输出 "released"。 +脚本里创建它,然后把引用设为 nil。 +``` + +### TSL-089: 外部评分函数 + +```text +请写一份 .tsl 代码: +有一个外部提供的“评分”功能,TSL 中使用的名字由你自己取,它接收一个值并给出结果。 +这里只需要写出它和外部功能的连接写法,不需要调用。 +``` + +### TSL-090: 外部日志动作 + +```text +请写一份 .tsl 代码: +有一个外部提供的“写日志”动作,TSL 中使用的名字由你自己取,它接收一段文本。 +这里只需要写出它和外部动作的连接写法,不需要调用。 +``` + +### TSL-091: 包装原生函数指针 + +```text +请写一份 .tsl 代码: +假设 native_ptr 已经保存了一个原生函数指针。 +请按 TSL 支持的方式把它包装成可调用对象,并演示传入两个数字调用。 +``` + +### TSL-092: 后台任务 + +```text +请写一份 .tsl 代码: +准备一个后台任务,名字由你自己取,里面输出 "work"。 +请用线程相关写法启动它,并保持代码尽量小。 +``` + +### TSL-093: FMArray 尺寸 + +```text +请写一份 .tsl 代码: +创建一个 2 行 3 列的 FMArray。 +请输出它是不是 FMArray,并输出行数、列数和总尺寸。 +``` + +### TSL-094: 矩阵大小 + +```text +请写一份 .tsl 代码: +准备一个两行三列的数字矩阵。 +请输出它的行数、列数和总尺寸。 +``` + +### TSL-095: 金额对象相加 + +```text +请写一份 .tsl 代码: +我需要一种“金额盒子”对象,类型名由你自己取,里面有 value。 +请让两个这种对象可以直接相加,相加后得到新的同类对象。 +脚本里创建两个对象,并输出相加后的 value。 +``` + +### TSL-096: 区分局部和全局功能 + +```text +请写一份 .tsl 代码: +写一个局部功能,名字故意和某个系统功能一样。 +脚本里请分别调用局部功能和全局/系统功能,并输出两次结果。 +``` + +### TSL-097: 关闭默认写回 + +```text +请写一份 .tsl 代码: +关闭默认的输入写回行为。 +请做一个“双值触碰”动作,名字由你自己取:普通输入不要写回,明确标记为 var 的输入要写回。 +脚本调用后输出两个变量,证明只有 var 那个改变了。 +``` + +### TSL-098: In 和 Out + +```text +请写一份 .tsl 代码: +关闭默认的输入写回行为。 +请做一个“同步几个值”的动作,名字由你自己取,接收三个值,并只让 out 标记的值写回。 +脚本调用时使用 in 和 out 前缀,然后输出三个变量。 +``` + +### TSL-099: 提前退出 + +```text +请写一份 .tsl 代码: +请做一个“保护性计算”的功能,名字由你自己取。 +如果输入小于 0,就直接退出;否则给出输入乘以 2 的结果。 +脚本里分别用 -1 和 6 调用它,并输出两次结果。 +``` + +### TSL-100: 订单汇总 + +```text +请写一份 .tsl 代码: +有一批订单行,每行包含商品名、数量、单价。 +请做一个“计算单行金额”的功能,名字由你自己取。 +遍历所有订单行,数量为 0 的行跳过,其他行累计金额。 +如果总金额大于 100,输出 "bulk",否则输出 "normal"。 +最后输出总金额。 +``` diff --git a/test/agent/test_cases.md b/test/agent/test_cases.md deleted file mode 100644 index 7335472e..00000000 --- a/test/agent/test_cases.md +++ /dev/null @@ -1,2218 +0,0 @@ -# TSL Agent Codegen Prompt Tests - -This file defines manual prompt tests for evaluating whether an agent can read -`docs/tsl` and produce syntactically correct TSL code on the first attempt. - -These are not TSL language docs. They are agent evaluation prompts. Keep grammar -facts in `docs/tsl`; keep agent test prompts here. - -## How To Run - -For each case: - -1. Start from a fresh agent context that has access to this repository. -2. Send only the `Prompt` text to the agent unless the test runner has a - standard system prompt. -3. Allow the agent to read `docs/tsl`. -4. Score the first complete answer only. Do not let the agent revise. -5. Record pass/fail against the `Pass criteria`. - -Recommended runner setup: - -```text -You are in this repository. TSL grammar and reference docs are under docs/tsl. -When asked to write TSL, read the relevant docs/tsl pages first. Do not infer -syntax from Pascal, TypeScript, JavaScript, Python, or SQL. -``` - -## Scoring - -- `2` = first answer satisfies all pass criteria. -- `1` = mostly correct, but has one minor issue that does not change the tested - grammar point. -- `0` = wrong file model, invalid TSL syntax, invented syntax, or missed the - tested grammar point. - -Track these aggregate metrics: - -- Overall first-pass accuracy. -- Accuracy by topic group. -- Most common failure patterns. -- Whether failures came from not reading docs, reading the wrong docs page, or - overfitting to another language. - -## Global Failure Patterns - -Flag these as failures whenever they appear in generated code: - -- Uses `=` for ordinary assignment instead of `:=`. -- Uses comma separators in a typed parameter list, such as - `function Add(a: integer, b: integer): integer`. -- Writes named arguments as `a = 1` instead of `a: 1`. -- Writes a `.tsl` script as only top-level reusable declarations when executable - script behavior was requested. -- Appends executable script statements after a `.tsl` function or class - declaration section. -- Writes a top-level class as `class Name ... end;` instead of - `type Name = class ... end;`. -- Uses bare class names for class functions or static fields instead of - `class(Name)`. -- Invents syntax not documented in `docs/tsl`. - -## Test Cases - -### TSL-001: Typed Add Function - -Prompt: - -```text -请根据本仓库 docs/tsl 的语法,写一个 TSL 加法函数 Add。 -要求两个参数都有整数类型,返回值也要有整数类型。 -只输出代码。 -``` - -Expected focus: - -- Basic `function` declaration. -- Typed parameters and typed return value. - -Pass criteria: - -- Uses `function Add(a: integer; b: integer): integer;`. -- Uses `return a + b;`. -- Uses `begin ... end;`. -- Does not separate typed parameters with commas. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-002: Executable Script Calling A Local Function - -Prompt: - -```text -写一段可执行的 .tsl 脚本:计算 1 + 2,并用 writeLn 输出结果。 -加法逻辑封装成 Add 函数,脚本里调用它。 -只输出代码。 -``` - -Expected focus: - -- `.tsl` file model. -- Executable statements before local function declarations. - -Pass criteria: - -- Script statements appear before the `function Add...` declaration. -- Calls `writeLn(Add(1, 2));` or an equivalent statement before declarations. -- Does not append executable statements after the function declaration. -- Uses `:=` for ordinary assignments if assignments are introduced. - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-003: Reusable Function File - -Prompt: - -```text -我要一个可复用的 .tsf 函数扩展文件,里面只有一个函数 IsPositive, -输入整数 x,返回 x 是否大于 0。只输出代码。 -``` - -Expected focus: - -- `.tsf` reusable declaration model. -- No executable script entry statements. - -Pass criteria: - -- Outputs a top-level `function IsPositive(x: integer);` or typed return variant - if supported by the chosen evidence. -- Function body returns `x > 0`. -- Does not add `.tsl` entry statements such as `writeLn(...)`. -- Does not invent an undocumented `boolean` return type. - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-004: Procedure With Write-Back Parameter - -Prompt: - -```text -写一段 .tsl 脚本,定义一个过程 Bump,把传入变量加 1。 -脚本里先把 a 设为 1,调用 Bump(a),再输出 a。只输出代码。 -``` - -Expected focus: - -- `procedure` only when explicitly requested. -- `var` parameter write-back. -- `.tsl` declaration section order. - -Pass criteria: - -- Uses `procedure Bump(var x);`. -- Assigns `a := 1;` before calling `Bump(a);`. -- Outputs `a` before the procedure declaration section. -- Does not put a return type on the `procedure` header. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/02_core_model.md` - -### TSL-005: Named Parameter Call - -Prompt: - -```text -写一个 TSL 示例,定义函数 MakePair(a, b),返回 array(a, b)。 -调用时必须使用命名参数,把 b 传 20,把 a 传 10,并输出两个元素。 -只输出代码。 -``` - -Expected focus: - -- Named argument syntax. -- Array indexing. - -Pass criteria: - -- Calls the function with `MakePair(b: 20, a: 10)` or equivalent named argument - order. -- Does not use `MakePair(b = 20, a = 10)`. -- Reads array elements with zero-based array indexes. -- Keeps executable statements before the function declaration in `.tsl`. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-006: Default Variable Model - -Prompt: - -```text -写一段最简单的 TSL 脚本:把 3 赋给 a,把 4 赋给 b, -再输出 a * b。不要做多余声明。只输出代码。 -``` - -Expected focus: - -- Ordinary variables do not need a `var` declaration by default. -- Assignment operator. - -Pass criteria: - -- Uses `a := 3;` and `b := 4;`. -- Does not use `a = 3;` or `b = 4;`. -- Does not add unnecessary `var` declarations. - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-007: Explicit Variable Mode - -Prompt: - -```text -写一段 TSL 脚本,开启 explicit 模式,声明变量 total, -把 total 设置为 0,然后输出它。只输出代码。 -``` - -Expected focus: - -- `{$explicit+}`. -- Explicit `var` declaration. - -Pass criteria: - -- Starts with `{$explicit+}` or places it before first undeclared variable use. -- Declares `var total;`. -- Assigns with `total := 0;`. - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-008: Constant Initialization - -Prompt: - -```text -写一段 TSL 脚本,定义常量 max_count 为 3 + 4, -然后输出 max_count。只输出代码。 -``` - -Expected focus: - -- `const name = value;` is constant initialization, not ordinary assignment. - -Pass criteria: - -- Uses `const max_count = 3 + 4;`. -- Outputs `max_count`. -- Does not later assign to `max_count`. - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-009: Single-Variable Destructuring - -Prompt: - -```text -写一段 TSL 脚本,从 array(7, 8, 9) 里只拆出第一个值到 first, -然后输出 first。只输出代码。 -``` - -Expected focus: - -- Single-variable destructuring keeps the trailing comma. - -Pass criteria: - -- Uses `[first, ] := array(7, 8, 9);`. -- Does not use `[first] := ...`. - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-010: If Else Block - -Prompt: - -```text -写一段 TSL 脚本:如果 score >= 60,就把 result 设为 "pass", -否则设为 "fail",最后输出 result。score 设为 70。只输出代码。 -``` - -Expected focus: - -- Block-style `if ... then begin ... end else begin ... end`. -- No semicolon between `then` block `end` and `else`. - -Pass criteria: - -- Uses `if score >= 60 then` followed by a valid block. -- Does not put a semicolon after the `then` branch `end` before `else`. -- Outputs after the conditional block, not inside only one branch. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-011: For Loop With Step - -Prompt: - -```text -写一段 TSL 脚本,用 for 循环计算 1、3、5 的和并输出。 -要求使用 step。只输出代码。 -``` - -Expected focus: - -- `for i := 1 to 5 step 2 do`. - -Pass criteria: - -- Uses `for i := 1 to 5 step 2 do`. -- Accumulates with `:=` or `+=`. -- Outputs `9` or the computed sum variable. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-012: Array Traversal - -Prompt: - -```text -写一段 TSL 脚本,遍历 array(10, 20, 30),每行输出索引和值的和。 -必须使用 for i, v in data。只输出代码。 -``` - -Expected focus: - -- Array traversal form. -- Zero-based index behavior. - -Pass criteria: - -- Uses `for i, v in data do`. -- Uses `data := array(10, 20, 30);`. -- Does not invent Python-style or JavaScript-style iteration syntax. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-013: Array And String Indexing - -Prompt: - -```text -写一段 TSL 脚本,创建 array(10, 20, 30) 和字符串 "ABC"。 -输出数组第一个元素,再输出字符串第一个字符。只输出代码。 -``` - -Expected focus: - -- Arrays are zero-based. -- Strings are one-based. - -Pass criteria: - -- Reads the first array element with `arr[0]`. -- Reads the first string character with `s[1]`. -- Does not use `s[0]`. - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/03_values_and_literals.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-014: Hash-Like Array - -Prompt: - -```text -写一段 TSL 脚本,用 array 创建一个带字符串键的表, -包含 Code = "0001" 和 Price = 12.3,然后输出 Code。只输出代码。 -``` - -Expected focus: - -- `array("Code": "0001", "Price": 12.3)`. - -Pass criteria: - -- Uses string-key `array(...)` syntax. -- Reads with `hash["Code"]` or equivalent variable name. - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-015: in Versus sqlin - -Prompt: - -```text -写一段 TSL 脚本,同时演示: -1 是否属于 array(1, 2),以及 array(1, 2) 这一整行是否存在于 -array((1, 2), (3, 4))。分别输出两个判断结果。只输出代码。 -``` - -Expected focus: - -- Element/subset relation uses `in`. -- Whole-row relation uses `sqlin`. - -Pass criteria: - -- Uses `1 in array(1, 2)`. -- Uses `array(1, 2) sqlin array((1, 2), (3, 4))`. -- Does not use `in` for the whole-row test. - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-016: Explicit String To Integer Conversion - -Prompt: - -```text -写一段 TSL 脚本,把字符串 "1234" 转成整数后加 1, -再输出结果。只输出代码。 -``` - -Expected focus: - -- Explicit conversion instead of relying on mixed-type arithmetic. - -Pass criteria: - -- Uses `strToInt(...)`. -- Does not directly compute `"1234" + 1`. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-017: Nil Handling - -Prompt: - -```text -写一段 TSL 脚本,创建空数组 arr,判断 arr[0] 是否为 nil, -并输出判断结果。只输出代码。 -``` - -Expected focus: - -- Empty array missing element returns `nil`. -- Explicit nil comparison. - -Pass criteria: - -- Uses `arr := array();`. -- Checks `arr[0] = nil` or uses documented `ifNil(...)`. -- Does not invent `null`, `None`, or `undefined`. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-018: Regex-Like - -Prompt: - -```text -写一段 TSL 脚本,判断字符串 "abc" 是否匹配以 a 开头的模式, -用 like 运算符,并输出结果。只输出代码。 -``` - -Expected focus: - -- `like` right side is regex-like, not SQL `%` wildcard. - -Pass criteria: - -- Uses a regex-style pattern such as `"^a.*"` or another documented-compatible - regex pattern. -- Does not use `"a%"` as the pattern. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-019: Basic Class - -Prompt: - -```text -写一段 .tsl 脚本,定义 Person 类,包含 public 字段 name。 -脚本里创建 Person,把 name 设为 "Tom",然后输出 name。只输出代码。 -``` - -Expected focus: - -- Top-level class declaration syntax. -- `.tsl` executable statements before class declaration section. - -Pass criteria: - -- Uses `type Person = class`. -- Includes `public` before `name;`. -- Creates with `new Person()`. -- Does not write `class Person`. -- Does not append executable statements after the class declaration. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` -- `docs/tsl/syntax/02_core_model.md` - -### TSL-020: Public Constructor - -Prompt: - -```text -写一段 .tsl 脚本,定义 Counter 类。 -构造函数接收初始值 v,保存到 value;Inc 方法把 value 加 1 并返回。 -脚本里 new Counter(10),输出 Inc 的结果。只输出代码。 -``` - -Expected focus: - -- `function create(...)` constructor under `public`. -- Instance method body accesses members directly. - -Pass criteria: - -- Defines `type Counter = class`. -- Puts `function create(v);` in a `public` section. -- Uses `value := v;` in `create`. -- Uses `value := value + 1; return value;` or equivalent in `Inc`. -- Does not make `create` private or protected. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-021: Static Field Access - -Prompt: - -```text -写一段 TSL 示例,定义 THuman 类,包含 static 字段 mCount。 -先把 mCount 设置为 100,再输出它。只输出代码。 -``` - -Expected focus: - -- Static field access through class type. - -Pass criteria: - -- Defines `static mCount;`. -- Sets or reads it through `class(THuman).mCount`. -- Does not use `THuman.mCount`. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-022: Class Function Access - -Prompt: - -```text -写一个 TSL 类 MathBox,里面有 class function Add(a, b),返回 a + b。 -再写脚本输出 MathBox 的 Add(1, 2) 结果。只输出代码。 -``` - -Expected focus: - -- Class function declaration. -- Class function call through class type. - -Pass criteria: - -- Defines a `class function Add(a, b);` inside `type MathBox = class`. -- Calls via `class(MathBox).Add(1, 2)` or another documented class-type path. -- Does not call `MathBox.Add(1, 2)`. -- Keeps executable call before the class declaration in `.tsl`. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-023: Full Unit Skeleton - -Prompt: - -```text -写一个 .tsf unit,名字是 DemoUnit。 -对外暴露函数 Ping,调用返回 1。使用完整 interface / implementation 结构。 -只输出代码。 -``` - -Expected focus: - -- Full `unit` structure. -- `end.` terminator. - -Pass criteria: - -- Starts with `unit DemoUnit;`. -- Has `interface` and `implementation` sections. -- Declares `function Ping();` in `interface`. -- Implements `function Ping(); begin return 1; end;`. -- Ends the unit with `end.`. - -Source docs: - -- `docs/tsl/syntax/09_units_and_scope.md` -- `docs/tsl/syntax/01_quickstart.md` - -### TSL-024: Top-Level uses Before Statements - -Prompt: - -```text -写一段 .tsl 脚本,使用 UnitA 和 UnitB 两个 unit, -然后调用 Run() 并输出结果。注意 uses 的位置。只输出代码。 -``` - -Expected focus: - -- Top-level `uses` before ordinary statements. -- Multiple units in one `uses` statement. - -Pass criteria: - -- Uses `uses UnitA, UnitB;` before executable statements. -- Does not write ordinary statements before top-level `uses`. -- Does not generate two separate top-level `uses` statements as the default. - -Source docs: - -- `docs/tsl/syntax/09_units_and_scope.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-025: Function-Body uses Placement - -Prompt: - -```text -写一个 TSL 函数 RunInFunction,函数体内使用 DemoUnit, -然后返回 Ping()。只输出这个函数代码。 -``` - -Expected focus: - -- Function-body `uses` must be the first statement. - -Pass criteria: - -- Writes `uses DemoUnit;` as the first statement after `begin`. -- Does not put any assignment or other statement before function-body `uses`. -- Does not repeat `uses` inside the same function body. - -Source docs: - -- `docs/tsl/syntax/09_units_and_scope.md` - -### TSL-026: Try Except - -Prompt: - -```text -写一段 TSL 脚本,用 try/except 捕获 raise "bad", -在 except 中输出 exceptObject.errInfo。只输出代码。 -``` - -Expected focus: - -- TSL exception syntax. -- `exceptObject` fields. - -Pass criteria: - -- Uses `try ... except ... end`. -- Raises with `raise "bad"`. -- Reads `exceptObject.errInfo` in the `except` block. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-027: Ambiguous File Model - -Prompt: - -```text -帮我写一个 TSL 的加法函数。 -``` - -Expected focus: - -- Handling an underspecified user request. -- Avoiding invented file model assumptions. - -Pass criteria: - -- Either produces only a minimal reusable function declaration, or explicitly - states the file-model assumption before the code. -- Uses `function`, not `procedure`. -- Does not generate invalid `.tsl` declaration ordering. -- Does not invent parameter types if the prompt did not require them. - -Source docs: - -- `docs/tsl/index.md` -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-028: Bad Prompt With Type Requirement - -Prompt: - -```text -帮我写一个tsl代码,写一个加法,需要参数类型和返回类型。 -``` - -Expected focus: - -- Robustness to informal Chinese prompts. -- Correct typed function syntax. - -Pass criteria: - -- Uses a `function` with typed parameters and typed return value. -- Uses semicolons between typed parameters. -- Uses `return a + b;`. -- Does not use TypeScript-like syntax such as - `function add(a: number, b: number): number`. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-029: Anti-Pascal Assignment Trap - -Prompt: - -```text -写一段 TSL 脚本,把 a 设为 1,把 b 设为 2, -如果 a + b 等于 3 就输出 "ok"。只输出代码。 -``` - -Expected focus: - -- Ordinary assignment versus equality comparison. - -Pass criteria: - -- Uses `a := 1;` and `b := 2;`. -- Uses `=` only in the comparison expression. -- Does not use `==`. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-030: No Script After Declaration Trap - -Prompt: - -```text -写一段 .tsl 脚本:先调用 Hello(),Hello 输出 "hello"。 -调用完成后再输出 "done"。只输出代码。 -``` - -Expected focus: - -- All executable script statements must be before the declaration section. -- A natural prompt order can tempt the agent to put `writeLn("done")` after - `function Hello`. - -Pass criteria: - -- Places both `Hello();` and the statement that outputs `"done"` before - `function Hello();`. -- Defines `Hello` after the executable statements. -- Does not append the `"done"` output statement after the function declaration. - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/11_pitfalls.md` - -## Extended Compact Cases - -The first 30 cases above are detailed baseline cases. The following compact -cases broaden grammar coverage while keeping each prompt independently runnable. - -### TSL-031: Numeric Literal Types - -Prompt: - -```text -写一段 TSL 脚本,分别输出 0x10、0b10、0o10、100L、1E2 的类型判断结果。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented numeric literals. -- Uses type checks such as `ifInt`, `ifInt64`, and `ifReal`. -- Does not rewrite the literals into decimal-only values. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-032: Date Time Literals - -Prompt: - -```text -写一段 TSL 脚本,创建 20111231T 和 20101231.0931T, -并分别输出日期和时间字符串。只输出代码。 -``` - -Pass criteria: - -- Uses documented date-time literal forms. -- Uses documented conversion helpers such as `dateToStr` and `timeToStr`. -- Does not invent ISO string literal syntax. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-033: Boolean And Numeric Truthiness - -Prompt: - -```text -写一段 TSL 脚本,输出 true、false,并演示 if 2、if 0、if -1 的判断结果。 -只输出代码。 -``` - -Pass criteria: - -- Uses `true` and `false` directly. -- Treats `0` as false and non-zero numeric values as true. -- Does not invent `True` / `False` capitalization. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-034: Nil Arithmetic Boundary - -Prompt: - -```text -写一段 TSL 脚本,输出 ifNil(nil)、nil + 1、1 + nil, -以及 nil + nil 是否仍为 nil。只输出代码。 -``` - -Pass criteria: - -- Uses `nil`, not `null`, `None`, or `undefined`. -- Uses `ifNil(nil)` or documented `nil` comparison. -- Does not reject `nil + 1` as invalid syntax. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-035: Complex Number Basics - -Prompt: - -```text -写一段 TSL 脚本,创建复数 4 + 3j 和 complex(5, -2), -输出第一个复数的 real、imag 和 ifComplex 判断。只输出代码。 -``` - -Pass criteria: - -- Uses `4 + 3j` or `complex(real, imag)` as documented. -- Uses `real(...)`, `imag(...)`, and `ifComplex(...)`. -- Does not invent Python object methods such as `.real`. - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-036: String Concatenation - -Prompt: - -```text -写一段 TSL 脚本,把 "TS" 和 "L" 拼成 "TSL" 并输出。 -使用 docs/tsl 里确认的字符串连接写法。只输出代码。 -``` - -Pass criteria: - -- Uses documented string concatenation with `+` or `$`. -- Uses TSL string literals. -- Does not call undocumented helpers such as `concat(...)`. - -Source docs: - -- `docs/tsl/syntax/03_values_and_literals.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-037: Arithmetic Operator Coverage - -Prompt: - -```text -写一段 TSL 脚本,分别输出 9 div 4、9 mod 4、2 ^ 3、8 ~ 2、3 \ 2。 -只输出代码。 -``` - -Pass criteria: - -- Uses `div`, `mod`, `^`, `~`, and `\` as documented. -- Does not replace them with JavaScript-style operators. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-038: Conditional Expression - -Prompt: - -```text -写一段 TSL 脚本,a 小于 b 时 value 为 10,否则为 20, -要求使用条件表达式并输出 value。只输出代码。 -``` - -Pass criteria: - -- Uses `condition ? true_value : false_value`. -- Uses `:=` for assignments. -- Does not invent `?:` placement from C/JS incorrectly. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-039: Omitted-True Conditional Expression - -Prompt: - -```text -写一段 TSL 脚本,分别输出 2 ?: 9 和 0 ?: 9 的结果。只输出代码。 -``` - -Pass criteria: - -- Uses the documented `value ?: fallback` form. -- Does not rewrite it as a normal `if` statement unless it preserves the tested - expression form. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-040: Logical Operators - -Prompt: - -```text -写一段 TSL 脚本,使用 and、or、not 组合两个条件,并输出结果。 -只输出代码。 -``` - -Pass criteria: - -- Uses `and`, `or`, and `not`. -- Does not use `!` as logical negation. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: Bitwise Operators - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- Uses dot-prefixed bitwise operators such as `.&`, `.|`, `.!`, and `.^`. -- Does not use ordinary `&`, `|`, or `~` as bitwise operators. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: Compound Assignment And Increment - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- Uses documented `+=` and `a++` or `++a`. -- Initializes with `a := 1;`. -- Does not use `a = a + 2`. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil-Safe Access - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- Uses documented nil-safe access such as `obj?.value`. -- Does not invent optional chaining forms beyond the documented patterns. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: Scalar Chain Comparison - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- Uses scalar chain comparison such as `1 :< 2 :< 3`. -- Does not write Python-style `1 < 2 < 3`. - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: Matrix-Like Chain Comparison - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- Uses matrix chain comparison such as `::<`. -- Reads result array elements by zero-based indexes. -- Does not use scalar `:<` for array-wise comparison. - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: Default Parameter - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- Uses `function AddOne(a = 1);`. -- Calls the function before the `.tsl` declaration section. -- Does not use unsupported default-parameter syntax. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: Typed Default Parameter - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- Uses `function TypedAdd(a: integer = 1): integer;`. -- Does not separate typed parameters with commas. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: Named Parameter Skipping Middle Argument - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- Uses named parameter syntax `c: 3`. -- Checks skipped `b` with `ifNil(b)` or documented nil comparison. -- Keeps executable call before the function declaration. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: call With Named Parameters - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- Uses `call("TestFunc", a: ..., b: ..., c: ...)`. -- Does not write named arguments with `=`. -- Defines `TestFunc` after the call in `.tsl`. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef Switch - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- Uses `{$varByRef-}` and later restores if needed with `{$varByRef+}`. -- Includes one unmodified parameter function and one `var` parameter function. -- Does not rely on another language's value/reference model. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-051: in And out Call Prefixes - -Prompt: - -```text -写一段 TSL 脚本,在 {$varByRef-} 下调用 Touch3(in a, out b, c), -演示只有 b 被写回。只输出代码。 -``` - -Pass criteria: - -- Uses call-site prefixes `in` and `out`. -- Uses `{$varByRef-}`. -- Does not write `in` / `out` as type annotations in the function header. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-052: exit Boundary - -Prompt: - -```text -写一段 TSL 脚本,函数 Demo(x) 在 x > 0 时 exit, -否则 return 99;输出 Demo(1) 和 Demo(0)。只输出代码。 -``` - -Pass criteria: - -- Uses `exit;` inside the function. -- Uses `return 99;` for the other branch. -- Does not treat `exit` as returning an explicit custom value. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-053: Variadic Sum - -Prompt: - -```text -写一个 TSL 可变参数函数 SumAll(...),遍历 Params 求和并返回。 -再输出 SumAll(1, 2, 3, 4)。只输出代码。 -``` - -Pass criteria: - -- Uses `function SumAll(...);`. -- Iterates `Params`. -- Does not invent JavaScript rest syntax. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-054: ParamCount And RealParamCount - -Prompt: - -```text -写一个 TSL 函数 CountArgs(a, b, ...),返回 ParamCount * 10 + RealParamCount。 -输出 CountArgs(1, 2, 3, 4)。只输出代码。 -``` - -Pass criteria: - -- Uses `ParamCount` and `RealParamCount`. -- Uses trailing `...` in the function header. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-055: Variadic Forward With call - -Prompt: - -```text -写一段 TSL 脚本,DoFunc(fc, ...) 通过 call(fc, ...) 转发参数给 Sum3。 -输出 DoFunc("Sum3", 1, 2, 3)。只输出代码。 -``` - -Pass criteria: - -- Uses `call(fc, ...)`. -- Uses `function DoFunc(fc, ...);`. -- Does not manually unpack a fixed number of variadic arguments. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-056: Anonymous Function Variable - -Prompt: - -```text -写一段 TSL 脚本,把匿名函数赋给变量 a, -匿名函数返回 x + y,然后用 call(a, 1, 2) 输出结果。只输出代码。 -``` - -Pass criteria: - -- Uses `a := function(x, y) begin ... end;`. -- Calls via `call(a, 1, 2)` or documented `##a(...)`. -- Does not call the function variable only as `a(1, 2)`. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-057: Anonymous Function As Argument - -Prompt: - -```text -写一段 TSL 脚本,定义 Apply(fun),内部 call(fun, 2, 3)。 -调用 Apply 时直接传入一个匿名乘法函数。只输出代码。 -``` - -Pass criteria: - -- Passes `function(x, y) begin ... end` as an argument. -- Uses `call(fun, 2, 3)` inside `Apply`. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-058: findFunction Call - -Prompt: - -```text -写一段 TSL 脚本,用 findFunction("Add") 找到 Add 函数, -再用文档支持的函数值调用方式输出 Add(1, 2)。只输出代码。 -``` - -Pass criteria: - -- Uses `findFunction("Add")`. -- Calls the returned function with `##f(...)` or `call(f, ...)`. -- Does not call `f(...)` directly. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-059: thisFunction Call - -Prompt: - -```text -写一段 TSL 脚本,用 thisFunction(Add) 得到函数值, -再通过一个 Call 包装函数调用它。只输出代码。 -``` - -Pass criteria: - -- Uses `thisFunction(Add)`. -- Calls the function value with `call(...)` or documented wrapper style. -- Does not quote `Add` if using `thisFunction`. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-060: Global Function Qualification - -Prompt: - -```text -写一段 TSL 示例,局部函数名和全局/系统函数同名时, -用 docs/tsl 里明确的全局函数限定调用写法。只输出代码。 -``` - -Pass criteria: - -- Uses `::FuncName(...)` for global/system function qualification. -- Does not invent namespace separators from other languages. - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-061: Case Statement With Range - -Prompt: - -```text -写一段 TSL 脚本,a 为 4,用 case 判断: -1,2 输出 small;3 到 5 输出 mid;其他输出 other。只输出代码。 -``` - -Pass criteria: - -- Uses `case a of`. -- Uses comma labels and `3 to 5`. -- Uses `else` and closes with `end`. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-062: Case Expression - -Prompt: - -```text -写一段 TSL 脚本,用 case 表达式给 value 赋值, -a 为 2 时 value 是 "two",否则是 "other",然后输出 value。只输出代码。 -``` - -Pass criteria: - -- Uses `value := case ... of ... else ... end;`. -- Does not put `begin ... end` blocks inside expression-form branches. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-063: Repeat Until - -Prompt: - -```text -写一段 TSL 脚本,用 repeat ... until 把 counter 从 3 减到 0, -最后输出 counter。只输出代码。 -``` - -Pass criteria: - -- Uses `repeat ... until counter = 0;`. -- Does not write `do while` syntax. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-064: Break In While Loop - -Prompt: - -```text -写一段 TSL 脚本,用 while true 循环累加 1 到 3, -i 大于 3 时 break,然后输出 sum。只输出代码。 -``` - -Pass criteria: - -- Uses `while true do`. -- Uses `break;` inside the loop. -- Uses TSL block structure for multi-statement loop body. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-065: Continue In While Loop - -Prompt: - -```text -写一段 TSL 脚本,while 循环 i 从 1 到 4, -跳过 i = 2,只累加其他值并输出 sum。只输出代码。 -``` - -Pass criteria: - -- Uses `continue;` for the skipped iteration. -- Does not put the increment after a `continue` path that would cause an - infinite loop. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-066: Try Finally - -Prompt: - -```text -写一段 TSL 脚本,用 try/finally,try 中输出 "run", -finally 中输出 "cleanup"。只输出代码。 -``` - -Pass criteria: - -- Uses `try ... finally ... end`. -- Does not use `catch` or JavaScript-style exception syntax. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-067: Exception Metadata - -Prompt: - -```text -写一段 TSL 脚本,raise "bad" 后在 except 中输出 errInfo、errLine、errNo。 -只输出代码。 -``` - -Pass criteria: - -- Uses `exceptObject.errInfo`, `exceptObject.errLine`, and `exceptObject.errNo`. -- Uses `try ... except ... end`. - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-068: Nested Array Destructuring - -Prompt: - -```text -写一段 TSL 脚本,从 array((1, 2), (3, 4)) 拆出 r1 和 r2, -并输出 r1[0]、r1[1]、r2[0]、r2[1]。只输出代码。 -``` - -Pass criteria: - -- Uses `[r1, r2] := array((1, 2), (3, 4));`. -- Reads nested array elements with zero-based indexes. - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-069: Row Set Operations - -Prompt: - -```text -写一段 TSL 脚本,对 left_rows 和 right_rows 做 union2、intersect、minus、outersect。 -只输出代码。 -``` - -Pass criteria: - -- Uses row-set operators `union2`, `intersect`, `minus`, and `outersect`. -- Does not treat `union2` as preserving duplicate rows. - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-070: filterIn Single Column - -Prompt: - -```text -写一段 TSL 示例,用 filterIn 按单列从结果集中筛选命中行。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `filterIn(...)` shape. -- Does not replace resultset filtering with `in`/`sqlin` set operations. - -Source docs: - -- `docs/tsl/syntax/13_resultset_and_filters.md` - -### TSL-071: filterNotIn - -Prompt: - -```text -写一段 TSL 示例,用 filterNotIn 从结果集中排除命中行。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `filterNotIn(...)` shape. -- Does not use `minus` when the task asks to preserve filtering semantics. - -Source docs: - -- `docs/tsl/syntax/13_resultset_and_filters.md` - -### TSL-072: TS-SQL Minimal Query - -Prompt: - -```text -写一段 TSL 示例,对 array((1, 2), (3, 4)) 使用 TS-SQL 最小查询骨架。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented TS-SQL query form from the syntax docs. -- Does not invent ordinary SQL string execution. - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-073: TS-SQL where And order by - -Prompt: - -```text -写一段 TSL 示例,使用 TS-SQL 对数组结果集按条件过滤并排序。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `where` and `order by` TS-SQL syntax. -- Does not use SQL `%` wildcard assumptions unless documented for TS-SQL. - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-074: TS-SQL group by - -Prompt: - -```text -写一段 TSL 示例,使用 TS-SQL 按字段 group by,并计算每组统计值。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `group by` TS-SQL form. -- Uses documented aggregate/reference helpers only. - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-075: TS-SQL join - -Prompt: - -```text -写一段 TSL 示例,用 TS-SQL join 两个数组结果集。只输出代码。 -``` - -Pass criteria: - -- Uses documented `join` form. -- Does not invent database connection or external SQL execution. - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-076: Runtime with Star - -Prompt: - -```text -写一段 TSL 示例,使用 docs/tsl 中的 with * 块环境写法。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `with *` syntax. -- Does not invent Python `with` semantics. - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-077: Runtime with Double Star - -Prompt: - -```text -写一段 TSL 示例,使用 docs/tsl 中的 with ** 块环境写法。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `with **` syntax. -- Does not generalize beyond the documented runtime context form. - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-078: Grid Call Timeout - -Prompt: - -```text -写一段 TSL 示例,用 # 网格调用并带 timeout。只输出代码。 -``` - -Pass criteria: - -- Uses documented `#Func(...)` and `timeout N` shape. -- Does not turn `timeout` into a normal function argument unless documented. - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-079: Global Cache - -Prompt: - -```text -写一段 TSL 示例,设置全局缓存、读取全局缓存,并判断缓存是否存在。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `setGlobalCache`, `getGlobalCache`, and `ifCache`. -- Does not invent browser/local-storage style APIs. - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-080: Conditional Compilation - -Prompt: - -```text -写一段 TSL 示例,使用 {$ifdef ...} 和 {$else} 做条件编译分支。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented compile-option syntax. -- Does not write runtime `if` when the task asks for conditional compilation. - -Source docs: - -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-081: Comments And Identifiers - -Prompt: - -```text -写一段 TSL 示例,包含 docs/tsl 支持的注释写法和一个普通标识符赋值。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented comment syntax from the lexical structure page. -- Uses `:=` for assignment. - -Source docs: - -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-082: goto Label - -Prompt: - -```text -写一段 TSL 示例,使用 goto 跳转到标签并输出结果。只输出代码。 -``` - -Pass criteria: - -- Uses documented `goto` and label syntax. -- Does not invent C-style label rules if they differ from docs. - -Source docs: - -- `docs/tsl/syntax/15_debug_and_profiler.md` - -### TSL-083: debugReturn - -Prompt: - -```text -写一段 TSL 示例,使用 debugReturn 提前返回调试值。只输出代码。 -``` - -Pass criteria: - -- Uses documented `debugReturn` form. -- Does not confuse it with ordinary `return` unless both are required. - -Source docs: - -- `docs/tsl/syntax/15_debug_and_profiler.md` - -### TSL-084: Profiler Timing - -Prompt: - -```text -写一段 TSL 示例,使用 mtic 和 mtoc 做简单计时。只输出代码。 -``` - -Pass criteria: - -- Uses documented `mtic` / `mtoc` shape. -- Does not invent external timing APIs. - -Source docs: - -- `docs/tsl/syntax/15_debug_and_profiler.md` - -### TSL-085: External Function Declaration - -Prompt: - -```text -写一个 TSL external 函数声明示例,按 docs/tsl 的最小 external 写法。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `external` declaration shape. -- Does not invent FFI syntax from C, Python, or TypeScript. - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-086: External Procedure Declaration - -Prompt: - -```text -写一个 TSL procedure external 示例。只输出代码。 -``` - -Pass criteria: - -- Uses documented `procedure external` shape. -- Does not put a return type on the procedure header. - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-087: Native Function Pointer Wrapper - -Prompt: - -```text -写一段 TSL 示例,按 docs/tsl 包装原生函数指针。只输出代码。 -``` - -Pass criteria: - -- Uses only the documented native-function-pointer wrapper shape. -- Does not invent raw pointer syntax. - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-088: Thread Minimal Pattern - -Prompt: - -```text -写一段 TSL 线程模式最小正例,按 docs/tsl 的线程示例组织。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented thread-mode syntax. -- Does not invent async/await or JavaScript thread syntax. - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-089: Class Property - -Prompt: - -```text -写一个 TSL 类 Box,字段 value 通过 property Value read/write 访问。 -脚本里设置并输出这个属性。只输出代码。 -``` - -Pass criteria: - -- Uses documented `property Name read ... write ...` shape. -- Uses `type Box = class`. -- Creates with `new Box()`. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-090: Typed Class Property - -Prompt: - -```text -写一个 TSL 类 Person,包含 string 类型字段 name_, -并定义带类型注解的 property Name。只输出代码。 -``` - -Pass criteria: - -- Uses field type annotation such as `name_: string;`. -- Uses documented typed property form. -- Does not invent C# property blocks. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-091: Method Overload - -Prompt: - -```text -写一个 TSL 类 Calc,包含两个同名 Add 方法,参数个数不同。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `overload` method form. -- Keeps methods inside `type Calc = class`. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-092: Inheritance - -Prompt: - -```text -写一个 TSL 类 Animal 和继承它的 Dog,Dog 增加一个方法 Speak。 -只输出代码。 -``` - -Pass criteria: - -- Uses `type Dog = class(Animal)`. -- Does not use `extends`. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-093: Virtual Override - -Prompt: - -```text -写一个 TSL 父类 Base,虚方法 Name;子类 Child 覆盖 Name。 -脚本里创建 Child 并输出 Name。只输出代码。 -``` - -Pass criteria: - -- Uses documented `virtual` and `override`. -- Uses `type Child = class(Base)`. -- Creates with `new Child()`. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-094: Inherited Method Call - -Prompt: - -```text -写一个 TSL 子类方法,在方法里调用父类同名方法后再追加自己的逻辑。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `Inherited` call form. -- Does not invent `super.method()` syntax. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-095: Class Method Implementation Outside Class - -Prompt: - -```text -写一个 TSL 类 Greeter,类内只声明 Say 方法, -在类外用 ClassName.Method 形式实现它。只输出代码。 -``` - -Pass criteria: - -- Uses class declaration plus `function Greeter.Say(...)` implementation. -- Does not append executable script statements after the implementation section. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-096: createObject By String Class Name - -Prompt: - -```text -写一段 TSL 示例,用字符串类名通过 createObject 创建本地类实例。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `createObject("ClassName")` shape. -- Uses `new ClassName()` only if explaining it is not the requested string-name - path. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-097: Destructor - -Prompt: - -```text -写一个 TSL 类,定义无参 destroy 函数,在对象引用设为 nil 时触发清理。 -只输出代码。 -``` - -Pass criteria: - -- Uses `function destroy();`. -- Sets the object reference to `nil` in executable script code. -- Does not invent `destructor` keyword. - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-098: FMArray Basics - -Prompt: - -```text -写一段 TSL 示例,创建 FMArray,判断它是 FMArray,并输出尺寸信息。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented FMArray construction from the FMArray page. -- Uses documented FMArray type/size helpers. -- Does not treat plain `array(...)` as automatically being FMArray. - -Source docs: - -- `docs/tsl/syntax/23_fmarray.md` - -### TSL-099: Matrix Deep Dive - -Prompt: - -```text -写一段 TSL 示例,初始化矩阵并使用 mrows、mcols、msize 输出维度。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented matrix initialization. -- Uses `mrows`, `mcols`, and `msize`. - -Source docs: - -- `docs/tsl/syntax/22_matrix_deep_dive.md` - -### TSL-100: Object Operator Overload - -Prompt: - -```text -写一个 TSL 类,重载二元 + 运算符,让两个对象相加得到一个新对象。 -只输出代码。 -``` - -Pass criteria: - -- Uses documented `operator +` overload shape. -- Keeps overload implementation inside a valid `type Name = class` structure. -- Does not invent Python `__add__` or C++ syntax. - -Source docs: - -- `docs/tsl/syntax/24_object_overloads_and_iteration.md` - -## Result Sheet Template - -Copy this table for each evaluated agent: - -| Case | Score | Failure pattern | Notes | -| ------- | ----: | --------------- | ----- | -| TSL-001 | | | | -| TSL-002 | | | | -| TSL-003 | | | | -| TSL-004 | | | | -| TSL-005 | | | | -| TSL-006 | | | | -| TSL-007 | | | | -| TSL-008 | | | | -| TSL-009 | | | | -| TSL-010 | | | | -| TSL-011 | | | | -| TSL-012 | | | | -| TSL-013 | | | | -| TSL-014 | | | | -| TSL-015 | | | | -| TSL-016 | | | | -| TSL-017 | | | | -| TSL-018 | | | | -| TSL-019 | | | | -| TSL-020 | | | | -| TSL-021 | | | | -| TSL-022 | | | | -| TSL-023 | | | | -| TSL-024 | | | | -| TSL-025 | | | | -| TSL-026 | | | | -| TSL-027 | | | | -| TSL-028 | | | | -| TSL-029 | | | | -| TSL-030 | | | | -| TSL-031 | | | | -| TSL-032 | | | | -| TSL-033 | | | | -| TSL-034 | | | | -| TSL-035 | | | | -| TSL-036 | | | | -| TSL-037 | | | | -| TSL-038 | | | | -| TSL-039 | | | | -| TSL-040 | | | | -| TSL-041 | | | | -| TSL-042 | | | | -| TSL-043 | | | | -| TSL-044 | | | | -| TSL-045 | | | | -| TSL-046 | | | | -| TSL-047 | | | | -| TSL-048 | | | | -| TSL-049 | | | | -| TSL-050 | | | | -| TSL-051 | | | | -| TSL-052 | | | | -| TSL-053 | | | | -| TSL-054 | | | | -| TSL-055 | | | | -| TSL-056 | | | | -| TSL-057 | | | | -| TSL-058 | | | | -| TSL-059 | | | | -| TSL-060 | | | | -| TSL-061 | | | | -| TSL-062 | | | | -| TSL-063 | | | | -| TSL-064 | | | | -| TSL-065 | | | | -| TSL-066 | | | | -| TSL-067 | | | | -| TSL-068 | | | | -| TSL-069 | | | | -| TSL-070 | | | | -| TSL-071 | | | | -| TSL-072 | | | | -| TSL-073 | | | | -| TSL-074 | | | | -| TSL-075 | | | | -| TSL-076 | | | | -| TSL-077 | | | | -| TSL-078 | | | | -| TSL-079 | | | | -| TSL-080 | | | | -| TSL-081 | | | | -| TSL-082 | | | | -| TSL-083 | | | | -| TSL-084 | | | | -| TSL-085 | | | | -| TSL-086 | | | | -| TSL-087 | | | | -| TSL-088 | | | | -| TSL-089 | | | | -| TSL-090 | | | | -| TSL-091 | | | | -| TSL-092 | | | | -| TSL-093 | | | | -| TSL-094 | | | | -| TSL-095 | | | | -| TSL-096 | | | | -| TSL-097 | | | | -| TSL-098 | | | | -| TSL-099 | | | | -| TSL-100 | | | | diff --git a/test/agent/test_cases_zh.md b/test/agent/test_cases_zh.md deleted file mode 100644 index d7f54693..00000000 --- a/test/agent/test_cases_zh.md +++ /dev/null @@ -1,3136 +0,0 @@ -# TSL Agent 代码生成提示测试 - -本文件定义了用于评估 agent 能否阅读 `docs/tsl` 并在首次尝试时生成语法正确的 TSL 代码的手动提示测试。 - -这些不是 TSL 语言文档。它们是 agent 评估提示。语法事实保留在 `docs/tsl` 中;agent 测试提示保留在此处。 - -## 运行方法 - -对于每个测试用例: - -1. 从可访问此仓库的全新 agent 上下文开始。 -2. 仅将 `Prompt` 文本发送给 agent,除非测试运行器有标准系统提示。 -3. 允许 agent 阅读 `docs/tsl`。 -4. 仅对第一个完整答案评分。不允许 agent 修订。 -5. 根据 `Pass criteria` 记录通过/失败。 - -推荐的运行器设置: - -```text -You are in this repository. TSL grammar and reference docs are under docs/tsl. -When asked to write TSL, read the relevant docs/tsl pages first. Do not infer -syntax from Pascal, TypeScript, JavaScript, Python, or SQL. -``` - -## 评分标准 - -- `2` = 首次回答满足所有通过标准。 -- `1` = 基本正确,但有一个不影响被测语法点的小问题。 -- `0` = 错误的文件模型、无效的 TSL 语法、虚构的语法或遗漏了被测语法点。 - -跟踪这些汇总指标: - -- 整体首次通过准确率。 -- 按主题组的准确率。 -- 最常见的失败模式。 -- 失败是否来自未阅读文档、阅读了错误的文档页面或过度拟合到另一种语言。 - -## 全局失败模式 - -只要生成的代码中出现以下情况,就标记为失败: - -- 使用 `=` 进行普通赋值而不是 `:=`。 -- 在类型化参数列表中使用逗号分隔符,例如 `function Add(a: integer, b: integer): integer`。 -- 将命名参数写为 `a = 1` 而不是 `a: 1`。 -- 将 `.tsl` 脚本写为仅包含顶层可复用声明,而请求的是可执行脚本行为。 -- 在 `.tsl` function 或 class 声明部分之后追加可执行脚本语句。 -- 将顶层 class 写为 `class Name ... end;` 而不是 `type Name = class ... end;`。 -- 对 class function 或 static 字段使用裸类名而不是 `class(Name)`。 -- 虚构 `docs/tsl` 中未记录的语法。 - -## 测试用例 - -### TSL-001: 类型化加法函数 - -Prompt: - -```text -请根据本仓库 docs/tsl 的语法,写一个 TSL 加法函数 Add。 -要求两个参数都有整数类型,返回值也要有整数类型。 -只输出代码。 -``` - -Expected focus: - -- 基本的 `function` 声明。 -- 类型化参数和类型化返回值。 - -Pass criteria: - -- 使用 `function Add(a: integer; b: integer): integer;`。 -- 使用 `return a + b;`。 -- 使用 `begin ... end;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-002: 调用本地函数的可执行脚本 - -Prompt: - -```text -写一段可执行的 .tsl 脚本:计算 1 + 2,并用 writeLn 输出结果。 -加法逻辑封装成 Add 函数,脚本里调用它。 -只输出代码。 -``` - -Expected focus: - -- `.tsl` 文件模型。 -- 可执行语句在本地函数声明之前。 - -Pass criteria: - -- 脚本语句出现在 `function Add...` 声明之前。 -- 在声明之前调用 `writeLn(Add(1, 2));` 或等效语句。 -- 不在函数声明之后追加可执行语句。 -- 如果引入赋值,使用 `:=` 进行普通赋值。 - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-003: 可复用函数文件 - -Prompt: - -```text -我要一个可复用的 .tsf 函数扩展文件,里面只有一个函数 IsPositive, -输入整数 x,返回 x 是否大于 0。只输出代码。 -``` - -Expected focus: - -- `.tsf` 可复用声明模型。 -- 没有可执行脚本入口语句。 - -Pass criteria: - -- 输出顶层 `function IsPositive(x: integer);` 或类型化返回值变体(如果所选证据支持)。 -- 函数体返回 `x > 0`。 -- 不添加 `.tsl` 入口语句,如 `writeLn(...)`。 -- 不虚构未记录的 `boolean` 返回类型。 - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-004: 带写回参数的过程 - -Prompt: - -```text -写一段 .tsl 脚本,定义一个过程 Bump,把传入变量加 1。 -脚本里先把 a 设为 1,调用 Bump(a),再输出 a。只输出代码。 -``` - -Expected focus: - -- 仅在显式请求时使用 `procedure`。 -- `var` 参数写回。 -- `.tsl` 声明部分顺序。 - -Pass criteria: - -- 使用 `procedure Bump(var x);`。 -- 在调用 `Bump(a);` 之前赋值 `a := 1;`。 -- 在 procedure 声明之前输出 `a`。 -- 不在 `procedure` 头上加返回类型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/02_core_model.md` - -### TSL-005: 命名参数调用 - -Prompt: - -```text -写一个 TSL 示例,定义函数 MakePair(a, b),返回 array(a, b)。 -调用时必须使用命名参数,把 b 传 20,把 a 传 10,并输出两个元素。 -只输出代码。 -``` - -Expected focus: - -- 命名参数语法。 -- Array 索引。 - -Pass criteria: - -- 使用 `MakePair(b: 20, a: 10)` 或等效的命名参数顺序调用函数。 -- 不使用 `MakePair(b = 20, a = 10)`。 -- 使用从零开始的 array 索引读取数组元素。 -- 在 `.tsl` 中保持可执行语句在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-006: 默认变量模型 - -Prompt: - -```text -写一段最简单的 TSL 脚本:把 3 赋给 a,把 4 赋给 b, -再输出 a * b。不要做多余声明。只输出代码。 -``` - -Expected focus: - -- 普通变量默认不需要 `var` 声明。 -- 赋值运算符。 - -Pass criteria: - -- 使用 `a := 3;` 和 `b := 4;`。 -- 不使用 `a = 3;` 或 `b = 4;`。 -- 不添加不必要的 `var` 声明。 - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-007: 显式变量模式 - -Prompt: - -```text -写一段 TSL 脚本,开启 explicit 模式,声明变量 total, -把 total 设置为 0,然后输出它。只输出代码。 -``` - -Expected focus: - -- `{$explicit+}`。 -- 显式 `var` 声明。 - -Pass criteria: - -- 以 `{$explicit+}` 开头或在首次使用未声明变量之前放置。 -- 声明 `var total;`。 -- 使用 `total := 0;` 赋值。 - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-008: 常量初始化 - -Prompt: - -```text -写一段 TSL 脚本,定义常量 max_count 为 3 + 4, -然后输出 max_count。只输出代码。 -``` - -Expected focus: - -- `const name = value;` 是常量初始化,不是普通赋值。 - -Pass criteria: - -- 使用 `const max_count = 3 + 4;`。 -- 输出 `max_count`。 -- 之后不对 `max_count` 赋值。 - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-009: 单变量解构 - -Prompt: - -```text -写一段 TSL 脚本,从 array(7, 8, 9) 里只拆出第一个值到 first, -然后输出 first。只输出代码。 -``` - -Expected focus: - -- 单变量解构保留尾随逗号。 - -Pass criteria: - -- 使用 `[first, ] := array(7, 8, 9);`。 -- 不使用 `[first] := ...`。 - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-010: If Else 块 - -Prompt: - -```text -写一段 TSL 脚本:如果 score >= 60,就把 result 设为 "pass", -否则设为 "fail",最后输出 result。score 设为 70。只输出代码。 -``` - -Expected focus: - -- 块式 `if ... then begin ... end else begin ... end`。 -- `then` 块的 `end` 和 `else` 之间没有分号。 - -Pass criteria: - -- 使用 `if score >= 60 then` 后跟有效块。 -- 不在 `then` 分支的 `end` 之后、`else` 之前放置分号。 -- 在条件块之后输出,不是仅在一个分支内输出。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-011: 带步长的 For 循环 - -Prompt: - -```text -写一段 TSL 脚本,用 for 循环计算 1、3、5 的和并输出。 -要求使用 step。只输出代码。 -``` - -Expected focus: - -- `for i := 1 to 5 step 2 do`。 - -Pass criteria: - -- 使用 `for i := 1 to 5 step 2 do`。 -- 使用 `:=` 或 `+=` 累加。 -- 输出 `9` 或计算的和变量。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-012: Array 遍历 - -Prompt: - -```text -写一段 TSL 脚本,遍历 array(10, 20, 30),每行输出索引和值的和。 -必须使用 for i, v in data。只输出代码。 -``` - -Expected focus: - -- Array 遍历形式。 -- 从零开始的索引行为。 - -Pass criteria: - -- 使用 `for i, v in data do`。 -- 使用 `data := array(10, 20, 30);`。 -- 不虚构 Python 风格或 JavaScript 风格的迭代语法。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-013: Array 和 String 索引 - -Prompt: - -```text -写一段 TSL 脚本,创建 array(10, 20, 30) 和字符串 "ABC"。 -输出数组第一个元素,再输出字符串第一个字符。只输出代码。 -``` - -Expected focus: - -- Array 是从零开始的。 -- String 是从一开始的。 - -Pass criteria: - -- 使用 `arr[0]` 读取第一个数组元素。 -- 使用 `s[1]` 读取第一个字符串字符。 -- 不使用 `s[0]`。 - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/03_values_and_literals.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-014: 类哈希 Array - -Prompt: - -```text -写一段 TSL 脚本,用 array 创建一个带字符串键的表, -包含 Code = "0001" 和 Price = 12.3,然后输出 Code。只输出代码。 -``` - -Expected focus: - -- `array("Code": "0001", "Price": 12.3)`。 - -Pass criteria: - -- 使用字符串键 `array(...)` 语法。 -- 使用 `hash["Code"]` 或等效变量名读取。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-015: in 与 sqlin - -Prompt: - -```text -写一段 TSL 脚本,同时演示: -1 是否属于 array(1, 2),以及 array(1, 2) 这一整行是否存在于 -array((1, 2), (3, 4))。分别输出两个判断结果。只输出代码。 -``` - -Expected focus: - -- 元素/子集关系使用 `in`。 -- 整行关系使用 `sqlin`。 - -Pass criteria: - -- 使用 `1 in array(1, 2)`。 -- 使用 `array(1, 2) sqlin array((1, 2), (3, 4))`。 -- 不对整行测试使用 `in`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-016: 显式字符串到整数转换 - -Prompt: - -```text -写一段 TSL 脚本,把字符串 "1234" 转成整数后加 1, -再输出结果。只输出代码。 -``` - -Expected focus: - -- 显式转换而不是依赖混合类型算术。 - -Pass criteria: - -- 使用 `strToInt(...)`。 -- 不直接计算 `"1234" + 1`。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-017: Nil 处理 - -Prompt: - -```text -写一段 TSL 脚本,创建空数组 arr,判断 arr[0] 是否为 nil, -并输出判断结果。只输出代码。 -``` - -Expected focus: - -- 空数组缺失元素返回 `nil`。 -- 显式 nil 比较。 - -Pass criteria: - -- 使用 `arr := array();`。 -- 检查 `arr[0] = nil` 或使用已记录的 `ifNil(...)`。 -- 不虚构 `null`、`None` 或 `undefined`。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-018: 类正则表达式 Like - -Prompt: - -```text -写一段 TSL 脚本,判断字符串 "abc" 是否匹配以 a 开头的模式, -用 like 运算符,并输出结果。只输出代码。 -``` - -Expected focus: - -- `like` 右侧是类正则表达式,不是 SQL `%` 通配符。 - -Pass criteria: - -- 使用正则风格模式,如 `"^a.*"` 或其他已记录的兼容正则模式。 -- 不使用 `"a%"` 作为模式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: 位运算符 - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用点前缀位运算符,如 `.&`、`.|`、`.!` 和 `.^`。 -- 不使用普通的 `&`、`|` 或 `~` 作为位运算符。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: 复合赋值和自增 - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `+=` 和 `a++` 或 `++a`。 -- 使用 `a := 1;` 初始化。 -- 不使用 `a = a + 2`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil 安全访问 - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 nil 安全访问,如 `obj?.value`。 -- 不虚构超出已记录模式的可选链式调用形式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: 标量链式比较 - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- 使用标量链式比较,如 `1 :< 2 :< 3`。 -- 不写 Python 风格的 `1 < 2 < 3`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: 类矩阵链式比较 - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- 使用矩阵链式比较,如 `::<`。 -- 使用从零开始的索引读取结果数组元素。 -- 不对数组级比较使用标量 `:<`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: 默认参数 - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function AddOne(a = 1);`。 -- 在 `.tsl` 声明部分之前调用函数。 -- 不使用不支持的默认参数语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: 类型化默认参数 - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- 使用 `function TypedAdd(a: integer = 1): integer;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: 跳过中间参数的命名参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用命名参数语法 `c: 3`。 -- 使用 `ifNil(b)` 或已记录的 nil 比较检查跳过的 `b`。 -- 保持可执行调用在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: 带命名参数的 call - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- 使用 `call("TestFunc", a: ..., b: ..., c: ...)`。 -- 不用 `=` 写命名参数。 -- 在 `.tsl` 中的调用之后定义 `TestFunc`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef 开关 - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- 使用 `{$varByRef-}`,如果需要则稍后使用 `{$varByRef+}` 恢复。 -- 包含一个未修饰参数函数和一个 `var` 参数函数。 -- 不依赖其他语言的值/引用模型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-019: 基本 Class - -Prompt: - -```text -写一段 .tsl 脚本,定义 Person 类,包含 public 字段 name。 -脚本里创建 Person,把 name 设为 "Tom",然后输出 name。只输出代码。 -``` - -Expected focus: - -- 顶层 class 声明语法。 -- `.tsl` 可执行语句在 class 声明部分之前。 - -Pass criteria: - -- 使用 `type Person = class`。 -- 在 `name;` 之前包含 `public`。 -- 使用 `new Person()` 创建。 -- 不写 `class Person`。 -- 不在 class 声明之后追加可执行语句。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` -- `docs/tsl/syntax/02_core_model.md` - -### TSL-020: Public 构造函数 - -Prompt: - -```text -写一段 .tsl 脚本,定义 Counter 类。 -构造函数接收初始值 v,保存到 value;Inc 方法把 value 加 1 并返回。 -脚本里 new Counter(10),输出 Inc 的结果。只输出代码。 -``` - -Expected focus: - -- `public` 下的 `function create(...)` 构造函数。 -- 实例方法体直接访问成员。 - -Pass criteria: - -- 定义 `type Counter = class`。 -- 在 `public` 部分放置 `function create(v);`。 -- 在 `create` 中使用 `value := v;`。 -- 在 `Inc` 中使用 `value := value + 1; return value;` 或等效语句。 -- 不将 `create` 设为 private 或 protected。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-021: Static 字段访问 - -Prompt: - -```text -写一段 TSL 示例,定义 THuman 类,包含 static 字段 mCount。 -先把 mCount 设置为 100,再输出它。只输出代码。 -``` - -Expected focus: - -- 通过 class type 访问 static 字段。 - -Pass criteria: - -- 定义 `static mCount;`。 -- 通过 `class(THuman).mCount` 设置或读取。 -- 不使用 `THuman.mCount`。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-022: Class Function 访问 - -Prompt: - -```text -写一个 TSL 类 MathBox,里面有 class function Add(a, b),返回 a + b。 -再写脚本输出 MathBox 的 Add(1, 2) 结果。只输出代码。 -``` - -Expected focus: - -- Class function 声明。 -- 通过 class type 调用 class function。 - -Pass criteria: - -- 在 `type MathBox = class` 内定义 `class function Add(a, b);`。 -- 通过 `class(MathBox).Add(1, 2)` 或其他已记录的 class-type 路径调用。 -- 不调用 `MathBox.Add(1, 2)`。 -- 在 `.tsl` 中保持可执行调用在 class 声明之前。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-023: 完整 Unit 骨架 - -Prompt: - -```text -写一个 .tsf unit,名字是 DemoUnit。 -对外暴露函数 Ping,调用返回 1。使用完整 interface / implementation 结构。 -只输出代码。 -``` - -Expected focus: - -- 完整的 `unit` 结构。 -- `end.` 终止符。 - -Pass criteria: - -- 以 `unit DemoUnit;` 开头。 -- 有 `interface` 和 `implementation` 部分。 -- 在 `interface` 中声明 `function Ping();`。 -- 实现 `function Ping(); begin return 1; end;`。 -- 以 `end.` 结束 unit。 - -Source docs: - -- `docs/tsl/syntax/09_units_and_scope.md` -- `docs/tsl/syntax/01_quickstart.md` - -### TSL-024: 顶层 uses 在语句之前 - -Prompt: - -```text -写一段 .tsl 脚本,使用 UnitA 和 UnitB 两个 unit, -然后调用 Run() 并输出结果。注意 uses 的位置。只输出代码。 -``` - -Expected focus: - -- 顶层 `uses` 在普通语句之前。 -- 一个 `uses` 语句中包含多个 unit。 - -Pass criteria: - -- 在可执行语句之前使用 `uses UnitA, UnitB;`。 -- 不在顶层 `uses` 之前写普通语句。 -- 默认不生成两个独立的顶层 `uses` 语句。 - -Source docs: - -- `docs/tsl/syntax/09_units_and_scope.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-025: 函数体 uses 位置 - -Prompt: - -```text -写一个 TSL 函数 RunInFunction,函数体内使用 DemoUnit, -然后返回 Ping()。只输出这个函数代码。 -``` - -Expected focus: - -- 函数体 `uses` 必须是第一条语句。 - -Pass criteria: - -- 将 `uses DemoUnit;` 作为 `begin` 之后的第一条语句。 -- 不在函数体 `uses` 之前放置任何赋值或其他语句。 -- 不在同一个函数体内重复 `uses`。 - -Source docs: - -- `docs/tsl/syntax/09_units_and_scope.md` - -### TSL-026: Try Except - -Prompt: - -```text -写一段 TSL 脚本,用 try/except 捕获 raise "bad", -在 except 中输出 exceptObject.errInfo。只输出代码。 -``` - -Expected focus: - -- TSL 异常语法。 -- `exceptObject` 字段。 - -Pass criteria: - -- 使用 `try ... except ... end`。 -- 使用 `raise "bad"` 抛出。 -- 在 `except` 块中读取 `exceptObject.errInfo`。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-027: 模糊的文件模型 - -Prompt: - -```text -帮我写一个 TSL 的加法函数。 -``` - -Expected focus: - -- 处理未充分指定的用户请求。 -- 避免虚构文件模型假设。 - -Pass criteria: - -- 要么仅生成最小的可复用函数声明,要么在代码之前明确说明文件模型假设。 -- 使用 `function`,不使用 `procedure`。 -- 不生成无效的 `.tsl` 声明排序。 -- 如果提示未要求参数类型,则不虚构参数类型。 - -Source docs: - -- `docs/tsl/index.md` -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-028: 带类型要求的不规范提示 - -Prompt: - -```text -帮我写一个tsl代码,写一个加法,需要参数类型和返回类型。 -``` - -Expected focus: - -- 对非正式中文提示的鲁棒性。 -- 正确的类型化函数语法。 - -Pass criteria: - -- 使用带类型化参数和类型化返回值的 `function`。 -- 在类型化参数之间使用分号。 -- 使用 `return a + b;`。 -- 不使用类似 TypeScript 的语法,如 `function add(a: number, b: number): number`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-029: 反 Pascal 赋值陷阱 - -Prompt: - -```text -写一段 TSL 脚本,把 a 设为 1,把 b 设为 2, -如果 a + b 等于 3 就输出 "ok"。只输出代码。 -``` - -Expected focus: - -- 普通赋值与相等比较。 - -Pass criteria: - -- 使用 `a := 1;` 和 `b := 2;`。 -- 仅在比较表达式中使用 `=`。 -- 不使用 `==`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: 位运算符 - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用点前缀位运算符,如 `.&`、`.|`、`.!` 和 `.^`。 -- 不使用普通的 `&`、`|` 或 `~` 作为位运算符。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: 复合赋值和自增 - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `+=` 和 `a++` 或 `++a`。 -- 使用 `a := 1;` 初始化。 -- 不使用 `a = a + 2`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil 安全访问 - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 nil 安全访问,如 `obj?.value`。 -- 不虚构超出已记录模式的可选链式调用形式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: 标量链式比较 - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- 使用标量链式比较,如 `1 :< 2 :< 3`。 -- 不写 Python 风格的 `1 < 2 < 3`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: 类矩阵链式比较 - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- 使用矩阵链式比较,如 `::<`。 -- 使用从零开始的索引读取结果数组元素。 -- 不对数组级比较使用标量 `:<`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: 默认参数 - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function AddOne(a = 1);`。 -- 在 `.tsl` 声明部分之前调用函数。 -- 不使用不支持的默认参数语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: 类型化默认参数 - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- 使用 `function TypedAdd(a: integer = 1): integer;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: 跳过中间参数的命名参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用命名参数语法 `c: 3`。 -- 使用 `ifNil(b)` 或已记录的 nil 比较检查跳过的 `b`。 -- 保持可执行调用在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: 带命名参数的 call - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- 使用 `call("TestFunc", a: ..., b: ..., c: ...)`。 -- 不用 `=` 写命名参数。 -- 在 `.tsl` 中的调用之后定义 `TestFunc`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef 开关 - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- 使用 `{$varByRef-}`,如果需要则稍后使用 `{$varByRef+}` 恢复。 -- 包含一个未修饰参数函数和一个 `var` 参数函数。 -- 不依赖其他语言的值/引用模型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` -- `docs/tsl/syntax/11_pitfalls.md` - -### TSL-030: 声明后无脚本陷阱 - -Prompt: - -```text -写一段 .tsl 脚本:先调用 Hello(),Hello 输出 "hello"。 -调用完成后再输出 "done"。只输出代码。 -``` - -Expected focus: - -- 所有可执行脚本语句必须在声明部分之前。 -- 自然的提示顺序可能诱使 agent 在 `function Hello` 之后放置 `writeLn("done")`。 - -Pass criteria: - -- 将 `Hello();` 和输出 `"done"` 的语句都放在 `function Hello();` 之前。 -- 在可执行语句之后定义 `Hello`。 -- 不在函数声明之后追加 `"done"` 输出语句。 - -Source docs: - -- `docs/tsl/syntax/01_quickstart.md` -- `docs/tsl/syntax/02_core_model.md` -- `docs/tsl/syntax/11_pitfalls.md` - -## 扩展紧凑用例 - -前 30 个用例是详细的基线用例。以下紧凑用例扩展了语法覆盖范围,同时保持每个提示独立可运行。 - -### TSL-031: 数字字面量类型 - -Prompt: - -```text -写一段 TSL 脚本,分别输出 0x10、0b10、0o10、100L、1E2 的类型判断结果。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的数字字面量。 -- 使用类型检查,如 `ifInt`、`ifInt64` 和 `ifReal`。 -- 不将字面量重写为仅十进制值。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-032: 日期时间字面量 - -Prompt: - -```text -写一段 TSL 脚本,创建 20111231T 和 20101231.0931T, -并分别输出日期和时间字符串。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的日期时间字面量形式。 -- 使用已记录的转换辅助函数,如 `dateToStr` 和 `timeToStr`。 -- 不虚构 ISO 字符串字面量语法。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-033: Boolean 和数字真值性 - -Prompt: - -```text -写一段 TSL 脚本,输出 true、false,并演示 if 2、if 0、if -1 的判断结果。 -只输出代码。 -``` - -Pass criteria: - -- 直接使用 `true` 和 `false`。 -- 将 `0` 视为 false,将非零数值视为 true。 -- 不虚构 `True` / `False` 大写形式。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-034: Nil 算术边界 - -Prompt: - -```text -写一段 TSL 脚本,输出 ifNil(nil)、nil + 1、1 + nil, -以及 nil + nil 是否仍为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用 `nil`,不使用 `null`、`None` 或 `undefined`。 -- 使用 `ifNil(nil)` 或已记录的 `nil` 比较。 -- 不将 `nil + 1` 拒绝为无效语法。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-035: 复数基础 - -Prompt: - -```text -写一段 TSL 脚本,创建复数 4 + 3j 和 complex(5, -2), -输出第一个复数的 real、imag 和 ifComplex 判断。只输出代码。 -``` - -Pass criteria: - -- 按文档使用 `4 + 3j` 或 `complex(real, imag)`。 -- 使用 `real(...)`、`imag(...)` 和 `ifComplex(...)`。 -- 不虚构 Python 对象方法,如 `.real`。 - -Source docs: - -- `docs/tsl/syntax/17_types_and_conversions.md` - -### TSL-036: 字符串连接 - -Prompt: - -```text -写一段 TSL 脚本,把 "TS" 和 "L" 拼成 "TSL" 并输出。 -使用 docs/tsl 里确认的字符串连接写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的字符串连接,用 `+` 或 `$`。 -- 使用 TSL 字符串字面量。 -- 不调用未记录的辅助函数,如 `concat(...)`。 - -Source docs: - -- `docs/tsl/syntax/03_values_and_literals.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-037: 算术运算符覆盖 - -Prompt: - -```text -写一段 TSL 脚本,分别输出 9 div 4、9 mod 4、2 ^ 3、8 ~ 2、3 \ 2。 -只输出代码。 -``` - -Pass criteria: - -- 按文档使用 `div`、`mod`、`^`、`~` 和 `\`。 -- 不用 JavaScript 风格的运算符替换它们。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: 位运算符 - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用点前缀位运算符,如 `.&`、`.|`、`.!` 和 `.^`。 -- 不使用普通的 `&`、`|` 或 `~` 作为位运算符。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: 复合赋值和自增 - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `+=` 和 `a++` 或 `++a`。 -- 使用 `a := 1;` 初始化。 -- 不使用 `a = a + 2`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil 安全访问 - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 nil 安全访问,如 `obj?.value`。 -- 不虚构超出已记录模式的可选链式调用形式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: 标量链式比较 - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- 使用标量链式比较,如 `1 :< 2 :< 3`。 -- 不写 Python 风格的 `1 < 2 < 3`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: 类矩阵链式比较 - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- 使用矩阵链式比较,如 `::<`。 -- 使用从零开始的索引读取结果数组元素。 -- 不对数组级比较使用标量 `:<`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: 默认参数 - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function AddOne(a = 1);`。 -- 在 `.tsl` 声明部分之前调用函数。 -- 不使用不支持的默认参数语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: 类型化默认参数 - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- 使用 `function TypedAdd(a: integer = 1): integer;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: 跳过中间参数的命名参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用命名参数语法 `c: 3`。 -- 使用 `ifNil(b)` 或已记录的 nil 比较检查跳过的 `b`。 -- 保持可执行调用在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: 带命名参数的 call - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- 使用 `call("TestFunc", a: ..., b: ..., c: ...)`。 -- 不用 `=` 写命名参数。 -- 在 `.tsl` 中的调用之后定义 `TestFunc`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef 开关 - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- 使用 `{$varByRef-}`,如果需要则稍后使用 `{$varByRef+}` 恢复。 -- 包含一个未修饰参数函数和一个 `var` 参数函数。 -- 不依赖其他语言的值/引用模型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-038: 条件表达式 - -Prompt: - -```text -写一段 TSL 脚本,a 小于 b 时 value 为 10,否则为 20, -要求使用条件表达式并输出 value。只输出代码。 -``` - -Pass criteria: - -- 使用 `condition ? true_value : false_value`。 -- 使用 `:=` 进行赋值。 -- 不错误地虚构 C/JS 的 `?:` 位置。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: 位运算符 - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用点前缀位运算符,如 `.&`、`.|`、`.!` 和 `.^`。 -- 不使用普通的 `&`、`|` 或 `~` 作为位运算符。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: 复合赋值和自增 - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `+=` 和 `a++` 或 `++a`。 -- 使用 `a := 1;` 初始化。 -- 不使用 `a = a + 2`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil 安全访问 - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 nil 安全访问,如 `obj?.value`。 -- 不虚构超出已记录模式的可选链式调用形式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: 标量链式比较 - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- 使用标量链式比较,如 `1 :< 2 :< 3`。 -- 不写 Python 风格的 `1 < 2 < 3`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: 类矩阵链式比较 - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- 使用矩阵链式比较,如 `::<`。 -- 使用从零开始的索引读取结果数组元素。 -- 不对数组级比较使用标量 `:<`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: 默认参数 - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function AddOne(a = 1);`。 -- 在 `.tsl` 声明部分之前调用函数。 -- 不使用不支持的默认参数语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: 类型化默认参数 - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- 使用 `function TypedAdd(a: integer = 1): integer;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: 跳过中间参数的命名参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用命名参数语法 `c: 3`。 -- 使用 `ifNil(b)` 或已记录的 nil 比较检查跳过的 `b`。 -- 保持可执行调用在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: 带命名参数的 call - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- 使用 `call("TestFunc", a: ..., b: ..., c: ...)`。 -- 不用 `=` 写命名参数。 -- 在 `.tsl` 中的调用之后定义 `TestFunc`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef 开关 - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- 使用 `{$varByRef-}`,如果需要则稍后使用 `{$varByRef+}` 恢复。 -- 包含一个未修饰参数函数和一个 `var` 参数函数。 -- 不依赖其他语言的值/引用模型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-039: 省略真值的条件表达式 - -Prompt: - -```text -写一段 TSL 脚本,分别输出 2 ?: 9 和 0 ?: 9 的结果。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `value ?: fallback` 形式。 -- 除非保留被测试的表达式形式,否则不重写为普通 `if` 语句。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: 位运算符 - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用点前缀位运算符,如 `.&`、`.|`、`.!` 和 `.^`。 -- 不使用普通的 `&`、`|` 或 `~` 作为位运算符。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: 复合赋值和自增 - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `+=` 和 `a++` 或 `++a`。 -- 使用 `a := 1;` 初始化。 -- 不使用 `a = a + 2`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil 安全访问 - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 nil 安全访问,如 `obj?.value`。 -- 不虚构超出已记录模式的可选链式调用形式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: 标量链式比较 - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- 使用标量链式比较,如 `1 :< 2 :< 3`。 -- 不写 Python 风格的 `1 < 2 < 3`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: 类矩阵链式比较 - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- 使用矩阵链式比较,如 `::<`。 -- 使用从零开始的索引读取结果数组元素。 -- 不对数组级比较使用标量 `:<`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: 默认参数 - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function AddOne(a = 1);`。 -- 在 `.tsl` 声明部分之前调用函数。 -- 不使用不支持的默认参数语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: 类型化默认参数 - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- 使用 `function TypedAdd(a: integer = 1): integer;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: 跳过中间参数的命名参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用命名参数语法 `c: 3`。 -- 使用 `ifNil(b)` 或已记录的 nil 比较检查跳过的 `b`。 -- 保持可执行调用在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: 带命名参数的 call - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- 使用 `call("TestFunc", a: ..., b: ..., c: ...)`。 -- 不用 `=` 写命名参数。 -- 在 `.tsl` 中的调用之后定义 `TestFunc`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef 开关 - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- 使用 `{$varByRef-}`,如果需要则稍后使用 `{$varByRef+}` 恢复。 -- 包含一个未修饰参数函数和一个 `var` 参数函数。 -- 不依赖其他语言的值/引用模型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-040: 逻辑运算符 - -Prompt: - -```text -写一段 TSL 脚本,使用 and、or、not 组合两个条件,并输出结果。 -只输出代码。 -``` - -Pass criteria: - -- 使用 `and`、`or` 和 `not`。 -- 不使用 `!` 作为逻辑否定。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-041: 位运算符 - -Prompt: - -```text -写一段 TSL 脚本,对两个整数演示位与、位或、位非、位异或, -并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用点前缀位运算符,如 `.&`、`.|`、`.!` 和 `.^`。 -- 不使用普通的 `&`、`|` 或 `~` 作为位运算符。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-042: 复合赋值和自增 - -Prompt: - -```text -写一段 TSL 脚本,a 初始为 1,先用复合赋值加 2, -再自增一次,最后输出 a。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `+=` 和 `a++` 或 `++a`。 -- 使用 `a := 1;` 初始化。 -- 不使用 `a = a + 2`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-043: Nil 安全访问 - -Prompt: - -```text -写一段 TSL 示例,安全读取可能为 nil 的对象成员 value, -使用 docs/tsl 里的空安全访问写法。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 nil 安全访问,如 `obj?.value`。 -- 不虚构超出已记录模式的可选链式调用形式。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-044: 标量链式比较 - -Prompt: - -```text -写一段 TSL 脚本,判断 1 < 2 < 3 的连续标量比较并输出结果。 -使用 docs/tsl 的链式比较写法。只输出代码。 -``` - -Pass criteria: - -- 使用标量链式比较,如 `1 :< 2 :< 3`。 -- 不写 Python 风格的 `1 < 2 < 3`。 - -Source docs: - -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-045: 类矩阵链式比较 - -Prompt: - -```text -写一段 TSL 脚本,对 array(1, 2, -1)、array(2, 1, 0)、array(3, 2, 1) -做逐元素链式小于比较,并输出结果数组的三个元素。只输出代码。 -``` - -Pass criteria: - -- 使用矩阵链式比较,如 `::<`。 -- 使用从零开始的索引读取结果数组元素。 -- 不对数组级比较使用标量 `:<`。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` -- `docs/tsl/syntax/06_expressions_and_operators.md` - -### TSL-046: 默认参数 - -Prompt: - -```text -写一个 TSL 函数 AddOne,参数 a 默认值为 1,返回 a + 1。 -再写脚本输出 AddOne() 和 AddOne(5)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function AddOne(a = 1);`。 -- 在 `.tsl` 声明部分之前调用函数。 -- 不使用不支持的默认参数语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-047: 类型化默认参数 - -Prompt: - -```text -写一个 TSL 函数 TypedAdd,参数 a 是 integer,默认值为 1, -返回值是 integer,返回 a + 1。只输出代码。 -``` - -Pass criteria: - -- 使用 `function TypedAdd(a: integer = 1): integer;`。 -- 不用逗号分隔类型化参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-048: 跳过中间参数的命名参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 TestFunc(a, b, c),调用 TestFunc(1, c: 3), -在函数里输出 b 是否为 nil。只输出代码。 -``` - -Pass criteria: - -- 使用命名参数语法 `c: 3`。 -- 使用 `ifNil(b)` 或已记录的 nil 比较检查跳过的 `b`。 -- 保持可执行调用在函数声明之前。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-049: 带命名参数的 call - -Prompt: - -```text -写一段 TSL 脚本,通过 call 调用 TestFunc,并用命名参数传 a、b、c。 -TestFunc 返回 a * 100 + b * 10 + c。只输出代码。 -``` - -Pass criteria: - -- 使用 `call("TestFunc", a: ..., b: ..., c: ...)`。 -- 不用 `=` 写命名参数。 -- 在 `.tsl` 中的调用之后定义 `TestFunc`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-050: varByRef 开关 - -Prompt: - -```text -写一段 TSL 脚本,演示 {$varByRef-} 下未修饰参数不写回, -但 var 参数仍会写回。只输出代码。 -``` - -Pass criteria: - -- 使用 `{$varByRef-}`,如果需要则稍后使用 `{$varByRef+}` 恢复。 -- 包含一个未修饰参数函数和一个 `var` 参数函数。 -- 不依赖其他语言的值/引用模型。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-051: in 和 out 调用前缀 - -Prompt: - -```text -写一段 TSL 脚本,在 {$varByRef-} 下调用 Touch3(in a, out b, c), -演示只有 b 被写回。只输出代码。 -``` - -Pass criteria: - -- 使用调用端前缀 `in` 和 `out`。 -- 使用 `{$varByRef-}`。 -- 不在函数头中将 `in` / `out` 写为类型注解。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-052: exit 边界 - -Prompt: - -```text -写一段 TSL 脚本,函数 Demo(x) 在 x > 0 时 exit, -否则 return 99;输出 Demo(1) 和 Demo(0)。只输出代码。 -``` - -Pass criteria: - -- 在函数内使用 `exit;`。 -- 对另一个分支使用 `return 99;`。 -- 不将 `exit` 视为返回显式自定义值。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-053: 可变参数求和 - -Prompt: - -```text -写一个 TSL 可变参数函数 SumAll(...),遍历 Params 求和并返回。 -再输出 SumAll(1, 2, 3, 4)。只输出代码。 -``` - -Pass criteria: - -- 使用 `function SumAll(...);`。 -- 迭代 `Params`。 -- 不虚构 JavaScript rest 语法。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-054: ParamCount 和 RealParamCount - -Prompt: - -```text -写一个 TSL 函数 CountArgs(a, b, ...),返回 ParamCount * 10 + RealParamCount。 -输出 CountArgs(1, 2, 3, 4)。只输出代码。 -``` - -Pass criteria: - -- 使用 `ParamCount` 和 `RealParamCount`。 -- 在函数头中使用尾随 `...`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-055: 用 call 转发可变参数 - -Prompt: - -```text -写一段 TSL 脚本,DoFunc(fc, ...) 通过 call(fc, ...) 转发参数给 Sum3。 -输出 DoFunc("Sum3", 1, 2, 3)。只输出代码。 -``` - -Pass criteria: - -- 使用 `call(fc, ...)`。 -- 使用 `function DoFunc(fc, ...);`。 -- 不手动解包固定数量的可变参数。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-056: 匿名函数变量 - -Prompt: - -```text -写一段 TSL 脚本,把匿名函数赋给变量 a, -匿名函数返回 x + y,然后用 call(a, 1, 2) 输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用 `a := function(x, y) begin ... end;`。 -- 通过 `call(a, 1, 2)` 或已记录的 `##a(...)` 调用。 -- 不仅将函数变量作为 `a(1, 2)` 调用。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-057: 匿名函数作为参数 - -Prompt: - -```text -写一段 TSL 脚本,定义 Apply(fun),内部 call(fun, 2, 3)。 -调用 Apply 时直接传入一个匿名乘法函数。只输出代码。 -``` - -Pass criteria: - -- 将 `function(x, y) begin ... end` 作为参数传递。 -- 在 `Apply` 内使用 `call(fun, 2, 3)`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-058: findFunction 调用 - -Prompt: - -```text -写一段 TSL 脚本,用 findFunction("Add") 找到 Add 函数, -再用文档支持的函数值调用方式输出 Add(1, 2)。只输出代码。 -``` - -Pass criteria: - -- 使用 `findFunction("Add")`。 -- 使用 `##f(...)` 或 `call(f, ...)` 调用返回的函数。 -- 不直接调用 `f(...)`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-059: thisFunction 调用 - -Prompt: - -```text -写一段 TSL 脚本,用 thisFunction(Add) 得到函数值, -再通过一个 Call 包装函数调用它。只输出代码。 -``` - -Pass criteria: - -- 使用 `thisFunction(Add)`。 -- 使用 `call(...)` 或已记录的包装器风格调用函数值。 -- 如果使用 `thisFunction`,不引用 `Add`。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-060: 全局函数限定 - -Prompt: - -```text -写一段 TSL 示例,局部函数名和全局/系统函数同名时, -用 docs/tsl 里明确的全局函数限定调用写法。只输出代码。 -``` - -Pass criteria: - -- 使用 `::FuncName(...)` 进行全局/系统函数限定。 -- 不虚构其他语言的命名空间分隔符。 - -Source docs: - -- `docs/tsl/syntax/05_functions_and_calls.md` - -### TSL-061: 带范围的 Case 语句 - -Prompt: - -```text -写一段 TSL 脚本,a 为 4,用 case 判断: -1,2 输出 small;3 到 5 输出 mid;其他输出 other。只输出代码。 -``` - -Pass criteria: - -- 使用 `case a of`。 -- 使用逗号标签和 `3 to 5`。 -- 使用 `else` 并以 `end` 结束。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-062: Case 表达式 - -Prompt: - -```text -写一段 TSL 脚本,用 case 表达式给 value 赋值, -a 为 2 时 value 是 "two",否则是 "other",然后输出 value。只输出代码。 -``` - -Pass criteria: - -- 使用 `value := case ... of ... else ... end;`。 -- 不在表达式形式的分支内放置 `begin ... end` 块。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-063: Repeat Until - -Prompt: - -```text -写一段 TSL 脚本,用 repeat ... until 把 counter 从 3 减到 0, -最后输出 counter。只输出代码。 -``` - -Pass criteria: - -- 使用 `repeat ... until counter = 0;`。 -- 不写 `do while` 语法。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-064: While 循环中的 Break - -Prompt: - -```text -写一段 TSL 脚本,用 while true 循环累加 1 到 3, -i 大于 3 时 break,然后输出 sum。只输出代码。 -``` - -Pass criteria: - -- 使用 `while true do`。 -- 在循环内使用 `break;`。 -- 为多语句循环体使用 TSL 块结构。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-065: While 循环中的 Continue - -Prompt: - -```text -写一段 TSL 脚本,while 循环 i 从 1 到 4, -跳过 i = 2,只累加其他值并输出 sum。只输出代码。 -``` - -Pass criteria: - -- 对跳过的迭代使用 `continue;`。 -- 不在 `continue` 路径之后放置会导致无限循环的增量。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-066: Try Finally - -Prompt: - -```text -写一段 TSL 脚本,用 try/finally,try 中输出 "run", -finally 中输出 "cleanup"。只输出代码。 -``` - -Pass criteria: - -- 使用 `try ... finally ... end`。 -- 不使用 `catch` 或 JavaScript 风格的异常语法。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-067: 异常元数据 - -Prompt: - -```text -写一段 TSL 脚本,raise "bad" 后在 except 中输出 errInfo、errLine、errNo。 -只输出代码。 -``` - -Pass criteria: - -- 使用 `exceptObject.errInfo`、`exceptObject.errLine` 和 `exceptObject.errNo`。 -- 使用 `try ... except ... end`。 - -Source docs: - -- `docs/tsl/syntax/07_control_flow.md` - -### TSL-068: 嵌套 Array 解构 - -Prompt: - -```text -写一段 TSL 脚本,从 array((1, 2), (3, 4)) 拆出 r1 和 r2, -并输出 r1[0]、r1[1]、r2[0]、r2[1]。只输出代码。 -``` - -Pass criteria: - -- 使用 `[r1, r2] := array((1, 2), (3, 4));`。 -- 使用从零开始的索引读取嵌套数组元素。 - -Source docs: - -- `docs/tsl/syntax/04_variables_and_constants.md` -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-069: 行集合操作 - -Prompt: - -```text -写一段 TSL 脚本,对 left_rows 和 right_rows 做 union2、intersect、minus、outersect。 -只输出代码。 -``` - -Pass criteria: - -- 使用行集合运算符 `union2`、`intersect`、`minus` 和 `outersect`。 -- 不将 `union2` 视为保留重复行。 - -Source docs: - -- `docs/tsl/syntax/12_matrix_and_collections.md` - -### TSL-070: 单列 filterIn - -Prompt: - -```text -写一段 TSL 示例,用 filterIn 按单列从结果集中筛选命中行。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `filterIn(...)` 形式。 -- 不用 `in`/`sqlin` 集合操作替换结果集筛选。 - -Source docs: - -- `docs/tsl/syntax/13_resultset_and_filters.md` - -### TSL-071: filterNotIn - -Prompt: - -```text -写一段 TSL 示例,用 filterNotIn 从结果集中排除命中行。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `filterNotIn(...)` 形式。 -- 当任务要求保留筛选语义时,不使用 `minus`。 - -Source docs: - -- `docs/tsl/syntax/13_resultset_and_filters.md` - -### TSL-072: TS-SQL 最小查询 - -Prompt: - -```text -写一段 TSL 示例,对 array((1, 2), (3, 4)) 使用 TS-SQL 最小查询骨架。 -只输出代码。 -``` - -Pass criteria: - -- 使用语法文档中已记录的 TS-SQL 查询形式。 -- 不虚构普通 SQL 字符串执行。 - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-073: TS-SQL where 和 order by - -Prompt: - -```text -写一段 TSL 示例,使用 TS-SQL 对数组结果集按条件过滤并排序。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `where` 和 `order by` TS-SQL 语法。 -- 除非 TS-SQL 文档记录,否则不使用 SQL `%` 通配符假设。 - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-074: TS-SQL group by - -Prompt: - -```text -写一段 TSL 示例,使用 TS-SQL 按字段 group by,并计算每组统计值。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `group by` TS-SQL 形式。 -- 仅使用已记录的聚合/引用辅助函数。 - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-075: TS-SQL join - -Prompt: - -```text -写一段 TSL 示例,用 TS-SQL join 两个数组结果集。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `join` 形式。 -- 不虚构数据库连接或外部 SQL 执行。 - -Source docs: - -- `docs/tsl/syntax/14_ts_sql.md` - -### TSL-076: Runtime with 星号 - -Prompt: - -```text -写一段 TSL 示例,使用 docs/tsl 中的 with * 块环境写法。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `with *` 语法。 -- 不虚构 Python `with` 语义。 - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-077: Runtime with 双星号 - -Prompt: - -```text -写一段 TSL 示例,使用 docs/tsl 中的 with ** 块环境写法。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `with **` 语法。 -- 不超出已记录的运行时上下文形式进行泛化。 - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-078: 网格调用超时 - -Prompt: - -```text -写一段 TSL 示例,用 # 网格调用并带 timeout。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `#Func(...)` 和 `timeout N` 形式。 -- 除非有文档记录,否则不将 `timeout` 转换为普通函数参数。 - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-079: 全局缓存 - -Prompt: - -```text -写一段 TSL 示例,设置全局缓存、读取全局缓存,并判断缓存是否存在。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `setGlobalCache`、`getGlobalCache` 和 `ifCache`。 -- 不虚构浏览器/本地存储风格的 API。 - -Source docs: - -- `docs/tsl/syntax/10_runtime_context_and_with.md` - -### TSL-080: 条件编译 - -Prompt: - -```text -写一段 TSL 示例,使用 {$ifdef ...} 和 {$else} 做条件编译分支。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的编译选项语法。 -- 当任务要求条件编译时,不写运行时 `if`。 - -Source docs: - -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-081: 注释和标识符 - -Prompt: - -```text -写一段 TSL 示例,包含 docs/tsl 支持的注释写法和一个普通标识符赋值。 -只输出代码。 -``` - -Pass criteria: - -- 使用词法结构页面中已记录的注释语法。 -- 使用 `:=` 进行赋值。 - -Source docs: - -- `docs/tsl/syntax/16_lexical_structure_and_compile_options.md` - -### TSL-082: goto 标签 - -Prompt: - -```text -写一段 TSL 示例,使用 goto 跳转到标签并输出结果。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `goto` 和标签语法。 -- 如果与文档不同,不虚构 C 风格标签规则。 - -Source docs: - -- `docs/tsl/syntax/15_debug_and_profiler.md` - -### TSL-083: debugReturn - -Prompt: - -```text -写一段 TSL 示例,使用 debugReturn 提前返回调试值。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `debugReturn` 形式。 -- 除非两者都需要,否则不将其与普通 `return` 混淆。 - -Source docs: - -- `docs/tsl/syntax/15_debug_and_profiler.md` - -### TSL-084: 性能分析计时 - -Prompt: - -```text -写一段 TSL 示例,使用 mtic 和 mtoc 做简单计时。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `mtic` / `mtoc` 形式。 -- 不虚构外部计时 API。 - -Source docs: - -- `docs/tsl/syntax/15_debug_and_profiler.md` - -### TSL-085: External 函数声明 - -Prompt: - -```text -写一个 TSL external 函数声明示例,按 docs/tsl 的最小 external 写法。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `external` 声明形式。 -- 不虚构 C、Python 或 TypeScript 的 FFI 语法。 - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-086: External 过程声明 - -Prompt: - -```text -写一个 TSL procedure external 示例。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `procedure external` 形式。 -- 不在 procedure 头上放置返回类型。 - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-087: 原生函数指针包装器 - -Prompt: - -```text -写一段 TSL 示例,按 docs/tsl 包装原生函数指针。只输出代码。 -``` - -Pass criteria: - -- 仅使用已记录的原生函数指针包装器形式。 -- 不虚构原始指针语法。 - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-088: 线程最小模式 - -Prompt: - -```text -写一段 TSL 线程模式最小正例,按 docs/tsl 的线程示例组织。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的线程模式语法。 -- 不虚构 async/await 或 JavaScript 线程语法。 - -Source docs: - -- `docs/tsl/syntax/18_external_calls_and_threads.md` - -### TSL-089: Class Property - -Prompt: - -```text -写一个 TSL 类 Box,字段 value 通过 property Value read/write 访问。 -脚本里设置并输出这个属性。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `property Name read ... write ...` 形式。 -- 使用 `type Box = class`。 -- 使用 `new Box()` 创建。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-090: 类型化 Class Property - -Prompt: - -```text -写一个 TSL 类 Person,包含 string 类型字段 name_, -并定义带类型注解的 property Name。只输出代码。 -``` - -Pass criteria: - -- 使用字段类型注解,如 `name_: string;`。 -- 使用已记录的类型化 property 形式。 -- 不虚构 C# property 块。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-091: 方法重载 - -Prompt: - -```text -写一个 TSL 类 Calc,包含两个同名 Add 方法,参数个数不同。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `overload` 方法形式。 -- 将方法保持在 `type Calc = class` 内。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-092: 继承 - -Prompt: - -```text -写一个 TSL 类 Animal 和继承它的 Dog,Dog 增加一个方法 Speak。 -只输出代码。 -``` - -Pass criteria: - -- 使用 `type Dog = class(Animal)`。 -- 不使用 `extends`。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-093: Virtual Override - -Prompt: - -```text -写一个 TSL 父类 Base,虚方法 Name;子类 Child 覆盖 Name。 -脚本里创建 Child 并输出 Name。只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `virtual` 和 `override`。 -- 使用 `type Child = class(Base)`。 -- 使用 `new Child()` 创建。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-094: Inherited 方法调用 - -Prompt: - -```text -写一个 TSL 子类方法,在方法里调用父类同名方法后再追加自己的逻辑。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `Inherited` 调用形式。 -- 不虚构 `super.method()` 语法。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-095: 类外 Class 方法实现 - -Prompt: - -```text -写一个 TSL 类 Greeter,类内只声明 Say 方法, -在类外用 ClassName.Method 形式实现它。只输出代码。 -``` - -Pass criteria: - -- 使用 class 声明加 `function Greeter.Say(...)` 实现。 -- 不在实现部分之后追加可执行脚本语句。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-096: 通过字符串类名 createObject - -Prompt: - -```text -写一段 TSL 示例,用字符串类名通过 createObject 创建本地类实例。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `createObject("ClassName")` 形式。 -- 仅在解释它不是请求的字符串名称路径时使用 `new ClassName()`。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-097: 析构函数 - -Prompt: - -```text -写一个 TSL 类,定义无参 destroy 函数,在对象引用设为 nil 时触发清理。 -只输出代码。 -``` - -Pass criteria: - -- 使用 `function destroy();`。 -- 在可执行脚本代码中将对象引用设为 `nil`。 -- 不虚构 `destructor` 关键字。 - -Source docs: - -- `docs/tsl/syntax/08_objects_and_classes.md` - -### TSL-098: FMArray 基础 - -Prompt: - -```text -写一段 TSL 示例,创建 FMArray,判断它是 FMArray,并输出尺寸信息。 -只输出代码。 -``` - -Pass criteria: - -- 使用 FMArray 页面中已记录的 FMArray 构造。 -- 使用已记录的 FMArray 类型/大小辅助函数。 -- 不将普通 `array(...)` 视为自动成为 FMArray。 - -Source docs: - -- `docs/tsl/syntax/23_fmarray.md` - -### TSL-099: 矩阵深入 - -Prompt: - -```text -写一段 TSL 示例,初始化矩阵并使用 mrows、mcols、msize 输出维度。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的矩阵初始化。 -- 使用 `mrows`、`mcols` 和 `msize`。 - -Source docs: - -- `docs/tsl/syntax/22_matrix_deep_dive.md` - -### TSL-100: 对象运算符重载 - -Prompt: - -```text -写一个 TSL 类,重载二元 + 运算符,让两个对象相加得到一个新对象。 -只输出代码。 -``` - -Pass criteria: - -- 使用已记录的 `operator +` 重载形式。 -- 将重载实现保持在有效的 `type Name = class` 结构内。 -- 不虚构 Python `__add__` 或 C++ 语法。 - -Source docs: - -- `docs/tsl/syntax/24_object_overloads_and_iteration.md` - -## 结果表模板 - -为每个评估的 agent 复制此表: - -| Case | Score | Failure pattern | Notes | -| ------- | ----: | --------------- | ----- | -| TSL-001 | | | | -| TSL-002 | | | | -| TSL-003 | | | | -| TSL-004 | | | | -| TSL-005 | | | | -| TSL-006 | | | | -| TSL-007 | | | | -| TSL-008 | | | | -| TSL-009 | | | | -| TSL-010 | | | | -| TSL-011 | | | | -| TSL-012 | | | | -| TSL-013 | | | | -| TSL-014 | | | | -| TSL-015 | | | | -| TSL-016 | | | | -| TSL-017 | | | | -| TSL-018 | | | | -| TSL-019 | | | | -| TSL-020 | | | | -| TSL-021 | | | | -| TSL-022 | | | | -| TSL-023 | | | | -| TSL-024 | | | | -| TSL-025 | | | | -| TSL-026 | | | | -| TSL-027 | | | | -| TSL-028 | | | | -| TSL-029 | | | | -| TSL-030 | | | | -| TSL-031 | | | | -| TSL-032 | | | | -| TSL-033 | | | | -| TSL-034 | | | | -| TSL-035 | | | | -| TSL-036 | | | | -| TSL-037 | | | | -| TSL-038 | | | | -| TSL-039 | | | | -| TSL-040 | | | | -| TSL-041 | | | | -| TSL-042 | | | | -| TSL-043 | | | | -| TSL-044 | | | | -| TSL-045 | | | | -| TSL-046 | | | | -| TSL-047 | | | | -| TSL-048 | | | | -| TSL-049 | | | | -| TSL-050 | | | | -| TSL-051 | | | | -| TSL-052 | | | | -| TSL-053 | | | | -| TSL-054 | | | | -| TSL-055 | | | | -| TSL-056 | | | | -| TSL-057 | | | | -| TSL-058 | | | | -| TSL-059 | | | | -| TSL-060 | | | | -| TSL-061 | | | | -| TSL-062 | | | | -| TSL-063 | | | | -| TSL-064 | | | | -| TSL-065 | | | | -| TSL-066 | | | | -| TSL-067 | | | | -| TSL-068 | | | | -| TSL-069 | | | | -| TSL-070 | | | | -| TSL-071 | | | | -| TSL-072 | | | | -| TSL-073 | | | | -| TSL-074 | | | | -| TSL-075 | | | | -| TSL-076 | | | | -| TSL-077 | | | | -| TSL-078 | | | | -| TSL-079 | | | | -| TSL-080 | | | | -| TSL-081 | | | | -| TSL-082 | | | | -| TSL-083 | | | | -| TSL-084 | | | | -| TSL-085 | | | | -| TSL-086 | | | | -| TSL-087 | | | | -| TSL-088 | | | | -| TSL-089 | | | | -| TSL-090 | | | | -| TSL-091 | | | | -| TSL-092 | | | | -| TSL-093 | | | | -| TSL-094 | | | | -| TSL-095 | | | | -| TSL-096 | | | | -| TSL-097 | | | | -| TSL-098 | | | | -| TSL-099 | | | | -| TSL-100 | | | |