test(csharp): remove try/catch that masked query compilation failures

The C# integration test wrapped parseAndQuery in a try/catch that
accepted TSQueryError as a passing condition. This meant the broken
simple_base_type query compiled, failed silently, and the test still
passed — hiding the fact that zero C# symbols were being extracted.

Removed the try/catch so query compilation errors are caught by CI.
Also added specific assertions for class, method, and namespace
extraction from the C# fixture.
This commit is contained in:
jiangnan 2026-03-06 05:19:14 +08:00
parent 8ca25fe753
commit acda87a247

View file

@ -149,17 +149,20 @@ describe('Tree-sitter multi-language parsing', () => {
});
describe('C#', () => {
it('parses class, method, and property declarations', async () => {
it('parses class, method, and namespace declarations', async () => {
await loadLanguage(SupportedLanguages.CSharp);
const content = readFixture('simple.cs');
try {
const { matches } = parseAndQuery(parser, content, LANGUAGE_QUERIES[SupportedLanguages.CSharp]);
const defs = extractDefinitions(matches);
expect(defs.length).toBeGreaterThan(0);
} catch (e: any) {
// Some tree-sitter-c-sharp versions don't support all query node types
expect(e.message).toContain('TSQueryError');
}
const { matches } = parseAndQuery(parser, content, LANGUAGE_QUERIES[SupportedLanguages.CSharp]);
const defs = extractDefinitions(matches);
expect(defs.length).toBeGreaterThan(0);
const defTypes = defs.map(d => d.type);
expect(defTypes).toContain('definition.class');
expect(defTypes).toContain('definition.method');
expect(defTypes).toContain('definition.namespace');
const names = defs.map(d => d.name);
expect(names).toContain('Calculator');
expect(names).toContain('Add');
});
});
@ -234,14 +237,9 @@ describe('Tree-sitter multi-language parsing', () => {
for (const [lang, fixture, filePath] of langFixtures) {
await loadLanguage(lang, filePath || fixture);
const content = readFixture(fixture);
try {
const { matches } = parseAndQuery(parser, content, LANGUAGE_QUERIES[lang]);
const defs = extractDefinitions(matches);
expect(defs.length, `${lang} (${fixture}) should have definitions`).toBeGreaterThan(0);
} catch (e: any) {
// Some grammars may have query compatibility issues
if (!e.message?.includes('TSQueryError')) throw e;
}
const { matches } = parseAndQuery(parser, content, LANGUAGE_QUERIES[lang]);
const defs = extractDefinitions(matches);
expect(defs.length, `${lang} (${fixture}) should have definitions`).toBeGreaterThan(0);
}
});
});