narrow type
This commit is contained in:
parent
354df33894
commit
b42675e1d9
|
|
@ -3,7 +3,7 @@ import { parser } from '#parser/shrimp'
|
|||
import { $ } from 'bun'
|
||||
import { assert, errorMessage } from '#utils/utils'
|
||||
import { Compiler } from '#compiler/compiler'
|
||||
import { run, VM } from 'reefvm'
|
||||
import { run, VM, type TypeScriptFunction } from 'reefvm'
|
||||
import { treeToString, VMResultToValue } from '#utils/tree'
|
||||
|
||||
const regenerateParser = async () => {
|
||||
|
|
@ -33,7 +33,7 @@ declare module 'bun:test' {
|
|||
toMatchTree(expected: string): T
|
||||
toMatchExpression(expected: string): T
|
||||
toFailParse(): T
|
||||
toEvaluateTo(expected: unknown, nativeFunctions?: Record<string, Function>): Promise<T>
|
||||
toEvaluateTo(expected: unknown, globalFunctions?: Record<string, TypeScriptFunction>): Promise<T>
|
||||
toFailEvaluation(): Promise<T>
|
||||
}
|
||||
}
|
||||
|
|
@ -96,13 +96,13 @@ expect.extend({
|
|||
async toEvaluateTo(
|
||||
received: unknown,
|
||||
expected: unknown,
|
||||
nativeFunctions: Record<string, Function> = {}
|
||||
globalFunctions: Record<string, TypeScriptFunction> = {}
|
||||
) {
|
||||
assert(typeof received === 'string', 'toEvaluateTo can only be used with string values')
|
||||
|
||||
try {
|
||||
const compiler = new Compiler(received)
|
||||
const result = await run(compiler.bytecode, nativeFunctions)
|
||||
const result = await run(compiler.bytecode, globalFunctions)
|
||||
let value = VMResultToValue(result)
|
||||
|
||||
// Just treat regex as strings for comparison purposes
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user