From 2eb301f62ae9d124c50c6e857754f323ac31ef5b Mon Sep 17 00:00:00 2001 From: Andika Tanuwijaya Date: Wed, 2 Jul 2025 20:20:37 +0700 Subject: [PATCH] enable unit test --- bindings/dart/lib/turso_dart.dart | 2 ++ bindings/dart/rust/.gitignore | 1 + bindings/dart/test/_memory_test.dart | 44 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 bindings/dart/test/_memory_test.dart diff --git a/bindings/dart/lib/turso_dart.dart b/bindings/dart/lib/turso_dart.dart index 5c4a303ab..f2511a5b4 100644 --- a/bindings/dart/lib/turso_dart.dart +++ b/bindings/dart/lib/turso_dart.dart @@ -1,3 +1,5 @@ library; +export 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + export 'src/client.dart'; diff --git a/bindings/dart/rust/.gitignore b/bindings/dart/rust/.gitignore index ea8c4bf7f..eca191f6d 100644 --- a/bindings/dart/rust/.gitignore +++ b/bindings/dart/rust/.gitignore @@ -1 +1,2 @@ /target +/test_build \ No newline at end of file diff --git a/bindings/dart/test/_memory_test.dart b/bindings/dart/test/_memory_test.dart new file mode 100644 index 000000000..443444472 --- /dev/null +++ b/bindings/dart/test/_memory_test.dart @@ -0,0 +1,44 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:turso_dart/src/rust/frb_generated.dart'; +import 'package:turso_dart/turso_dart.dart'; + +void main() async { + setUpAll(() async { + final lib = await loadExternalLibrary( + ExternalLibraryLoaderConfig( + stem: "turso_dart", + ioDirectory: "rust/test_build/debug/", + webPrefix: null, + ), + ); + await RustLib.init(externalLibrary: lib); + }); + + test('should be able to perform queries', () async { + final client = TursoClient.memory(); + await client.connect(); + + await client.execute( + "create table if not exists tasks (id integer primary key, title text, description text, completed integer)", + ); + + final rowsAffected = await client.execute( + "insert into tasks (title, description, completed) values (?, ?, ?)", + positional: ["title", "description", 0], + ); + expect(rowsAffected, equals(1)); + + final result = await client.query("select * from tasks"); + expect( + result, + equals([ + { + "id": 1, + "title": "title", + "description": "description", + "completed": 0, + }, + ]), + ); + }); +}