@boyingliu01/xp-gate 0.38.76 → 0.38.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/mirror-sync.test.js +387 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +202 -15
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/scripts/generate-mirrors.cjs +10 -0
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/mock-policy/__tests__/config.test.ts +0 -292
- package/mock-policy/__tests__/gate-m3.test.ts +0 -379
- package/mock-policy/__tests__/integration.test.ts +0 -600
- package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
- package/mock-policy/__tests__/schema.test.ts +0 -239
- package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
- package/mutation/__tests__/detect-ai-test.test.ts +0 -152
- package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
- package/mutation/__tests__/gate-m.test.ts +0 -246
- package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
- package/mutation/__tests__/gremlins-runner.test.ts +0 -167
- package/mutation/__tests__/init-baseline.test.ts +0 -347
- package/mutation/__tests__/mutation-mirror.test.ts +0 -49
- package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
- package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
- package/mutation/__tests__/pitest-runner.test.ts +0 -574
- package/mutation/__tests__/runners-index.test.ts +0 -162
- package/mutation/__tests__/stryker-runner.test.ts +0 -455
- package/mutation/__tests__/test-filter-parity.test.ts +0 -40
- package/mutation/__tests__/update-baseline.test.ts +0 -395
- package/principles/__tests__/adapter-metrics.test.ts +0 -292
- package/principles/__tests__/analyze-read-failure.test.ts +0 -70
- package/principles/__tests__/analyzer.test.ts +0 -367
- package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
- package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
- package/principles/__tests__/baseline-prune.test.ts +0 -399
- package/principles/__tests__/baseline-storage.test.ts +0 -188
- package/principles/__tests__/baseline.test.ts +0 -330
- package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
- package/principles/__tests__/boy-scout-integration.test.ts +0 -355
- package/principles/__tests__/boy-scout.test.ts +0 -893
- package/principles/__tests__/cli-files-separators.test.ts +0 -69
- package/principles/__tests__/config-arch-group.test.ts +0 -106
- package/principles/__tests__/config-enforcement.test.ts +0 -470
- package/principles/__tests__/config-git-timeout.test.ts +0 -66
- package/principles/__tests__/config-merge-warnings.test.ts +0 -148
- package/principles/__tests__/config.test.ts +0 -78
- package/principles/__tests__/direct-execution.test.ts +0 -187
- package/principles/__tests__/index.test.ts +0 -94
- package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
- package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
- package/principles/__tests__/lint-baseline.test.ts +0 -314
- package/principles/__tests__/many-exports-reexport.test.ts +0 -40
- package/principles/__tests__/reporter.test.ts +0 -660
- package/principles/__tests__/types.test.ts +0 -103
- package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
- package/principles/adapters/__tests__/base.test.ts +0 -95
- package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
- package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
- package/principles/adapters/__tests__/cpp.test.ts +0 -290
- package/principles/adapters/__tests__/dart.test.ts +0 -84
- package/principles/adapters/__tests__/go.test.ts +0 -68
- package/principles/adapters/__tests__/java.test.ts +0 -385
- package/principles/adapters/__tests__/kotlin.test.ts +0 -76
- package/principles/adapters/__tests__/objectivec.test.ts +0 -453
- package/principles/adapters/__tests__/python.test.ts +0 -84
- package/principles/adapters/__tests__/swift.test.ts +0 -68
- package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
- package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
- package/principles/adapters/__tests__/typescript.test.ts +0 -116
- package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
- package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
- package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
- package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
- package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
- package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
- package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
- package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
- package/principles/rules/__tests__/index.test.ts +0 -49
- package/principles/rules/__tests__/solid/dip.test.ts +0 -119
- package/principles/rules/__tests__/solid/isp.test.ts +0 -58
- package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
- package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
- package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
- package/principles/rules/__tests__/solid/srp.test.ts +0 -87
- package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
- package/principles/rules/arch/__tests__/naming.test.ts +0 -133
- package/principles/rules/arch/__tests__/shared.test.ts +0 -113
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, type Mock } from 'vitest';;
|
|
2
|
-
import { CppAdapter } from '../cpp';
|
|
3
|
-
|
|
4
|
-
type MockFunction = Record<string, unknown>;
|
|
5
|
-
|
|
6
|
-
vi.mock('fs', () => ({
|
|
7
|
-
readFileSync: vi.fn(),
|
|
8
|
-
existsSync: vi.fn(() => true),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
import { readFileSync } from 'fs';
|
|
12
|
-
|
|
13
|
-
describe('CppAdapter', () => {
|
|
14
|
-
|
|
15
|
-
it('should implement the Adapter interface', () => {
|
|
16
|
-
(readFileSync as Mock).mockReturnValue('int main() { return 0; }');
|
|
17
|
-
const adapter = new CppAdapter('test.cpp');
|
|
18
|
-
|
|
19
|
-
expect(adapter).toHaveProperty('detectLanguage');
|
|
20
|
-
expect(adapter).toHaveProperty('parseAST');
|
|
21
|
-
expect(adapter).toHaveProperty('extractFunctions');
|
|
22
|
-
expect(adapter).toHaveProperty('extractClasses');
|
|
23
|
-
expect(adapter).toHaveProperty('countLines');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should detect language as cpp for .cpp files', () => {
|
|
27
|
-
(readFileSync as Mock).mockReturnValue('int main() { return 0; }');
|
|
28
|
-
const adapter = new CppAdapter('test.cpp');
|
|
29
|
-
const detected = adapter.detectLanguage();
|
|
30
|
-
expect(detected).toBe('cpp');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should detect language as cpp for .cxx files', () => {
|
|
34
|
-
(readFileSync as Mock).mockReturnValue('int main() { return 0; }');
|
|
35
|
-
const adapter = new CppAdapter('test.cxx');
|
|
36
|
-
const detected = adapter.detectLanguage();
|
|
37
|
-
expect(detected).toBe('cpp');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should detect language as cpp for .cc files', () => {
|
|
41
|
-
(readFileSync as Mock).mockReturnValue('int main() { return 0; }');
|
|
42
|
-
const adapter = new CppAdapter('test.cc');
|
|
43
|
-
const detected = adapter.detectLanguage();
|
|
44
|
-
expect(detected).toBe('cpp');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should detect language as cpp for .c files', () => {
|
|
48
|
-
(readFileSync as Mock).mockReturnValue('int main() { return 0; }');
|
|
49
|
-
const adapter = new CppAdapter('test.c');
|
|
50
|
-
const detected = adapter.detectLanguage();
|
|
51
|
-
expect(detected).toBe('cpp');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should detect language as cpp for .hpp files', () => {
|
|
55
|
-
(readFileSync as Mock).mockReturnValue('#pragma once');
|
|
56
|
-
const adapter = new CppAdapter('test.hpp');
|
|
57
|
-
const detected = adapter.detectLanguage();
|
|
58
|
-
expect(detected).toBe('cpp');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should detect language as cpp for .h files', () => {
|
|
62
|
-
(readFileSync as Mock).mockReturnValue('#pragma once');
|
|
63
|
-
const adapter = new CppAdapter('test.h');
|
|
64
|
-
const detected = adapter.detectLanguage();
|
|
65
|
-
expect(detected).toBe('cpp');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should parse C++ file AST correctly', () => {
|
|
69
|
-
(readFileSync as Mock).mockReturnValue('int main() { return 0; }');
|
|
70
|
-
const adapter = new CppAdapter('test.cpp');
|
|
71
|
-
const ast = adapter.parseAST();
|
|
72
|
-
expect(ast).toHaveProperty('content');
|
|
73
|
-
expect(ast).toHaveProperty('language');
|
|
74
|
-
expect(ast).toHaveProperty('filePath');
|
|
75
|
-
expect((ast as { language: unknown }).language).toBe('cpp');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should extract functions from C++ code', () => {
|
|
79
|
-
(readFileSync as Mock).mockReturnValue(`
|
|
80
|
-
int add(int a, int b) {
|
|
81
|
-
return a + b;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
int main() {
|
|
85
|
-
return add(1, 2);
|
|
86
|
-
}
|
|
87
|
-
`);
|
|
88
|
-
const adapter = new CppAdapter('test.cpp');
|
|
89
|
-
const functions = adapter.extractFunctions();
|
|
90
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
91
|
-
expect(functions.some(fn => (fn as MockFunction).name === 'main')).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should handle C++ strings with special characters', () => {
|
|
95
|
-
(readFileSync as Mock).mockReturnValue(`
|
|
96
|
-
int main() {
|
|
97
|
-
const char* str = "Hello \\"World\\"";
|
|
98
|
-
char c = '\\'';
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
`);
|
|
102
|
-
|
|
103
|
-
const adapter = new CppAdapter('test.cpp');
|
|
104
|
-
const functions = adapter.extractFunctions();
|
|
105
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
106
|
-
expect(functions.some(fn => (fn as {name: string}).name === 'main')).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should throw error when file cannot be read', () => {
|
|
110
|
-
(readFileSync as Mock).mockImplementation(() => {
|
|
111
|
-
throw new Error('Could not read file');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
expect(() => {
|
|
115
|
-
new CppAdapter('nonexistent-file.cpp');
|
|
116
|
-
}).toThrow('Could not read file:');
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @test REQ-COV-004 CppAdapter extractCodeBlock branch coverage
|
|
122
|
-
* @intent Verify block-comment handling and nested-brace counting inside extractCodeBlock
|
|
123
|
-
* @covers AC-COV-004
|
|
124
|
-
*/
|
|
125
|
-
describe('CppAdapter - extractCodeBlock edge cases', () => {
|
|
126
|
-
it('should skip single-line block comment before the opening brace', () => {
|
|
127
|
-
const src = `int foo() /* inline comment */ { return 1; }`;
|
|
128
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
129
|
-
const adapter = new CppAdapter('test.cpp');
|
|
130
|
-
const block = adapter.extractCodeBlock(0);
|
|
131
|
-
expect(block).toContain('{ return 1; }');
|
|
132
|
-
expect(block.endsWith('}')).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should skip multi-line block comment spanning multiple lines', () => {
|
|
136
|
-
const src = [
|
|
137
|
-
'int foo()',
|
|
138
|
-
'/* this is a',
|
|
139
|
-
' multi-line block',
|
|
140
|
-
' comment */',
|
|
141
|
-
'{',
|
|
142
|
-
' return 42;',
|
|
143
|
-
'}',
|
|
144
|
-
].join('\n');
|
|
145
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
146
|
-
const adapter = new CppAdapter('test.cpp');
|
|
147
|
-
const block = adapter.extractCodeBlock(0);
|
|
148
|
-
expect(block).toContain('return 42;');
|
|
149
|
-
expect(block.trim().endsWith('}')).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('should ignore braces inside block comments', () => {
|
|
153
|
-
const src = `int foo() /* fake { brace } here */ { return 7; }`;
|
|
154
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
155
|
-
const adapter = new CppAdapter('test.cpp');
|
|
156
|
-
const block = adapter.extractCodeBlock(0);
|
|
157
|
-
expect(block).toContain('return 7;');
|
|
158
|
-
expect(block.trim().endsWith('}')).toBe(true);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should count nested braces correctly via braceCount++ path', () => {
|
|
162
|
-
const src = `void foo() { if (x) { return; } }`;
|
|
163
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
164
|
-
const adapter = new CppAdapter('test.cpp');
|
|
165
|
-
const block = adapter.extractCodeBlock(0);
|
|
166
|
-
expect(block).toBe('void foo() { if (x) { return; } }');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should handle deeply nested braces (triple nesting)', () => {
|
|
170
|
-
const src = `int bar() { if (a) { while (b) { c++; } } return 0; }`;
|
|
171
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
172
|
-
const adapter = new CppAdapter('test.cpp');
|
|
173
|
-
const block = adapter.extractCodeBlock(0);
|
|
174
|
-
expect(block.trim().endsWith('}')).toBe(true);
|
|
175
|
-
expect(block).toContain('c++;');
|
|
176
|
-
const opens = (block.match(/\{/g) || []).length;
|
|
177
|
-
const closes = (block.match(/\}/g) || []).length;
|
|
178
|
-
expect(opens).toBe(closes);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should combine block comments and nested braces in same body', () => {
|
|
182
|
-
const src = [
|
|
183
|
-
'int compute() {',
|
|
184
|
-
' /* outer block comment',
|
|
185
|
-
' with text { and } symbols */',
|
|
186
|
-
' if (a) {',
|
|
187
|
-
' /* nested comment */',
|
|
188
|
-
' return 1;',
|
|
189
|
-
' }',
|
|
190
|
-
' return 0;',
|
|
191
|
-
'}',
|
|
192
|
-
].join('\n');
|
|
193
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
194
|
-
const adapter = new CppAdapter('test.cpp');
|
|
195
|
-
const block = adapter.extractCodeBlock(0);
|
|
196
|
-
expect(block.trim().endsWith('}')).toBe(true);
|
|
197
|
-
expect(block).toContain('return 1;');
|
|
198
|
-
expect(block).toContain('return 0;');
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('should skip line comments (// ...) before brace', () => {
|
|
202
|
-
const src = [
|
|
203
|
-
'int foo() {',
|
|
204
|
-
' // line comment with { fake brace }',
|
|
205
|
-
' return 5;',
|
|
206
|
-
'}',
|
|
207
|
-
].join('\n');
|
|
208
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
209
|
-
const adapter = new CppAdapter('test.cpp');
|
|
210
|
-
const block = adapter.extractCodeBlock(0);
|
|
211
|
-
expect(block).toContain('return 5;');
|
|
212
|
-
expect(block.trim().endsWith('}')).toBe(true);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should extract constructors with member initializer lists', () => {
|
|
216
|
-
const src = [
|
|
217
|
-
'class Foo {',
|
|
218
|
-
'public:',
|
|
219
|
-
' Foo(int x) : value_(x) {',
|
|
220
|
-
' init();',
|
|
221
|
-
' }',
|
|
222
|
-
'private:',
|
|
223
|
-
' int value_;',
|
|
224
|
-
'};',
|
|
225
|
-
].join('\n');
|
|
226
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
227
|
-
const adapter = new CppAdapter('test.cpp');
|
|
228
|
-
const functions = adapter.extractFunctions();
|
|
229
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
230
|
-
expect(functions.some(fn => (fn as { type: string }).type === 'constructor')).toBe(true);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should extract classes from C++ source', () => {
|
|
234
|
-
const src = [
|
|
235
|
-
'class MyClass {',
|
|
236
|
-
'public:',
|
|
237
|
-
' void doStuff() { return; }',
|
|
238
|
-
'};',
|
|
239
|
-
'struct MyStruct : public Base {',
|
|
240
|
-
' int x;',
|
|
241
|
-
'};',
|
|
242
|
-
].join('\n');
|
|
243
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
244
|
-
const adapter = new CppAdapter('test.cpp');
|
|
245
|
-
const classes = adapter.extractClasses();
|
|
246
|
-
expect(Array.isArray(classes)).toBe(true);
|
|
247
|
-
expect(classes.length).toBeGreaterThanOrEqual(2);
|
|
248
|
-
expect(classes.some(c => (c as { name: string }).name === 'MyClass')).toBe(true);
|
|
249
|
-
expect(classes.some(c => (c as { name: string }).name === 'MyStruct')).toBe(true);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should count lines correctly', () => {
|
|
253
|
-
(readFileSync as Mock).mockReturnValue('line1\nline2\nline3');
|
|
254
|
-
const adapter = new CppAdapter('test.cpp');
|
|
255
|
-
expect(adapter.countLines()).toBe(3);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should fall back to super.detectLanguage for non-cpp extensions', () => {
|
|
259
|
-
(readFileSync as Mock).mockReturnValue('content');
|
|
260
|
-
const adapter = new CppAdapter('test.txt');
|
|
261
|
-
expect(adapter.detectLanguage()).toBe('unknown');
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('should extract functions correctly when source has block comments and nested braces', () => {
|
|
265
|
-
const src = [
|
|
266
|
-
'/* file header comment */',
|
|
267
|
-
'int outer(int x) {',
|
|
268
|
-
' /* explain logic */',
|
|
269
|
-
' if (x > 0) {',
|
|
270
|
-
' return x;',
|
|
271
|
-
' }',
|
|
272
|
-
' return -x;',
|
|
273
|
-
'}',
|
|
274
|
-
].join('\n');
|
|
275
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
276
|
-
const adapter = new CppAdapter('test.cpp');
|
|
277
|
-
const functions = adapter.extractFunctions();
|
|
278
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
279
|
-
expect(functions.some(fn => (fn as { name: string }).name === 'outer')).toBe(true);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('should extract functions with scope prefix (e.g. MyClass::method)', () => {
|
|
283
|
-
const src = 'void MyClass::method() { return; }';
|
|
284
|
-
(readFileSync as Mock).mockReturnValue(src);
|
|
285
|
-
const adapter = new CppAdapter('test.cpp');
|
|
286
|
-
const functions = adapter.extractFunctions();
|
|
287
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
288
|
-
expect(functions.some(fn => (fn as { name: string }).name === 'MyClass::method')).toBe(true);
|
|
289
|
-
});
|
|
290
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, type Mock } from 'vitest';;
|
|
2
|
-
import { DartAdapter } from '../dart';
|
|
3
|
-
|
|
4
|
-
vi.mock('fs', () => ({
|
|
5
|
-
readFileSync: vi.fn(),
|
|
6
|
-
existsSync: vi.fn(() => true),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
import { readFileSync } from 'fs';
|
|
10
|
-
|
|
11
|
-
describe('DartAdapter', () => {
|
|
12
|
-
it('should implement the Adapter interface', () => {
|
|
13
|
-
(readFileSync as Mock).mockReturnValue('void testFn() {}\nclass TestClass {}');
|
|
14
|
-
const adapter = new DartAdapter('test.dart');
|
|
15
|
-
|
|
16
|
-
expect(adapter).toHaveProperty('detectLanguage');
|
|
17
|
-
expect(adapter).toHaveProperty('parseAST');
|
|
18
|
-
expect(adapter).toHaveProperty('extractFunctions');
|
|
19
|
-
expect(adapter).toHaveProperty('extractClasses');
|
|
20
|
-
expect(adapter).toHaveProperty('countLines');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should detect language as dart for .dart files', () => {
|
|
24
|
-
(readFileSync as Mock).mockReturnValue('void testFn() {}');
|
|
25
|
-
const adapter = new DartAdapter('test.dart');
|
|
26
|
-
const detected = adapter.detectLanguage();
|
|
27
|
-
expect(detected).toBe('dart');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should parse Dart file AST correctly', () => {
|
|
31
|
-
(readFileSync as Mock).mockReturnValue('void testFn() {}\nclass TestClass {}');
|
|
32
|
-
const adapter = new DartAdapter('test.dart');
|
|
33
|
-
const ast = adapter.parseAST();
|
|
34
|
-
expect(ast).toHaveProperty('content');
|
|
35
|
-
expect(ast).toHaveProperty('language');
|
|
36
|
-
expect(ast).toHaveProperty('filePath');
|
|
37
|
-
expect((ast as { language: unknown }).language).toBe('dart');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should extract functions from Dart AST', () => {
|
|
41
|
-
(readFileSync as Mock).mockReturnValue('void testFn() {}\nclass TestClass {}');
|
|
42
|
-
const adapter = new DartAdapter('test.dart');
|
|
43
|
-
const functions = adapter.extractFunctions();
|
|
44
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
45
|
-
expect(functions.some(fn => (fn as {name: string}).name === 'testFn')).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should extract classes from Dart AST', () => {
|
|
49
|
-
(readFileSync as Mock).mockReturnValue('void testFn() {}\nclass TestClass {}');
|
|
50
|
-
const adapter = new DartAdapter('test.dart');
|
|
51
|
-
const classes = adapter.extractClasses();
|
|
52
|
-
expect(Array.isArray(classes)).toBe(true);
|
|
53
|
-
expect(classes.some(cls => (cls as {name: string}).name === 'TestClass')).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should count Dart file physical lines', () => {
|
|
57
|
-
(readFileSync as Mock).mockReturnValue('void testFn() {}\nvoid testFn2() {}');
|
|
58
|
-
const adapter = new DartAdapter('test.dart');
|
|
59
|
-
const lineCount = adapter.countLines();
|
|
60
|
-
expect(lineCount).toBe(2);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should fall back to super.detectLanguage for non-dart extensions', () => {
|
|
64
|
-
(readFileSync as Mock).mockReturnValue('content');
|
|
65
|
-
const adapter = new DartAdapter('test.py');
|
|
66
|
-
expect(adapter.detectLanguage()).toBe('python');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should handle async functions in Dart', () => {
|
|
70
|
-
(readFileSync as Mock).mockReturnValue('Future<void> fetchData() async {}\nasync void fireAndForget() {}');
|
|
71
|
-
const adapter = new DartAdapter('test.dart');
|
|
72
|
-
const functions = adapter.extractFunctions();
|
|
73
|
-
const asyncFns = functions.filter(fn => (fn as {type: string}).type === 'async_function');
|
|
74
|
-
expect(asyncFns.length).toBeGreaterThan(0);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should handle abstract class declarations in Dart', () => {
|
|
78
|
-
(readFileSync as Mock).mockReturnValue('abstract class Repository {\n void save();\n}\n');
|
|
79
|
-
const adapter = new DartAdapter('test.dart');
|
|
80
|
-
const classes = adapter.extractClasses();
|
|
81
|
-
const abstractClasses = classes.filter(cls => (cls as {type: string}).type === 'abstract_class');
|
|
82
|
-
expect(abstractClasses.length).toBeGreaterThan(0);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, type Mock } from 'vitest';;
|
|
2
|
-
import { GoAdapter } from '../go';
|
|
3
|
-
|
|
4
|
-
vi.mock('fs', () => ({
|
|
5
|
-
readFileSync: vi.fn(),
|
|
6
|
-
existsSync: vi.fn(() => true),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
import { readFileSync } from 'fs';
|
|
10
|
-
|
|
11
|
-
describe('GoAdapter', () => {
|
|
12
|
-
it('should implement the Adapter interface', () => {
|
|
13
|
-
(readFileSync as Mock).mockReturnValue('func testFn() {}\ntype TestClass struct {}');
|
|
14
|
-
const adapter = new GoAdapter('test.go');
|
|
15
|
-
|
|
16
|
-
expect(adapter).toHaveProperty('detectLanguage');
|
|
17
|
-
expect(adapter).toHaveProperty('parseAST');
|
|
18
|
-
expect(adapter).toHaveProperty('extractFunctions');
|
|
19
|
-
expect(adapter).toHaveProperty('extractClasses');
|
|
20
|
-
expect(adapter).toHaveProperty('countLines');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should detect language as go for .go files', () => {
|
|
24
|
-
(readFileSync as Mock).mockReturnValue('func testFn() {}');
|
|
25
|
-
const adapter = new GoAdapter('test.go');
|
|
26
|
-
const detected = adapter.detectLanguage();
|
|
27
|
-
expect(detected).toBe('go');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should parse Go file AST correctly', () => {
|
|
31
|
-
(readFileSync as Mock).mockReturnValue('func testFn() {}\ntype TestClass struct {}');
|
|
32
|
-
const adapter = new GoAdapter('test.go');
|
|
33
|
-
const ast = adapter.parseAST();
|
|
34
|
-
expect(ast).toHaveProperty('content');
|
|
35
|
-
expect(ast).toHaveProperty('language');
|
|
36
|
-
expect(ast).toHaveProperty('filePath');
|
|
37
|
-
expect((ast as { language: unknown }).language).toBe('go');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should extract functions from Go AST', () => {
|
|
41
|
-
(readFileSync as Mock).mockReturnValue('func testFn() {}\nfunc (t *TestClass) method() {}');
|
|
42
|
-
const adapter = new GoAdapter('test.go');
|
|
43
|
-
const functions = adapter.extractFunctions();
|
|
44
|
-
expect(Array.isArray(functions)).toBe(true);
|
|
45
|
-
expect(functions.some(fn => (fn as {name: string}).name === 'testFn')).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should extract structs from Go AST', () => {
|
|
49
|
-
(readFileSync as Mock).mockReturnValue('func testFn() {}\ntype TestClass struct {}');
|
|
50
|
-
const adapter = new GoAdapter('test.go');
|
|
51
|
-
const classes = adapter.extractClasses();
|
|
52
|
-
expect(Array.isArray(classes)).toBe(true);
|
|
53
|
-
expect(classes.some(cls => (cls as {name: string}).name === 'TestClass')).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should count Go file physical lines', () => {
|
|
57
|
-
(readFileSync as Mock).mockReturnValue('func testFn() {}\nfunc testFn2() {}');
|
|
58
|
-
const adapter = new GoAdapter('test.go');
|
|
59
|
-
const lineCount = adapter.countLines();
|
|
60
|
-
expect(lineCount).toBe(2);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should fall back to super.detectLanguage for non-go extensions', () => {
|
|
64
|
-
(readFileSync as Mock).mockReturnValue('content');
|
|
65
|
-
const adapter = new GoAdapter('test.ts');
|
|
66
|
-
expect(adapter.detectLanguage()).toBe('typescript');
|
|
67
|
-
});
|
|
68
|
-
});
|