63 lines
2.1 KiB
Dart
63 lines
2.1 KiB
Dart
|
|
// This file is auto-generated by alef — DO NOT EDIT.
|
||
|
|
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
|
||
|
|
// To regenerate: alef generate
|
||
|
|
// To verify freshness: alef verify --exit-code
|
||
|
|
// Issues & docs: https://github.com/kreuzberg-dev/alef
|
||
|
|
// ignore_for_file: unused_local_variable
|
||
|
|
|
||
|
|
import 'package:test/test.dart';
|
||
|
|
import 'dart:io';
|
||
|
|
import 'package:kreuzberg/kreuzberg.dart';
|
||
|
|
import 'package:kreuzberg/src/kreuzberg_bridge_generated/frb_generated.dart' show RustLib;
|
||
|
|
|
||
|
|
// E2e tests for category: code
|
||
|
|
|
||
|
|
String _alefE2eText(Object? value) {
|
||
|
|
if (value == null) return '';
|
||
|
|
// Check if it's an enum by examining its toString representation.
|
||
|
|
final str = value.toString();
|
||
|
|
if (str.contains('.')) {
|
||
|
|
// Enum.toString() returns 'EnumName.variantName'. Extract the variant name.
|
||
|
|
final parts = str.split('.');
|
||
|
|
if (parts.length == 2) {
|
||
|
|
final variantName = parts[1];
|
||
|
|
// Convert camelCase variant names to snake_case for serde compatibility.
|
||
|
|
// E.g. 'toolCalls' -> 'tool_calls', 'stop' -> 'stop'.
|
||
|
|
return _camelToSnake(variantName);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return str;
|
||
|
|
}
|
||
|
|
|
||
|
|
String _camelToSnake(String camel) {
|
||
|
|
final buffer = StringBuffer();
|
||
|
|
for (int i = 0; i < camel.length; i++) {
|
||
|
|
final char = camel[i];
|
||
|
|
if (char.contains(RegExp(r'[A-Z]'))) {
|
||
|
|
if (i > 0) buffer.write('_');
|
||
|
|
buffer.write(char.toLowerCase());
|
||
|
|
} else {
|
||
|
|
buffer.write(char);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return buffer.toString();
|
||
|
|
}
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
setUpAll(() async {
|
||
|
|
await RustLib.init();
|
||
|
|
final _testDocs = Platform.environment['FIXTURES_DIR'] ?? '../../test_documents';
|
||
|
|
final _dir = Directory(_testDocs);
|
||
|
|
if (_dir.existsSync()) Directory.current = _dir;
|
||
|
|
});
|
||
|
|
|
||
|
|
test('Test language detection from shebang line via bytes input', () async {
|
||
|
|
final result = await KreuzbergBridge.extractFileSync('code/script.sh', 'text/x-source-code');
|
||
|
|
expect(result.mimeType.toString().trim(), equals('text/x-source-code'.toString().trim()));
|
||
|
|
expect(result.content.length, greaterThanOrEqualTo(10));
|
||
|
|
expect(result.content, contains('build'));
|
||
|
|
expect(result.content, contains('clean'));
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|