mtcute/packages/core/tests/lru-map.spec.ts
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00

45 lines
1.4 KiB
TypeScript

import { expect } from 'chai'
import { describe, it } from 'mocha'
import { LruMap } from '../utils.js'
describe('LruMap', () => {
it('Map backend', () => {
const lru = new LruMap<string, number>(2)
lru.set('first', 1)
expect(lru.has('first')).true
expect(lru.has('second')).false
expect(lru.get('first')).eq(1)
lru.set('first', 42)
expect(lru.has('first')).true
expect(lru.has('second')).false
expect(lru.get('first')).eq(42)
lru.set('second', 2)
expect(lru.has('first')).true
expect(lru.has('second')).true
expect(lru.get('first')).eq(42)
expect(lru.get('second')).eq(2)
lru.set('third', 3)
expect(lru.has('first')).false
expect(lru.has('second')).true
expect(lru.has('third')).true
expect(lru.get('first')).eq(undefined)
expect(lru.get('second')).eq(2)
expect(lru.get('third')).eq(3)
lru.get('second') // update lru so that last = third
lru.set('fourth', 4)
expect(lru.has('first')).false
expect(lru.has('second')).true
expect(lru.has('third')).false
expect(lru.has('fourth')).true
expect(lru.get('first')).eq(undefined)
expect(lru.get('second')).eq(2)
expect(lru.get('third')).eq(undefined)
expect(lru.get('fourth')).eq(4)
})
})