2021-03-29 21:34:33 +03:00
|
|
|
import { assert } from "chai";
|
2021-04-12 11:48:06 +03:00
|
|
|
import "../src/polyfill.js";
|
|
|
|
import * as kv from "../src/kv.js";
|
|
|
|
import * as conv from "../src/converters.js";
|
2021-03-29 21:34:33 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
// clear KV before each test
|
|
|
|
for (const prop of Object.getOwnPropertyNames(kv.rawKv)) {
|
|
|
|
delete kv.rawKv[prop];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("typedKv", function () {
|
|
|
|
it("basic", function () {
|
|
|
|
const foo = kv.typedKv("foo", conv.string, conv.uint16);
|
|
|
|
const key = "bar";
|
|
|
|
const val = 65535;
|
|
|
|
assert.equal(foo.get(key), undefined);
|
|
|
|
foo.set(key, val);
|
|
|
|
assert.equal(foo.get(key), val);
|
|
|
|
assert.isTrue(foo.has(key));
|
|
|
|
let found = false;
|
|
|
|
foo.forEach((v, k) => {
|
|
|
|
if (k == key && v == val) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert.isTrue(found);
|
|
|
|
foo.delete(key);
|
|
|
|
assert.isNotTrue(foo.has(key));
|
|
|
|
assert.equal(foo.get(key), undefined);
|
|
|
|
});
|
|
|
|
});
|