🐛 fix(tsl-syntax-reference): close verified syntax gaps

This commit is contained in:
csh
2026-08-13 14:49:43 +08:00
parent ede9287d5f
commit 8315f1060a
17 changed files with 619 additions and 96 deletions
+49 -2
View File
@@ -298,8 +298,8 @@ class TslSyntaxReferenceTests(unittest.TestCase):
for query in ("数组下标", "请帮我解释数组的下标"):
with self.subTest(query=query):
result = lookup.query_sections(query, "explain", limit=1)
self.assertEqual("11_matrix_and_collections.md", result.matches[0].section.page.name)
self.assertEqual("基础数组与键表", result.matches[0].section.heading_path[-1])
self.assertEqual("03_values_and_literals.md", result.matches[0].section.page.name)
self.assertEqual("核心规则", result.matches[0].section.heading_path[-1])
def test_documented_write_and_diagnose_queries_rank_expected_sections(self):
write_result = lookup.query_sections("命名参数", "write", limit=1)
@@ -349,6 +349,53 @@ class TslSyntaxReferenceTests(unittest.TestCase):
self.assertEqual(2, result.returncode)
self.assertIn("only weak candidates", result.stderr)
def test_strong_candidates_are_ranked_before_weak_diagnose_boosts(self):
result = lookup.query_sections("变量赋值", "diagnose", limit=1)
self.assertTrue(result.matches)
self.assertFalse(result.matches[0].weak)
self.assertNotEqual("syntax-04-008", result.matches[0].section.id)
def test_page_intent_aliases_score_once_per_page(self):
result = lookup.query_sections("高性能矩阵 fmarray", "explain", limit=3)
self.assertTrue(result.matches)
self.assertEqual("syntax-22-004", result.matches[0].section.id)
for match in result.matches:
self.assertNotIn("intent=160", match.reasons)
self.assertIn("intent=80", result.matches[0].reasons)
def test_program_is_a_searchable_language_keyword(self):
result = lookup.query_sections("PROGRAM", "explain", limit=1)
self.assertTrue(result.matches)
self.assertEqual("syntax-02-009", result.matches[0].section.id)
def test_maintenance_html_comments_do_not_leak_into_lookup_output(self):
result = run_lookup("--query", "PROGRAM", "--mode", "explain")
self.assertEqual(0, result.returncode)
self.assertNotIn("prettier-ignore", result.stdout)
def test_new_language_gaps_have_stable_retrieval_entries(self):
cases = {
"全局变量": "syntax-04-009",
"运行时常量": "syntax-04-010",
"静态计算": "syntax-06-016",
"只计算一次": "syntax-06-016",
"指定系统函数": "syntax-05-013",
"运算符优先级": "syntax-06-015",
"内存上限": "syntax-14-011",
"嵌套注释": "syntax-15-005",
"JOIN 第二张表当前行": "syntax-13-010",
"按行广播": "syntax-11-011",
}
for query, expected_id in cases.items():
with self.subTest(query=query):
result = lookup.query_sections(query, "explain", limit=1)
self.assertTrue(result.matches, query)
self.assertEqual(expected_id, result.matches[0].section.id)
def test_batch_section_retrieval_is_atomic(self):
ids = [section.id for section in lookup.load_sections()[:2]]
success = run_lookup("--section", *ids)