Skip to content

Commit 1aa8809

Browse files
author
Eric Wheeler
committed
feat: standardize tree-sitter test implementations
Standardized tree-sitter test implementations across all supported languages: - Removed debugLog calls from test files - Implemented consistent line number pattern matching - Ensured proper test structure and execution order - Added comprehensive test coverage for supported structures - Maintained 1:1 mapping between queries, tests and samples - Documented unsupported features in TODO sections Signed-off-by: Eric Wheeler <[email protected]>
1 parent 155c9be commit 1aa8809

File tree

46 files changed

+1257
-1307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1257
-1307
lines changed

src/services/tree-sitter/__tests__/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from "fs/promises"
44
import * as path from "path"
55
import Parser from "web-tree-sitter"
66
import tsxQuery from "../queries/tsx"
7+
import goQuery from "../queries/go"
78
// Mock setup
89
jest.mock("fs/promises")
910
export const mockedFs = jest.mocked(fs)

src/services/tree-sitter/__tests__/inspectCSS.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ import { inspectTreeStructure, testParseSourceCodeDefinitions } from "./helpers"
33
import { cssQuery } from "../queries"
44
import sampleCSSContent from "./fixtures/sample-css"
55

6-
describe("inspectCSS", () => {
6+
describe("CSS Tree-sitter Parser", () => {
77
const testOptions = {
88
language: "css",
99
wasmFile: "tree-sitter-css.wasm",
1010
queryString: cssQuery,
1111
extKey: "css",
12-
debug: true,
1312
}
1413

15-
it("should inspect CSS tree structure", async () => {
14+
it("should properly parse CSS structures", async () => {
15+
// First run inspectTreeStructure to get query structure output
1616
await inspectTreeStructure(sampleCSSContent, "css")
17-
})
1817

19-
it("should parse CSS definitions", async () => {
18+
// Then run testParseSourceCodeDefinitions to get line numbers
2019
const result = await testParseSourceCodeDefinitions("test.css", sampleCSSContent, testOptions)
20+
expect(result).toBeDefined()
2121
if (!result) {
2222
throw new Error("No result returned from parser")
2323
}
24+
expect(result).toMatch(/\d+--\d+ \|/)
25+
expect(result.split("\n").length).toBeGreaterThan(1)
2426
})
2527
})

src/services/tree-sitter/__tests__/inspectCSharp.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ describe("inspectCSharp", () => {
1212
}
1313

1414
it("should inspect C# tree structure", async () => {
15-
await inspectTreeStructure(sampleCSharpContent, "c_sharp")
15+
// Should execute without throwing
16+
await expect(inspectTreeStructure(sampleCSharpContent, "c_sharp")).resolves.not.toThrow()
1617
})
1718

1819
it("should parse C# definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.cs", sampleCSharpContent, testOptions)
20+
const result = await testParseSourceCodeDefinitions("test.cs", sampleCSharpContent, testOptions)
21+
expect(result).toBeDefined()
22+
expect(result).toMatch(/\d+--\d+ \|/)
2023
})
2124
})
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { describe, it } from "@jest/globals"
1+
import { describe, it, expect } from "@jest/globals"
22
import { inspectTreeStructure, testParseSourceCodeDefinitions } from "./helpers"
33
import { cppQuery } from "../queries"
44
import sampleCppContent from "./fixtures/sample-cpp"
55

6-
describe("inspectCpp", () => {
6+
describe("C++ Tree-sitter Parser", () => {
77
const testOptions = {
88
language: "cpp",
99
wasmFile: "tree-sitter-cpp.wasm",
1010
queryString: cppQuery,
1111
extKey: "cpp",
1212
}
1313

14-
it("should inspect C++ tree structure", async () => {
14+
it("should properly parse structures", async () => {
15+
// First run inspectTreeStructure to get query structure output
1516
await inspectTreeStructure(sampleCppContent, "cpp")
16-
})
1717

18-
it("should parse C++ definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.cpp", sampleCppContent, testOptions)
18+
// Then run testParseSourceCodeDefinitions to get line numbers
19+
const result = await testParseSourceCodeDefinitions("test.cpp", sampleCppContent, testOptions)
20+
expect(result).toBeDefined()
21+
expect(result).toMatch(/\d+--\d+ \|/)
2022
})
2123
})

src/services/tree-sitter/__tests__/inspectElisp.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ describe("inspectElisp", () => {
1111
extKey: "el",
1212
}
1313

14-
it("should inspect Elisp tree structure", async () => {
15-
await inspectTreeStructure(sampleElispContent, "elisp")
14+
it("should validate Elisp tree structure inspection", async () => {
15+
const result = await inspectTreeStructure(sampleElispContent, "elisp")
16+
expect(result).toBeDefined()
17+
expect(result.length).toBeGreaterThan(0)
1618
})
1719

18-
it("should parse Elisp definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.el", sampleElispContent, testOptions)
20+
it("should validate Elisp definitions parsing", async () => {
21+
const result = await testParseSourceCodeDefinitions("test.el", sampleElispContent, testOptions)
22+
expect(result).toBeDefined()
23+
expect(result).toMatch(/\d+--\d+ \|/) // Verify line number format
24+
25+
// Verify some sample content is parsed
26+
expect(result).toMatch(/defun test-function/)
27+
expect(result).toMatch(/defmacro test-macro/)
2028
})
2129
})

src/services/tree-sitter/__tests__/inspectElixir.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ describe("inspectElixir", () => {
1212
}
1313

1414
it("should inspect Elixir tree structure", async () => {
15-
await inspectTreeStructure(sampleElixirContent, "elixir")
15+
const result = await inspectTreeStructure(sampleElixirContent, "elixir")
16+
expect(result).toBeDefined()
17+
expect(result.length).toBeGreaterThan(0)
1618
})
1719

1820
it("should parse Elixir definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.ex", sampleElixirContent, testOptions)
21+
const result = await testParseSourceCodeDefinitions("test.ex", sampleElixirContent, testOptions)
22+
expect(result).toBeDefined()
23+
expect(result).toContain("--")
24+
expect(result).toMatch(/\d+--\d+ \|/)
2025
})
2126
})

src/services/tree-sitter/__tests__/inspectEmbeddedTemplate.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ describe("inspectEmbeddedTemplate", () => {
88
language: "embedded_template",
99
wasmFile: "tree-sitter-embedded_template.wasm",
1010
queryString: embeddedTemplateQuery,
11-
extKey: "embedded_template",
11+
extKey: "erb", // Match the file extension we're using
1212
}
1313

1414
it("should inspect embedded template tree structure", async () => {
15-
await inspectTreeStructure(sampleEmbeddedTemplateContent, "embedded_template")
15+
const result = await inspectTreeStructure(sampleEmbeddedTemplateContent, "embedded_template")
16+
expect(result).toBeTruthy()
1617
})
1718

1819
it("should parse embedded template definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.erb", sampleEmbeddedTemplateContent, testOptions)
20+
const result = await testParseSourceCodeDefinitions("test.erb", sampleEmbeddedTemplateContent, testOptions)
21+
expect(result).toBeTruthy()
22+
expect(result).toMatch(/\d+--\d+ \|/) // Verify line number format
2023
})
2124
})
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
import { describe, test } from "@jest/globals"
2-
import { inspectTreeStructure } from "./helpers"
1+
import { describe, it, expect } from "@jest/globals"
2+
import { inspectTreeStructure, testParseSourceCodeDefinitions } from "./helpers"
33
import sampleGoContent from "./fixtures/sample-go"
4+
import goQuery from "../queries/go"
45

5-
describe("Go Structure Tests", () => {
6-
test("should output Go structures", async () => {
6+
describe("Go Tree-sitter Parser", () => {
7+
// Test 1: Get query structure output
8+
it("should inspect tree structure", async () => {
79
await inspectTreeStructure(sampleGoContent, "go")
810
})
11+
12+
// Test 2: Get line numbers
13+
it("should parse source code definitions", async () => {
14+
const testOptions = {
15+
language: "go",
16+
wasmFile: "tree-sitter-go.wasm",
17+
queryString: goQuery,
18+
extKey: "go",
19+
}
20+
21+
const result = await testParseSourceCodeDefinitions("file.go", sampleGoContent, testOptions)
22+
expect(result).toBeDefined()
23+
})
924
})

src/services/tree-sitter/__tests__/inspectHtml.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ describe("inspectHtml", () => {
1212
}
1313

1414
it("should inspect HTML tree structure", async () => {
15-
await inspectTreeStructure(sampleHtmlContent, "html")
15+
// Should execute without error
16+
await expect(inspectTreeStructure(sampleHtmlContent, "html")).resolves.not.toThrow()
1617
})
1718

1819
it("should parse HTML definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.html", sampleHtmlContent, testOptions)
20+
const result = await testParseSourceCodeDefinitions("test.html", sampleHtmlContent, testOptions)
21+
expect(result).toBeDefined()
22+
expect(result).toMatch(/\d+--\d+ \| </)
2023
})
2124
})

src/services/tree-sitter/__tests__/inspectJava.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ describe("inspectJava", () => {
1212
}
1313

1414
it("should inspect Java tree structure", async () => {
15-
await inspectTreeStructure(sampleJavaContent, "java")
15+
const result = await inspectTreeStructure(sampleJavaContent, "java")
16+
expect(result).toBeTruthy()
1617
})
1718

1819
it("should parse Java definitions", async () => {
19-
await testParseSourceCodeDefinitions("test.java", sampleJavaContent, testOptions)
20+
const result = await testParseSourceCodeDefinitions("test.java", sampleJavaContent, testOptions)
21+
expect(result).toBeTruthy()
22+
expect(result).toMatch(/\d+--\d+ \| /) // Verify line number format
2023
})
2124
})

0 commit comments

Comments
 (0)