<commit_before>library sembast.database_import_export_test;

import 'dart:async';

import 'package:sembast/sembast.dart';
import 'package:sembast/utils/sembast_import_export.dart';
import 'test_common.dart';

void main() {
  defineTests(memoryDatabaseContext);
}

void defineTests(DatabaseTestContext ctx) {
  group('import_export', () {
    tearDown(() {});

    Future _checkExportImport(Database db, Map expectedExport) async {
      var export = await exportDatabase(db);
      expect(export, expectedExport);

      // import and reexport to test content
      String importDbPath = ctx.dbPath + "_import.db";
      Database importedDb =
          await importDatabase(export, ctx.factory, importDbPath);
      expect(await exportDatabase(importedDb), expectedExport);
    }

    test('no_version', () async {
      Database db = await ctx.open();
      await _checkExportImport(db, {'sembast_export': 1, 'version': 1});
    });

    test('version_2', () async {
      Database db = await ctx.open(2);
      await _checkExportImport(db, {'sembast_export': 1, 'version': 2});
    });<commit_msg>test: fix js import/export test by properly closing the database<commit_after>library sembast.database_import_export_test;

import 'dart:async';

import 'package:sembast/sembast.dart';
import 'package:sembast/utils/sembast_import_export.dart';
import 'test_common.dart';

void main() {
  defineTests(memoryDatabaseContext);
}

void defineTests(DatabaseTestContext ctx) {
  group('import_export', () {
    tearDown(() {});

    Future _checkExportImport(Database db, Map expectedExport) async {
      var export = await exportDatabase(db);
      expect(export, expectedExport);
      await db.close();

      // import and reexport to test content
      String importDbPath = ctx.dbPath + "_import.db";
      Database importedDb =
          await importDatabase(export, ctx.factory, importDbPath);
      expect(await exportDatabase(importedDb), expectedExport);
      await importedDb.close();
    }

    test('no_version', () async {
      Database db = await ctx.open();
      await _checkExportImport(db, {'sembast_export': 1, 'version': 1});
    });

    test('version_2', () async {
      Database db = await ctx.open(2);
      await _checkExportImport(db, {'sembast_export': 1, 'version': 2});
    });
{'fraction_non_alphanumeric': 0.1266811279826464, 'fraction_numerical': 0.005206073752711497, 'mean_word_length': 3.980561555075594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380028', 'n_tokens_mistral': 684, 'n_tokens_neox': 679, 'n_words': 159}