File size: 2,352 Bytes
4cadbaf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html>
  <head>
    <title>JSONSelect JS lex tests</title>
    <link rel="stylesheet" type="text/css" href="js/doctest.css" />
    <script src="js/doctest.js"></script>
    <script src="../jsonselect.js"></script>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  </head>
  <body>

<div>
  <button onclick="doctest()" type="button">run tests</button>
  <pre id="doctestOutput"></pre>
</div>

    <h2> Tests of the JSONSelect lexer </h2>

<div class="test">
Simple tokens
<pre class="doctest">
$ JSONSelect._lex(">");
[1, ">"]
$ JSONSelect._lex("*");
[1, "*"]
$ JSONSelect._lex(",");
[1, ","]
$ JSONSelect._lex(".");
[1, "."]
</pre>
</div>

<div class="test">
Offsets
<pre class="doctest">
$ JSONSelect._lex("foobar>",6);
[7, ">"]
</pre>
</div>

<div class="test">
Types
<pre class="doctest">
$ 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"]
</pre>
</div>

<div class="test">
Whitespace
<pre class="doctest">
$ JSONSelect._lex("\r");
[1, " "]
$ JSONSelect._lex("\n");
[1, " "]
$ JSONSelect._lex("\t");
[1, " "]
$ JSONSelect._lex(" ");
[1, " "]
$ JSONSelect._lex("     \t   \r\n  !");
[13, " "]
</pre>

<div class="test">
pseudo classes
<pre class="doctest">
$ 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"]
</pre>
</div>

<div class="test">
json strings
<pre class="doctest">
$ JSONSelect._lex('"foo bar baz"');
[13, 4, "foo bar baz"]
$ JSONSelect._lex('"\\u0020"');
[8, 4, " "]
$ JSONSelect._lex('\"not terminated');
Error: unclosed json string
$ JSONSelect._lex('"invalid escape: \\y"');
Error: invalid json string
</pre>
</div>

<div class="test">
identifiers (like after '.')
<pre class="doctest">
$ JSONSelect._lex("foo");
[3, 4, "foo"]
$ JSONSelect._lex("foo\\ bar");
[8, 4, "foo bar"]
$ JSONSelect._lex("_aB129bcde-\\:foo\\@$");
[18, 4, "_aB129bcde-:foo@"]
</pre>
</div>

<div class="test">
non-ascii
<pre class="doctest">
$ JSONSelect._lex("обичам\\ те\\!");
[12, 4, "обичам те!"]
</pre>
</div>

  </body>
</html>