<commit_before>#library('IndexedDB4Test');
#import('../../lib/unittest/unittest.dart');
#import('../../lib/unittest/dom_config.dart');
#import('dart:dom');

// Test for IDBKeyRange and IDBCursor.

final String DB_NAME = 'Test';
final String STORE_NAME = 'TEST';
final String VERSION = '1';

class Test {
  var db;

  start() {
    var request = window.webkitIndexedDB.open(DB_NAME);
    Expect.isNotNull(request);
    request.addEventListener('success', initDb);
    request.addEventListener('error', fail('open'));
  }

  initDb(e) {
    db = e.target.result;
    // TODO.  Some browsers do this the w3 way - passing the VERSION to the
    // open call and listening to onversionchange.  Can we feature-detect the
    // difference and make it work?
    var request = db.setVersion(VERSION);
    request.addEventListener('success', (e) {
        try {
          // Nuke object store if it already exists.
          db.deleteObjectStore(STORE_NAME);
        } catch (IDBDatabaseException e) { }
        db.createObjectStore(STORE_NAME);
        writeItems(0);
      });
      request.addEventListener('blocked', fail('setVersion blocked'));
      request.addEventListener('error', fail('setVersion error'));
  }

  writeItems(int index) {
    if (index < 100) {
      var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE);
      var request = transaction.objectStore(STORE_NAME)
          .put('Item $index', index);
      request.addEventListener('success', (e) { writeItems(index + 1); });
      request.addEventListener('error', fail('put'));
    } else {
      callbackDone();
    }
  }

  fail(message) => (e) {
    callbackDone();
    Expect.fail('IndexedDB failure: $message');
  };

  testRange(range, expectedFirst, expectedLast) {
    IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY);
    IDBObjectStore objectStore = txn.objectStore(STORE_NAME);
    IDBRequest cursorRequest = objectStore.openCursor(range);
    int itemCount = 0;
    int firstKey = null;
    int lastKey = null;
    cursorRequest.addEventListener("success", (e) {
        var cursor = e.target.result;
        if (cursor != null) {
          if (firstKey == null) firstKey = cursor.key;
          lastKey = cursor.key;
          itemCount += 1;
          Expect.equals('Item ${cursor.key.toStringAsFixed(0)}', cursor.value);
          cursor.continueFunction();
        } else {<commit_msg>Quick fix to placate checked mode.<commit_after>#library('IndexedDB4Test');
#import('../../lib/unittest/unittest.dart');
#import('../../lib/unittest/dom_config.dart');
#import('dart:dom');

// Test for IDBKeyRange and IDBCursor.

final String DB_NAME = 'Test';
final String STORE_NAME = 'TEST';
final String VERSION = '1';

class Test {
  var db;

  start() {
    var request = window.webkitIndexedDB.open(DB_NAME);
    Expect.isNotNull(request);
    request.addEventListener('success', initDb);
    request.addEventListener('error', fail('open'));
  }

  initDb(e) {
    db = e.target.result;
    // TODO.  Some browsers do this the w3 way - passing the VERSION to the
    // open call and listening to onversionchange.  Can we feature-detect the
    // difference and make it work?
    var request = db.setVersion(VERSION);
    request.addEventListener('success', (e) {
        try {
          // Nuke object store if it already exists.
          db.deleteObjectStore(STORE_NAME);
        } catch (IDBDatabaseException e) { }
        db.createObjectStore(STORE_NAME);
        writeItems(0);
      });
      request.addEventListener('blocked', fail('setVersion blocked'));
      request.addEventListener('error', fail('setVersion error'));
  }

  writeItems(int index) {
    if (index < 100) {
      var transaction = db.transaction([STORE_NAME], IDBTransaction.READ_WRITE);
      var request = transaction.objectStore(STORE_NAME)
          .put('Item $index', index);
      request.addEventListener('success', (e) { writeItems(index + 1); });
      request.addEventListener('error', fail('put'));
    } else {
      callbackDone();
    }
  }

  fail(message) => (e) {
    callbackDone();
    Expect.fail('IndexedDB failure: $message');
  };

  testRange(range, expectedFirst, expectedLast) {
    IDBTransaction txn = db.transaction(STORE_NAME, IDBTransaction.READ_ONLY);
    IDBObjectStore objectStore = txn.objectStore(STORE_NAME);
    IDBRequest cursorRequest = objectStore.openCursor(range);
    int itemCount = 0;
    num firstKey = null;
    num lastKey = null;
    cursorRequest.addEventListener("success", (e) {
        var cursor = e.target.result;
        if (cursor != null) {
          if (firstKey == null) firstKey = cursor.key;
          lastKey = cursor.key;
          itemCount += 1;
          Expect.equals('Item ${cursor.key.toStringAsFixed(0)}', cursor.value);
          cursor.continueFunction();
        } else {
{'fraction_non_alphanumeric': 0.13714167869663849, 'fraction_numerical': 0.004537017941843679, 'mean_word_length': 3.1066892464013547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6865017', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1424, 'n_words': 331}