mirror of
https://github.com/yamadashy/repomix.git
synced 2026-02-03 11:33:39 +01:00
Expand Dart tree-sitter query based on grammar analysis to capture: - Enum declarations for better type understanding - Extension declarations (commonly used in modern Dart) - Constructor signatures (important for class structure) This addresses feedback from code review bots suggesting more comprehensive structural element capture while maintaining simplicity. The implementation is validated against actual tree-sitter-dart grammar and includes test coverage for all new node types. Updated biome.json schema version to match CLI version 2.2.5.
138 lines
3.6 KiB
TypeScript
138 lines
3.6 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { parseFile } from '../../../src/core/treeSitter/parseFile.js';
|
|
import { createMockConfig } from '../../../tests/testing/testUtils.js';
|
|
|
|
describe('parseFile for Dart', () => {
|
|
test('should parse Dart correctly', async () => {
|
|
const fileContent = `
|
|
/// A simple greeting class
|
|
class Greeter {
|
|
/// The name to greet
|
|
final String name;
|
|
|
|
/// Constructor
|
|
Greeter(this.name);
|
|
|
|
/// Prints a greeting message
|
|
void greet() {
|
|
print('Hello, $name!');
|
|
}
|
|
|
|
/// Returns a greeting message
|
|
String getMessage() {
|
|
return 'Hello, $name!';
|
|
}
|
|
}
|
|
|
|
/// Main entry point
|
|
void main() {
|
|
final greeter = Greeter('World');
|
|
greeter.greet();
|
|
}
|
|
`;
|
|
const filePath = 'dummy.dart';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
'/// A simple greeting class',
|
|
'class Greeter {',
|
|
'/// The name to greet',
|
|
'/// Constructor',
|
|
'/// Prints a greeting message',
|
|
'void greet() {',
|
|
'/// Returns a greeting message',
|
|
'String getMessage() {',
|
|
'/// Main entry point',
|
|
'void main() {',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should parse Dart with imports correctly', async () => {
|
|
const fileContent = `
|
|
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// A simple widget
|
|
class MyWidget extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container();
|
|
}
|
|
}
|
|
`;
|
|
const filePath = 'dummy.dart';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
"import 'dart:async';",
|
|
"import 'package:flutter/material.dart';",
|
|
'/// A simple widget',
|
|
'class MyWidget extends StatelessWidget {',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should parse Dart with enum, extension, and constructor', async () => {
|
|
const fileContent = `
|
|
/// Status enum
|
|
enum Status {
|
|
pending,
|
|
active,
|
|
completed
|
|
}
|
|
|
|
/// String extension
|
|
extension StringExtension on String {
|
|
/// Capitalizes first letter
|
|
String capitalize() {
|
|
return this[0].toUpperCase() + substring(1);
|
|
}
|
|
}
|
|
|
|
/// User class
|
|
class User {
|
|
final String name;
|
|
final Status status;
|
|
|
|
/// User constructor
|
|
User(this.name, this.status);
|
|
|
|
/// Named constructor
|
|
User.guest() : name = 'Guest', status = Status.pending;
|
|
}
|
|
`;
|
|
const filePath = 'dummy.dart';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
'/// Status enum',
|
|
'enum Status {',
|
|
'/// String extension',
|
|
'extension StringExtension on String {',
|
|
'/// Capitalizes first letter',
|
|
'String capitalize() {',
|
|
'/// User class',
|
|
'class User {',
|
|
'/// User constructor',
|
|
'/// Named constructor',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
});
|