From 0f705b3bd35c6cf83bccde9a36c2aba57a03769e Mon Sep 17 00:00:00 2001 From: Markus Felten Date: Thu, 22 Jun 2023 13:02:03 +0100 Subject: [PATCH] fix: detect some more tokens --- src/attribute.mjs | 4 +++- tests/attribute-ava.mjs | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/attribute.mjs b/src/attribute.mjs index 8229d75d..cffd0f18 100644 --- a/src/attribute.mjs +++ b/src/attribute.mjs @@ -53,9 +53,11 @@ export function* tokens(string) { break; } + case ".": case "+": case "-": - case ".": + case "*": + case "/": case "(": case ")": case "[": diff --git a/tests/attribute-ava.mjs b/tests/attribute-ava.mjs index 1212f871..051f8013 100644 --- a/tests/attribute-ava.mjs +++ b/tests/attribute-ava.mjs @@ -8,6 +8,17 @@ import { optionJSON, MultiGroupProvider } from "repository-provider"; +import { tokens } from "../src/attribute.mjs"; + +function tt(t, source, expected) { + t.deepEqual(expected, [...tokens(source)]); +} + +tt.title = (providedTitle = "", source, expected) => + `tokenize ${providedTitle}${source} -> ${expected.join(" ")}`.trim(); + +test(tt, "a1 .b.c[3 + 4 ]", ["a1", ".", "b", ".", "c", "[", "3", "+", "4", "]"]); +test(tt, "=<=>=!=+-*/", ["=", "<=", ">=", "!=", "+", "-", "*", "/"]); function gat(t, object, key, expected) { const value = getAttribute(object, key); @@ -198,6 +209,6 @@ test( { id: 1, isAdmin: false, - name: "a", + name: "a" } );