[FIX] qweb: add some missing operators

closes #162
This commit is contained in:
Géry Debongnie
2019-06-11 10:32:00 +02:00
parent b3db085745
commit 438e2fbc2e
2 changed files with 11 additions and 2 deletions
+2 -2
View File
@@ -82,7 +82,7 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = {
")": "RIGHT_PAREN" ")": "RIGHT_PAREN"
}; };
const OPERATORS = [".", "===", "==", "+", "!", "||", "&&", ">", "?", "-", "*"]; const OPERATORS = ".,===,==,+,!,||,&&,>=,>,<=,<,?,-,*,/,%".split(',');
type Tokenizer = (expr: string) => Token | false; type Tokenizer = (expr: string) => Token | false;
@@ -201,7 +201,7 @@ export function tokenize(expr: string): Token[] {
} }
} }
if (expr.length) { if (expr.length) {
throw new Error("Tokenizer error..."); throw new Error(`Tokenizer error: could not tokenize "${expr}"`);
} }
return result; return result;
} }
+9
View File
@@ -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", () => { test("strings", () => {
expect(() => tokenize("'")).toThrow("Invalid expression"); expect(() => tokenize("'")).toThrow("Invalid expression");
expect(() => tokenize("'\\")).toThrow("Invalid expression"); expect(() => tokenize("'\\")).toThrow("Invalid expression");