graph-ecs/tests/query/common.test.js

31 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-11-10 10:15:43 +01:00
import { describe, it } from 'node:test'
import assert from 'node:assert'
import { digit, many, parse, seq } from '../../src/parser.js'
import * as Common from '../../src/query/common.js'
describe('common parser library', () => {
it('literals should match literal types', () => {
const tBool = parse(Common.literal, 'true')
const fBool = parse(Common.literal, 'false')
const uint = parse(Common.literal, '5')
const posInt = parse(Common.literal, '+16')
const negInt = parse(Common.literal, '-710')
const ufloat = parse(Common.literal, '2.1')
const posFloat = parse(Common.literal, '+0.1')
const negFloat = parse(Common.literal, '-12.01')
const string = parse(Common.literal, '"akjsdfuaio"')
const v = r => r.value[0][0]
assert.strictEqual(v(tBool), true)
assert.strictEqual(v(fBool), false)
assert.strictEqual(v(uint), 5)
assert.strictEqual(v(posInt), 16)
assert.strictEqual(v(negInt), -710)
assert.strictEqual(v(ufloat), 2.1)
assert.strictEqual(v(posFloat), 0.1)
assert.strictEqual(v(negFloat), -12.01)
assert.strictEqual(v(string), 'akjsdfuaio')
})
})