Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 085d31f

Browse files
committed
Update README.md for next version. Refs #3
1 parent d5a0d71 commit 085d31f

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

README.md

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,12 @@ FROM
7373
{
7474
"statement": [
7575
{
76-
"explain": false,
7776
"type": "statement",
7877
"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,
9078
"result": [
9179
{
9280
"type": "function",
9381
"name": "min",
94-
"distinct": false,
9582
"args": [
9683
{
9784
"type": "identifier",
@@ -104,7 +91,6 @@ FROM
10491
{
10592
"type": "function",
10693
"name": "max",
107-
"distinct": false,
10894
"args": [
10995
{
11096
"type": "identifier",
@@ -115,11 +101,13 @@ FROM
115101
"alias": "Max Honey"
116102
}
117103
],
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+
]
123111
}
124112
]
125113
}
@@ -131,7 +119,7 @@ Once the dependencies are installed, start development with the following comman
131119

132120
`grunt test`
133121

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`.
135123

136124
Optionally, run `grunt debug` to get extended output and start a file watcher.
137125

@@ -141,24 +129,32 @@ and rebuild the `dist/` and `demo/` folders.
141129
### Writing tests
142130

143131
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`.
146137

147138
There are three options for the test helpers exposed by `tree`:
148139
- `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
150141
- `tree.error()` to assert that a test throws an error
151142
- `tree.error("This is the error message", this, done)` assert an error `message`
152143
- `tree.error({'line': 2}, this, done)` assert an object of properties that each exist in the error
153144

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.
149+
154150
``` javascript
155151
var tree = require('./helpers');
156152

157153
describe('sqlite-parser', function() {
158-
// uses: test/sql/basicSelect.sql
154+
// Test SQL: test/sql/select/basic-select.sql
155+
// Expected JSON: test/json/select/basic-select.json
159156
it('basic select', function(done) {
160-
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}]}';
161-
tree.equals(resultTree, this, done);
157+
tree.equals(this, done);
162158
});
163159

164160
// uses: test/sql/parseError1.sql

0 commit comments

Comments
 (0)