-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathparseSourceCodeDefinitions.elixir.spec.ts
More file actions
89 lines (73 loc) · 3.3 KB
/
Copy pathparseSourceCodeDefinitions.elixir.spec.ts
File metadata and controls
89 lines (73 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { elixirQuery } from "../queries"
import { testParseSourceCodeDefinitions, debugLog } from "./helpers"
import sampleElixirContent from "./fixtures/sample-elixir"
// Elixir test options
const elixirOptions = {
language: "elixir",
wasmFile: "tree-sitter-elixir.wasm",
queryString: elixirQuery,
extKey: "ex",
}
// Mock file system operations
vi.mock("fs/promises")
// Mock loadRequiredLanguageParsers
vi.mock("../languageParser", () => ({
loadRequiredLanguageParsers: vi.fn(),
}))
// Mock fileExistsAtPath to return true for our test paths
vi.mock("../../../utils/fs", () => ({
fileExistsAtPath: vi.fn().mockImplementation(() => Promise.resolve(true)),
}))
describe("parseSourceCodeDefinitionsForFile with Elixir", () => {
let parseResult: string = ""
beforeAll(async () => {
// Cache parse result for all tests
parseResult = (await testParseSourceCodeDefinitions("/test/file.ex", sampleElixirContent, elixirOptions))!
debugLog("Elixir Parse Result:", parseResult)
})
beforeEach(() => {
vi.clearAllMocks()
})
it("should parse module definitions", () => {
expect(parseResult).toMatch(/\d+--\d+ \| defmodule TestModuleDefinition do/)
expect(parseResult).toMatch(/\d+--\d+ \| defmodule TestBehaviourDefinition do/)
expect(parseResult).toMatch(/\d+--\d+ \| defmodule TestModuleDefinitionTest do/)
debugLog("Module definitions found:", parseResult.match(/defmodule[\s\S]*?end/g))
})
it("should parse function definitions", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}def test_function_definition/)
expect(parseResult).toMatch(/\d+--\d+ \| {3}def test_pipeline_definition/)
expect(parseResult).toMatch(/\d+--\d+ \| {3}def test_comprehension_definition/)
expect(parseResult).toMatch(/\d+--\d+ \| {3}def test_sigil_definition/)
debugLog("Function definitions found:", parseResult.match(/def[\s\S]*?end/g))
})
it("should parse macro definitions", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}defmacro test_macro_definition/)
debugLog("Macro definitions found:", parseResult.match(/defmacro[\s\S]*?end/g))
})
it("should parse protocol implementations", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}defimpl String\.Chars/)
debugLog("Protocol implementations found:", parseResult.match(/defimpl[\s\S]*?end/g))
})
it("should parse behaviour callbacks", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}@callback test_behaviour_callback/)
debugLog("Behaviour callbacks found:", parseResult.match(/@callback[\s\S]*?\)/g))
})
it("should parse struct definitions", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}defstruct \[/)
debugLog("Struct definitions found:", parseResult.match(/defstruct[\s\S]*?\]/g))
})
it("should parse guard definitions", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}defguard test_guard_definition/)
debugLog("Guard definitions found:", parseResult.match(/defguard[\s\S]*?end/g))
})
it("should parse module attributes", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}@test_attribute_definition/)
expect(parseResult).toMatch(/\d+--\d+ \| @moduledoc/)
debugLog("Module attributes found:", parseResult.match(/@[\s\S]*?\]/g))
})
it("should parse test definitions", () => {
expect(parseResult).toMatch(/\d+--\d+ \| {3}test "test_definition"/)
debugLog("Test definitions found:", parseResult.match(/test[\s\S]*?end/g))
})
})