<commit_before>﻿///<reference path="../src/Dexie.js" />

(function(){
    var db = new Dexie("TestDB");
    db.version(1).stores({ users: "++id,first,last,&username,*&email,*pets" });

    //db.users.mapToClass(User);
    var User = db.users.defineClass({
        id:         Number,
        first:      String,
        last:       String,
        username:   String,
        email:      [String],
        pets:       [String],
    });

    db.on("populate", function (trans) {
        db.users.add({first: "David", last: "Fahlander", username: "dfahlander", email: ["<EMAIL>", "<EMAIL>"], pets: ["dog"]});
        db.users.add({first: "Karl", last: "Faadersköld", username: "kceder", email: ["<EMAIL>", "<EMAIL>"], pets: []});
    });

    module("table", {
        setup: function () {
            stop();
            db.delete().then(function () {
                db.open();
                start();
            }).catch(function (e) {
                ok(false, "Error deleting database: " + e);
                start();
            });
        },
        teardown: function () {
            stop(); db.delete().finally(start);
        }
    });

    asyncTest("get", 4, function () {
        db.table("users").get(1, function (obj) {
            equal(obj.first, "David", "Got the first object");
            db.users.get(2).then(function (obj) {
                equal(obj.first, "Karl", "Got the second object");
                db.users.get(100).then(function (obj) {
                    ok(true, "Got then() even when getting non-existing object");
                    equal(obj, undefined, "Result is 'undefined' when not existing");
                    start();
                });
            });
        });
    });

    asyncTest("where", function () {
        db.transaction("r", db.users, function () {
            db.users.where("username").equals("kceder").first(function (user) {
                equal(user.first, "Karl", "where().equals()");
            }),
            db.users.where("id").above(1).toArray(function (a) {
                ok(a.length == 1, "where().above()");
            }),<commit_msg>Table.get() unit test continue also when failing<commit_after>﻿///<reference path="../src/Dexie.js" />

(function(){
    var db = new Dexie("TestDB");
    db.version(1).stores({ users: "++id,first,last,&username,*&email,*pets" });

    //db.users.mapToClass(User);
    var User = db.users.defineClass({
        id:         Number,
        first:      String,
        last:       String,
        username:   String,
        email:      [String],
        pets:       [String],
    });

    db.on("populate", function (trans) {
        db.users.add({first: "David", last: "Fahlander", username: "dfahlander", email: ["<EMAIL>", "<EMAIL>"], pets: ["dog"]});
        db.users.add({first: "Karl", last: "Faadersköld", username: "kceder", email: ["<EMAIL>", "<EMAIL>"], pets: []});
    });

    module("table", {
        setup: function () {
            stop();
            db.delete().then(function () {
                db.open();
                start();
            }).catch(function (e) {
                ok(false, "Error deleting database: " + e);
                start();
            });
        },
        teardown: function () {
            stop(); db.delete().finally(start);
        }
    });

    asyncTest("get", 4, function () {
        db.table("users").get(1).then(function(obj) {
            equal(obj.first, "David", "Got the first object");
            return db.users.get(2);
        }).then(function(obj) {
            equal(obj.first, "Karl", "Got the second object");
            return db.users.get(100);
        }).then(function(obj) {
            ok(true, "Got then() even when getting non-existing object");
            equal(obj, undefined, "Result is 'undefined' when not existing");
        }).catch(function(err) {
            ok(false, "Error: " + err);
        }).finally(start);
    });

    asyncTest("where", function () {
        db.transaction("r", db.users, function () {
            db.users.where("username").equals("kceder").first(function (user) {
                equal(user.first, "Karl", "where().equals()");
            }),
            db.users.where("id").above(1).toArray(function (a) {
                ok(a.length == 1, "where().above()");
            }),
{'fraction_non_alphanumeric': 0.19221861973135712, 'fraction_numerical': 0.0041685965724872626, 'mean_word_length': 1.8470665787738958, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4470256', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1263, 'n_words': 256}