You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 15, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+22-26Lines changed: 22 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,25 +73,12 @@ FROM
73
73
{
74
74
"statement": [
75
75
{
76
-
"explain": false,
77
76
"type": "statement",
78
77
"variant": "select",
79
-
"from": [
80
-
{
81
-
"type": "identifier",
82
-
"variant": "table",
83
-
"name": "beehive",
84
-
"alias": null,
85
-
"index": null
86
-
}
87
-
],
88
-
"where": null,
89
-
"group": null,
90
78
"result": [
91
79
{
92
80
"type": "function",
93
81
"name": "min",
94
-
"distinct": false,
95
82
"args": [
96
83
{
97
84
"type": "identifier",
@@ -104,7 +91,6 @@ FROM
104
91
{
105
92
"type": "function",
106
93
"name": "max",
107
-
"distinct": false,
108
94
"args": [
109
95
{
110
96
"type": "identifier",
@@ -115,11 +101,13 @@ FROM
115
101
"alias": "Max Honey"
116
102
}
117
103
],
118
-
"distinct": false,
119
-
"all": false,
120
-
"order": null,
121
-
"limit": null,
122
-
"with": null
104
+
"from": [
105
+
{
106
+
"type": "identifier",
107
+
"variant": "table",
108
+
"name": "beehive"
109
+
}
110
+
]
123
111
}
124
112
]
125
113
}
@@ -131,7 +119,7 @@ Once the dependencies are installed, start development with the following comman
131
119
132
120
`grunt test`
133
121
134
-
which will automatically compile the parser and run the tests in `test/index-spec.js`.
122
+
which will automatically compile the parser and run the tests in `test/core/**/*-spec.js`.
135
123
136
124
Optionally, run `grunt debug` to get extended output and start a file watcher.
137
125
@@ -141,24 +129,32 @@ and rebuild the `dist/` and `demo/` folders.
141
129
### Writing tests
142
130
143
131
Tests refer to a SQL test file in `test/sql/` and the test name is a
144
-
reference to the filename of the test file. For example `super test 2`
145
-
as a test name points to the file `test/sql/superTest2.sql`.
132
+
reference to the filename of the test file. For example `super test 2` as a test name in an `it()` block within a `describe()` block with title `parent block` points to the file `test/sql/parent-block/super-test2.sql`.
133
+
134
+
The expected AST that should be generated from `super-test-2.sql` should
135
+
be located in a JSON file in the following location:
136
+
`test/json/super-test2.json`.
146
137
147
138
There are three options for the test helpers exposed by `tree`:
148
139
-`tree.ok(this, done)` to assert that the test file successfully generates an AST
149
-
-`tree.equals(ast, this, done)` to assert that the test file generates an AST that exactly matches `ast`
140
+
-`tree.equals(this, done)` to assert that the test file generates an AST that exactly matches the expected output JSON file
150
141
-`tree.error()` to assert that a test throws an error
151
142
-`tree.error("This is the error message", this, done)` assert an error `message`
152
143
-`tree.error({'line': 2}, this, done)` assert an object of properties that each exist in the error
153
144
145
+
Use `grunt rewrite-json` generate new JSON files for each of the specs in
146
+
`test/core/**/*-spec.js` and save them in `test/json/`. Example:
147
+
the AST for `test/sql/parent-block/it-block.sql` will be re-parsed and the
148
+
results will overwrite the existing `json/parent block/it-block.json` file.
var resultTree ='{"statement":[{"explain":false,"type":"statement","variant":"select","from":[{"type":"identifier","variant":"table","name":"bananas","alias":null,"index":null}],"where":[{"type":"expression","format":"binary","variant":"operation","operation":"=","left":{"type":"identifier","variant":"column","name":"color"},"right":{"type":"literal","variant":"string","value":"red"}}],"group":null,"result":[{"type":"identifier","variant":"star","name":"*"}],"distinct":false,"all":false,"order":null,"limit":null}]}';
0 commit comments