mirror of
https://github.com/yamadashy/repomix.git
synced 2026-02-03 11:33:39 +01:00
Created BaseParseStrategy abstract class to reduce code duplication: - Common helper methods (getCaptureTypes, checkAndAddToProcessed, validateLineExists) - Shared ParseResult type and CommonCaptureTypes constants - All strategies (Default, TypeScript, Python, Go, CSS, Vue) now extend base class Unified language configuration in languageConfig.ts: - Consolidated ext2Lang.ts and lang2Query.ts functionality - Single source of truth for language settings (extensions, queries, strategies) - Efficient Map-based lookup system for better performance - Removed switch statement in createParseStrategy() Updated all Strategy classes to extend BaseParseStrategy: - Eliminated ~200 lines of duplicate code - Improved maintainability and extensibility - Easier to add new languages (single configuration change) This refactoring was motivated by the need to reduce code duplication across language-specific strategies and simplify the process of adding new language support. The previous implementation had language configurations scattered across multiple files, making it difficult to maintain and extend.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { CHUNK_SEPARATOR, parseFile } from '../../../src/core/treeSitter/parseFile.js';
|
|
import { createMockConfig } from '../../testing/testUtils.js';
|
|
|
|
describe('parseFile', () => {
|
|
// Test for merging adjacent chunks
|
|
test('should merge adjacent chunks', async () => {
|
|
const fileContent = `
|
|
/**
|
|
* First function
|
|
*/
|
|
function first() {
|
|
console.log('first');
|
|
}
|
|
|
|
/**
|
|
* Second function, right after first
|
|
*/
|
|
function second() {
|
|
console.log('second');
|
|
}
|
|
|
|
// Some space
|
|
|
|
/**
|
|
* Third function
|
|
*/
|
|
function third() {
|
|
console.log('third');
|
|
}
|
|
`;
|
|
const filePath = 'dummy.js';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
expect(result).not.toBeUndefined();
|
|
|
|
if (result) {
|
|
const chunks = result.split(`\n${CHUNK_SEPARATOR}\n`);
|
|
expect(chunks.length).toBe(4);
|
|
|
|
expect(chunks[0]).toContain('* First function');
|
|
expect(chunks[0]).toContain('function first()');
|
|
expect(chunks[1]).toContain('* Second function');
|
|
expect(chunks[1]).toContain('function second()');
|
|
expect(chunks[2]).toContain('// Some space');
|
|
expect(chunks[3]).toContain('* Third function');
|
|
expect(chunks[3]).toContain('function third()');
|
|
}
|
|
});
|
|
});
|