Skip to content

Commit

Permalink
test(loaders): Fix text and json loaders tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Aug 12, 2023
1 parent 4e911ea commit 3c69adf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
19 changes: 8 additions & 11 deletions packages/langchain/test/documents/loaders/json_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ void main() {
test('Test that a json file can be loaded', () async {
const filePath = './test/documents/loaders/assets/example_1.json';

final expectedDoc = Document(
pageContent: 'Foo\nBar\nBaz\n',
metadata: {
'source': filePath,
'name': 'example_1.json',
'size': 32,
'lastModified': DateTime.parse('2023-07-13 17:49:35.000'),
},
);

const loader = JsonLoader(
filePath,
jpSchema: r'$..text',
Expand All @@ -24,7 +14,14 @@ void main() {
expect(
loader.lazyLoad(),
emitsInOrder([
expectedDoc,
(final Document doc) {
expect(doc.pageContent, 'Foo\nBar\nBaz\n');
expect(doc.metadata['source'], filePath);
expect(doc.metadata['name'], 'example_1.json');
expect(doc.metadata['size'], 32);
expect(doc.metadata['lastModified'], isA<DateTime>());
return true;
},
emitsDone,
]),
);
Expand Down
20 changes: 8 additions & 12 deletions packages/langchain/test/documents/loaders/text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ void main() {
group('TextLoader tests', () {
test('Test that a text file can be loaded', () async {
const filePath = './test/documents/loaders/assets/example.txt';

final expectedDoc = Document(
pageContent: 'Foo\nBar\nBaz\n',
metadata: {
'source': filePath,
'name': 'example.txt',
'size': 12,
'lastModified': DateTime.parse('2023-06-20 22:12:19.000'),
},
);

const loader = TextLoader(filePath);
expect(
loader.lazyLoad(),
emitsInOrder([
expectedDoc,
(final Document doc) {
expect(doc.pageContent, 'Foo\nBar\nBaz\n');
expect(doc.metadata['source'], filePath);
expect(doc.metadata['name'], 'example.txt');
expect(doc.metadata['size'], 12);
expect(doc.metadata['lastModified'], isA<DateTime>());
return true;
},
emitsDone,
]),
);
Expand Down

0 comments on commit 3c69adf

Please sign in to comment.