Improve TwingLexer test

This commit is contained in:
Eric MORAND 2024-04-17 12:30:47 +00:00
parent 4e24952608
commit 0f3064d17b
3 changed files with 7 additions and 7 deletions

View File

@ -22,7 +22,7 @@ import {createSourceMapRuntime} from "./source-map-runtime";
import {createSandboxSecurityPolicy, TwingSandboxSecurityPolicy} from "./sandbox/security-policy";
import {TwingTemplate} from "./template";
import {Settings as DateTimeSettings} from "luxon";
import {createLexer, TwingLexer} from "./lexer";
import {createLexer, type TwingLexer} from "./lexer";
import {TwingCache} from "./cache";
import {createCoreExtension} from "./extension/core";
import {createAutoEscapeNode, createTemplateLoadingError, type TwingContext} from "../lib";
@ -102,7 +102,7 @@ export interface TwingEnvironment {
* @param name The name of the template to load
* @param from The name of the template that requested the load
*
* @throws {TwingTemplateLoadingError} When the template cannot be found
* @throws {Error} When the template cannot be found
* @throws {TwingParsingError} When an error occurred during the parsing of the source
*
* @return

View File

@ -85,11 +85,11 @@ export const createLexer = (
binaryOperators: Array<TwingOperator>,
unaryOperators: Array<TwingOperator>
): TwingLexer => {
const keepCompatibleOperators = (operator: TwingOperator) => operator.specificationLevel <= level;
const keepCompatibleOperator = (operator: TwingOperator) => operator.specificationLevel <= level;
return new TwingLexer(
level,
binaryOperators.filter(keepCompatibleOperators),
unaryOperators.filter(keepCompatibleOperators)
binaryOperators.filter(keepCompatibleOperator),
unaryOperators.filter(keepCompatibleOperator)
);
};

View File

@ -1,11 +1,11 @@
import * as tape from 'tape';
import {TwingLexer, typeToEnglish} from "../../../../../main/lib/lexer";
import {createLexer, typeToEnglish} from "../../../../../main/lib/lexer";
import {createOperator} from "../../../../../main/lib/operator";
tape('lexer', (test) => {
test.test('constructor', (test) => {
test.test('support custom operators', (test) => {
let lexer = new TwingLexer(
let lexer = createLexer(
2,
[
createOperator('foo', "BINARY", 0, () => {