From 438e2fbc2e08bc8bba952e6f790848b6c7962de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 11 Jun 2019 10:32:00 +0200 Subject: [PATCH] [FIX] qweb: add some missing operators closes #162 --- src/qweb_expressions.ts | 4 ++-- tests/qweb_expressions.test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/qweb_expressions.ts b/src/qweb_expressions.ts index 1c15ead6..28a030ab 100644 --- a/src/qweb_expressions.ts +++ b/src/qweb_expressions.ts @@ -82,7 +82,7 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = { ")": "RIGHT_PAREN" }; -const OPERATORS = [".", "===", "==", "+", "!", "||", "&&", ">", "?", "-", "*"]; +const OPERATORS = ".,===,==,+,!,||,&&,>=,>,<=,<,?,-,*,/,%".split(','); type Tokenizer = (expr: string) => Token | false; @@ -201,7 +201,7 @@ export function tokenize(expr: string): Token[] { } } if (expr.length) { - throw new Error("Tokenizer error..."); + throw new Error(`Tokenizer error: could not tokenize "${expr}"`); } return result; } diff --git a/tests/qweb_expressions.test.ts b/tests/qweb_expressions.test.ts index 2255c4a2..3a3eb714 100644 --- a/tests/qweb_expressions.test.ts +++ b/tests/qweb_expressions.test.ts @@ -39,6 +39,15 @@ describe("tokenizer", () => { ]); }); + test("various operators", () => { + expect(tokenize(">= <= < >")).toEqual([ + { type: "OPERATOR", value: ">=" }, + { type: "OPERATOR", value: "<=" }, + { type: "OPERATOR", value: "<" }, + { type: "OPERATOR", value: ">" }, + ]); + }); + test("strings", () => { expect(() => tokenize("'")).toThrow("Invalid expression"); expect(() => tokenize("'\\")).toThrow("Invalid expression");