deno.land / x / replicache@v10.0.0-beta.0 / hash.test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {expect} from '@esm-bundle/chai';import { assertNotTempHash, emptyHash, isHash, isTempHash, hashOf, newTempHash, parse,} from './hash';import type {ReadonlyJSONValue} from './json';
test('test of', async () => { const h = await hashOf('abc'); expect(h).to.not.equal(emptyHash);});
test('test native of', async () => { const h = await hashOf('abc'); expect(h).to.not.equal(emptyHash);
const testData = ['abc', '', '\u0000', 'abc', '💩'];
for (const s of testData) { const hash = await hashOf(s); const nativeHash = await hashOf(s); expect(hash).to.equal(nativeHash); }});
test('isHash', async () => { expect(isHash(emptyHash)).to.be.true;
const h = await hashOf('abc'); expect(isHash(h)).to.be.true; expect(isHash(h + 'a')).to.be.false; expect(isHash(String(h).slice(0, -1))).to.be.false;});
test('parse', async () => { const h = await hashOf('abc'); expect(parse(String(emptyHash))).to.equal(emptyHash); expect(parse(String(h))).to.equal(h); expect(() => parse(h + 'a')).to.throw(Error); expect(() => parse(String(h).slice(0, -1))).to.throw(Error);});
test('temp hash', async () => { const t = newTempHash(); const c = {hash: await hashOf('dummy')}; expect(String(t).length, 'temp hash length').to.equal(String(c.hash).length); expect(isTempHash(t)).to.equal(true); expect(isTempHash(c.hash)).to.equal(false);
expect(() => assertNotTempHash(t)).to.throw();});
test.skip('type checking only', async () => { const h = await hashOf('abc'); // @ts-expect-error Should be an error const s: string = h; console.log(s);
// @ts-expect-error Sould be an error const h2: Hash = 'abc'; console.log(h2);});
test('hashOf with different types', async () => { const t = async (v: ReadonlyJSONValue) => expect(isHash(await hashOf(v))).to.be.true;
await t(1); await t(1.1); await t(true); await t(false); await t(null); await t(''); await t('a'); await t('abc'); await t('abc\u0000'); await t([]); await t([1, 2, 3]); await t({}); await t({a: 1, b: 2});});
replicache

Version Info

Tagged at
2 years ago