Skip to content

Commit 33c8a5b

Browse files
committed
Add: test_suite.dart in dart dir
1 parent 5713516 commit 33c8a5b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/dart/test_suite.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'dart:io';
2+
import 'dart:convert';
3+
4+
import '../../dart/lib/fsoft_diff_patch.dart';
5+
6+
void main() {
7+
// for all directories in ../data directory, run the test
8+
var dataDir =
9+
Directory('../data');
10+
var dirs = dataDir
11+
.listSync()
12+
.where((e) => e is Directory)
13+
.map((e) => e.path)
14+
.toList()
15+
..sort();
16+
17+
for (final dir in dirs) {
18+
19+
final dirName = dir.split("/").last;
20+
21+
// write dir name, but keep the cursor at the same line
22+
stdout.write('Testing: $dirName ... ');
23+
24+
final file01 = File('$dir/01.json');
25+
final file02 = File('$dir/02.json');
26+
27+
// read file 01.json and 02.json from the directory
28+
final obj01 = jsonDecode(file01.readAsStringSync());
29+
final obj02 = jsonDecode(file02.readAsStringSync());
30+
31+
// diff obj01 and obj02 and create a diffData object
32+
final diffData = diff(obj01, obj02);
33+
34+
// apply diffData to obj01 and create a new object
35+
final patchedObj01 = patch(obj01, diffData);
36+
37+
// check if patchedObj01 is equal to obj02
38+
if (jsonEncode(patchedObj01) != jsonEncode(obj02)) {
39+
print('FAILED');
40+
} else {
41+
print('OK');
42+
}
43+
}
44+
;
45+
}

0 commit comments

Comments
 (0)