Files
pipelines/app/test/features/artifacts/domain/artifact_table_test.dart
T

59 lines
1.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_table.dart';
void main() {
test('plain rows split on the delimiter', () {
final table = parseArtifactTable('id,name\n1,alpha\n2,beta\n');
expect(table.rows, [
['id', 'name'],
['1', 'alpha'],
['2', 'beta'],
]);
expect(table.totalRows, 3);
expect(table.truncated, isFalse);
expect(table.columnCount, 2);
});
test('quoted fields keep delimiters, line breaks and doubled quotes', () {
final table = parseArtifactTable(
'k,v\r\n"a,b","line1\nline2"\r\n"say ""hi""",\r\n',
);
expect(table.rows, [
['k', 'v'],
['a,b', 'line1\nline2'],
['say "hi"', ''],
]);
});
test('ragged rows are kept as recorded', () {
final table = parseArtifactTable('a,b,c\n1\n1,2,3,4');
expect(table.rows, [
['a', 'b', 'c'],
['1'],
['1', '2', '3', '4'],
]);
expect(table.columnCount, 4);
});
test('tab-separated values use the tab delimiter', () {
final table = parseArtifactTable('a\tb\n1\t2', delimiter: '\t');
expect(table.rows, [
['a', 'b'],
['1', '2'],
]);
});
test('a large file is capped and says how many rows it has', () {
final text = List.generate(10, (i) => 'r$i').join('\n');
final table = parseArtifactTable(text, limit: 4);
expect(table.rows, hasLength(4));
expect(table.totalRows, 10);
expect(table.truncated, isTrue);
});
test('an empty file has no rows', () {
expect(parseArtifactTable('').rows, isEmpty);
expect(parseArtifactTable('\n').totalRows, 0);
});
}