Add tests
This commit is contained in:
26
test/search/kanji_search_test.dart
Normal file
26
test/search/kanji_search_test.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:jadb/jouyou_kanji.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'setup_database_connection.dart';
|
||||
|
||||
void main() {
|
||||
test("Search a kanji", () async {
|
||||
final connection = await setup_database_connection();
|
||||
|
||||
final result = await connection.searchKanji('漢');
|
||||
expect(result, isNotNull);
|
||||
});
|
||||
|
||||
group("Search all jouyou kanji", () {
|
||||
JOUYOU_KANJI.forEach((grade, characters) {
|
||||
test("Search all kanji in grade $grade", () async {
|
||||
final connection = await setup_database_connection();
|
||||
|
||||
for (final character in characters) {
|
||||
final result = await connection.searchKanji(character);
|
||||
expect(result, isNotNull);
|
||||
}
|
||||
}, timeout: Timeout.factor(10));
|
||||
});
|
||||
});
|
||||
}
|
||||
34
test/search/setup_database_connection.dart
Normal file
34
test/search/setup_database_connection.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:jadb/search.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
import 'package:sqlite3/open.dart';
|
||||
|
||||
Future<JaDBConnection> setup_database_connection() async {
|
||||
final lib_sqlite_path = Platform.environment['LIBSQLITE_PATH'];
|
||||
final jadb_path = Platform.environment['JADB_PATH'];
|
||||
|
||||
if (lib_sqlite_path == null) {
|
||||
throw Exception("LIBSQLITE_PATH is not set");
|
||||
}
|
||||
|
||||
if (jadb_path == null) {
|
||||
throw Exception("JADB_PATH is not set");
|
||||
}
|
||||
|
||||
final db_connection = createDatabaseFactoryFfi(ffiInit: () {
|
||||
open.overrideForAll(
|
||||
() => DynamicLibrary.open(lib_sqlite_path),
|
||||
);
|
||||
}).openDatabase(
|
||||
jadb_path,
|
||||
options: OpenDatabaseOptions(
|
||||
onOpen: (db) {
|
||||
db.execute("PRAGMA foreign_keys = ON");
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return JaDBConnection(await db_connection);
|
||||
}
|
||||
26
test/search/word_search_test.dart
Normal file
26
test/search/word_search_test.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'setup_database_connection.dart';
|
||||
|
||||
void main() {
|
||||
test("Search a word", () async {
|
||||
final connection = await setup_database_connection();
|
||||
|
||||
final result = await connection.searchWord("kana");
|
||||
expect(result, isNotNull);
|
||||
});
|
||||
|
||||
test(
|
||||
"Serialize all words",
|
||||
() async {
|
||||
final connection = await setup_database_connection();
|
||||
|
||||
// Test serializing all words
|
||||
for (final letter in "aiueoksthnmyrw".split("")) {
|
||||
await connection.searchWord(letter);
|
||||
}
|
||||
},
|
||||
timeout: Timeout.factor(100),
|
||||
skip: "Very slow test",
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user