probably using list.sort is okay?

This commit is contained in:
Chris Wanstrath 2025-11-06 21:39:51 -08:00
parent 3ac606d0b2
commit afaedeea23

View File

@ -454,31 +454,11 @@ describe('enumerables', () => {
describe('dict operations', () => { describe('dict operations', () => {
test('dict.keys returns all keys', async () => { test('dict.keys returns all keys', async () => {
const result = await (async () => { await expect(`dict.keys [a=1 b=2 c=3] | list.sort`).toEvaluateTo(['a', 'b', 'c'].sort())
const { Compiler } = await import('#compiler/compiler')
const { run, fromValue } = await import('reefvm')
const { setGlobals } = await import('#parser/tokenizer')
setGlobals(Object.keys(globals))
const c = new Compiler('dict.keys [a=1 b=2 c=3]')
const r = await run(c.bytecode)
return fromValue(r)
})()
// Check that all expected keys are present (order may vary)
expect(result.sort()).toEqual(['a', 'b', 'c'])
}) })
test('dict.values returns all values', async () => { test('dict.values returns all values', async () => {
const result = await (async () => { await expect('dict.values [a=1 b=2] | list.sort').toEvaluateTo([1, 2].sort())
const { Compiler } = await import('#compiler/compiler')
const { run, fromValue } = await import('reefvm')
const { setGlobals } = await import('#parser/tokenizer')
setGlobals(Object.keys(globals))
const c = new Compiler('dict.values [a=1 b=2]')
const r = await run(c.bytecode)
return fromValue(r)
})()
// Check that all expected values are present (order may vary)
expect(result.sort()).toEqual([1, 2])
}) })
test('dict.has? checks for key', async () => { test('dict.has? checks for key', async () => {
@ -489,6 +469,7 @@ describe('dict operations', () => {
test('dict.get retrieves value with default', async () => { test('dict.get retrieves value with default', async () => {
await expect(`dict.get [a=1] 'a' 0`).toEvaluateTo(1) await expect(`dict.get [a=1] 'a' 0`).toEvaluateTo(1)
await expect(`dict.get [a=1] 'b' 99`).toEvaluateTo(99) await expect(`dict.get [a=1] 'b' 99`).toEvaluateTo(99)
await expect(`dict.get [a=1] 'b'`).toEvaluateTo(null)
}) })
test('dict.set sets value', async () => { test('dict.set sets value', async () => {