Skip to main content
Module

x/pazza/examples/context_management.test.ts

Parser combinators library designed for Deno, but also works on browsers and Node.js.
Go to Latest
File
import { assertEquals, assertNotStrictEquals,} from "https://deno.land/std@0.70.0/testing/asserts.ts";import { Context, contextedParserWithImmer, contextedParserWithUnistore, parserContext, createUnistoreContext,} from "./context_management.ts";
const text = "[1,2,2,4,6,3,6,3,9,3,2,3,7,5,3]";
Deno.test("contextManagement", () => { const context: Context = { "0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0, };
const result1 = contextedParserWithImmer()(text, parserContext); assertNotStrictEquals(result1.context, context); assertEquals(result1, { ok: true, input: "", output: [ "1", "2", "2", "4", "6", "3", "6", "3", "9", "3", "2", "3", "7", "5", "3", ], context: { "0": 0, "1": 1, "2": 3, "3": 5, "4": 1, "5": 1, "6": 2, "7": 1, "8": 0, "9": 1, }, });
const result2 = contextedParserWithUnistore()(text, createUnistoreContext()); assertNotStrictEquals(result2.context.getState(), context); assertEquals({ ...result2, context: result2.context.getState() }, { ok: true, input: "", output: [ "1", "2", "2", "4", "6", "3", "6", "3", "9", "3", "2", "3", "7", "5", "3", ], context: { "0": 0, "1": 1, "2": 3, "3": 5, "4": 1, "5": 1, "6": 2, "7": 1, "8": 0, "9": 1, }, });});