9af7a2d122
* Password based agent implementation * tidy * tidy * wip * tidy * wip * tidy * wip * tests * tidy * websocket * tidy * tidy * tidy * tidy * tidy * tidy * tidy * tidy * changeset * codegen * tidy * tidy * tidy * tidy * tests * tidy * tidy * tests * tidy * tidy * tidy * wip * tidy * memoize * tidy * tests * tidy * files reorg * Ensure that default values match constraints * wip * use vitest to test lex * Add readme * fix lint * add vitest workspace config * vitest config * vitest-cfg * tests * ignore coverage * tidy
25 lines
911 B
TypeScript
25 lines
911 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { lexEquals } from '@atproto/lex-data'
|
|
import { jsonToLex, lexToJson } from '@atproto/lex-json'
|
|
import { cidForLex, decode, encode } from '../src/index.js'
|
|
import { vectors } from './vectors.js'
|
|
|
|
describe('lex', () => {
|
|
for (const vector of vectors) {
|
|
it(`passes test vector: ${vector.name}`, async () => {
|
|
const lex = jsonToLex(vector.json)
|
|
const json = lexToJson(lex)
|
|
const cbor = encode(lex)
|
|
const ipldAgain = decode(cbor)
|
|
const jsonAgain = lexToJson(ipldAgain)
|
|
const cid = await cidForLex(lex)
|
|
expect(json).toEqual(vector.json)
|
|
expect(jsonAgain).toEqual(vector.json)
|
|
expect(lexEquals(lex, vector.lex)).toBeTruthy()
|
|
expect(lexEquals(ipldAgain, vector.lex)).toBeTruthy()
|
|
expect(Buffer.compare(cbor, vector.cbor)).toBe(0)
|
|
expect(cid.toString()).toEqual(vector.cid)
|
|
})
|
|
}
|
|
})
|