lloyd / JSONSelect

CSS-like selectors for JSON
http://jsonselect.org
ISC License
1.59k stars 116 forks source link

test_lex.html for '.' fails #44

Open gregglind opened 11 years ago

gregglind commented 11 years ago

Which part of the regex is this supposed to match?

Failed example: JSONSelect._lex("."); Expected: [1, "."]

gregglind commented 11 years ago

Failed example:
    JSONSelect._lex(".");
Expected:
    [1, "."]

Got:
    (nothing)
Failed example:
    JSONSelect._lex('\"not terminated');
Expected:
    Error: unclosed json string
Got:
    Error: unclosed json string in '"not terminated'

Failed example:
    JSONSelect._lex('"invalid escape: \\y"');
Expected:
    Error: invalid json string

Got:
    Error: invalid json string in 'JSON.parse: bad escaped character'

Failed example:
    JSONSelect._lex("foo");
Expected:
    [3, 4, "foo"]
Got:
    (nothing)
Failed example:
    JSONSelect._lex("foo\\ bar");
Expected:
    [8, 4, "foo bar"]
Got:
    (nothing)
Failed example:
    JSONSelect._lex("_aB129bcde-\\:foo\\@$");
Expected:
    [18, 4, "_aB129bcde-:foo@"]

Got:
    (nothing)
Failed example:
    JSONSelect._lex("обичам\\ те\\!");
Expected:
    [12, 4, "обичам те!"]

Got:
    (nothing)
28 tests in 0 items.
21 tests of 28 passed, 7 failed.

Tests of the JSONSelect lexer
Simple tokens

$ JSONSelect._lex(">");
[1, ">"]
$ JSONSelect._lex("*");
[1, "*"]
$ JSONSelect._lex(",");
[1, ","]
$ JSONSelect._lex(".");
[1, "."]

Actual output:

Offsets

$ JSONSelect._lex("foobar>",6);
[7, ">"]

Types

$ JSONSelect._lex("string");
[6, 3, "string"]
$ JSONSelect._lex("boolean");
[7, 3, "boolean"]
$ JSONSelect._lex("null");
[4, 3, "null"]
$ JSONSelect._lex("array");
[5, 3, "array"]
$ JSONSelect._lex("object");
[6, 3, "object"]
$ JSONSelect._lex("number");
[6, 3, "number"]

Whitespace

$ JSONSelect._lex("\r");
[1, " "]
$ JSONSelect._lex("\n");
[1, " "]
$ JSONSelect._lex("\t");
[1, " "]
$ JSONSelect._lex(" ");
[1, " "]
$ JSONSelect._lex("     \t   \r\n  !");
[13, " "]

pseudo classes

$ JSONSelect._lex(":root");
[5, 1, ":root"]
$ JSONSelect._lex(":first-child");
[12, 1, ":first-child"]
$ JSONSelect._lex(":last-child");
[11, 1, ":last-child"]
$ JSONSelect._lex(":only-child");
[11, 1, ":only-child"]

json strings

$ JSONSelect._lex('"foo bar baz"');
[13, 4, "foo bar baz"]
$ JSONSelect._lex('"\\u0020"');
[8, 4, " "]
$ JSONSelect._lex('\"not terminated');
Error: unclosed json string
Actual output:
Error: unclosed json string in '"not terminated'
$ JSONSelect._lex('"invalid escape: \\y"');
Error: invalid json string

Actual output:
Error: invalid json string in 'JSON.parse: bad escaped character'

identifiers (like after '.')

$ JSONSelect._lex("foo");
[3, 4, "foo"]
Actual output:
$ JSONSelect._lex("foo\\ bar");
[8, 4, "foo bar"]
Actual output:
$ JSONSelect._lex("_aB129bcde-\\:foo\\@$");
[18, 4, "_aB129bcde-:foo@"]

Actual output:

non-ascii

$ JSONSelect._lex("обичам\\ те\\!");
[12, 4, "обичам те!"]

Actual output: