Files
IOT_SIM/server/test/samples.test.ts
T
xuyueandClaude Opus 5.5 90b739a2c7 任务说明:实验页"任务"面板、布置作业时可改写;先写项目 3 任务 2、项目 6 任务 2 两份
- 每个实验一份 task.md(任务目标、控件名表格、实现步骤、和书上不一样的地方、在平台上怎么试)
- 工具栏"评价项"改成"任务":上面是任务说明,下面是评价项和自己检查;不遮挡页面,第一次打开实验时自动打开
- 自己写的 Markdown 子集渲染,先转义全部 HTML(老师可以改写说明)
- 作业保存任务说明(新列 task),以前布置的作业用实验现在的说明
- 测试:任务说明表格里的控件名都在示例的 Designer.cs 里
- 修改作业时实验下拉框显示标题而不是编号

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 10:04:05 +08:00

39 lines
1.6 KiB
TypeScript

// 示例的任务说明(task.md):表格里写的控件名都要在示例的 Designer.cs 里有,学生照着改名不会被带错。
import { expect, test } from 'bun:test'
import { listSamples, loadSample, loadTask } from '../src/samples'
/** 控件表格(表头有"名称")里那一列用 `反引号` 写的名字 */
function tableNames(task: string): string[] {
const names: string[] = []
let column = -1
for (const line of task.split('\n')) {
if (!line.trim().startsWith('|')) {
column = -1
continue
}
const cells = line.trim().replace(/^\||\|$/g, '').split('|')
const header = cells.findIndex((c) => c.includes('名称'))
if (header >= 0) column = header
else if (column >= 0) names.push(...[...(cells[column] ?? '').matchAll(/`([^`]+)`/g)].map((m) => m[1]))
}
return names
}
test('任务说明里的控件名都在示例的界面里', async () => {
let checked = 0
for (const { id } of await listSamples()) {
const task = await loadTask(id)
if (!task) continue
const designer = (await loadSample(id))!.filter((f) => f.path.endsWith('.Designer.cs'))
const names = tableNames(task)
expect(names.length, `${id} 的任务说明没有控件表格`).toBeGreaterThan(0)
for (const name of names) {
// 窗体本身写的是类名,控件是 this.名字
const found = designer.some((f) => f.content.includes(`this.${name} `) || f.content.includes(`partial class ${name}`))
expect(found, `${id}:任务说明里的 ${name} 在 Designer.cs 里找不到`).toBe(true)
}
checked++
}
expect(checked).toBeGreaterThan(0)
})