Skip to content

Commit cb28fdb

Browse files
committed
docs: document the Test Suite
1 parent 5664175 commit cb28fdb

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ On this page:
3434
External pages:
3535

3636
- [Function reference](reference/functions.md)
37+
- [Test Suite](test-suite/README.md)
3738

3839
## Installation
3940

@@ -623,7 +624,9 @@ Another gotcha is that unlike some other query languages, you need to use the `m
623624

624625
## Development
625626

626-
To develop, check out the repo, install dependencies once, and then use the following scripts:
627+
### JavaScript
628+
629+
To develop, check out the JavaScript repo, install dependencies once, and then use the following scripts:
627630

628631
```text
629632
npm run test
@@ -637,6 +640,12 @@ npm run build-and-test
637640

638641
Note that a new package is published on [npm](https://www.npmjs.com/package/@jsonquerylang/jsonquery) and [GitHub](https://github.com/jsonquerylang/jsonquery/releases) on changes pushed to the `main` branch. This is done using [`semantic-release`](https://github.com/semantic-release/semantic-release), and we do not use the `version` number in the `package.json` file. A changelog can be found by looking at the [releases on GitHub](https://github.com/jsonquerylang/jsonquery/releases).
639642

643+
### Implement in a new language
644+
645+
Support for JSON Query language can be implemented in new programming languages. Implementing the query engine is most straight forward: this boils down to implementing each of the functions (`sort`, `filter`, `groupBy`, etc.), and creating a compiler which can go through a JSON Query like `["sort", ["get", "name"], "desc"]` look up the function `sort`, and pass the arguments to it. Implementing a parser and stringifier is a bit more work, but the parser and stringifier of the JavaScript implementation can be used as a reference.
646+
647+
There is a JSON based Test Suite available that can be used to ensure that your implementation matches the behavior of the reference implementation, see: [Test Suite](test-suite/README.md).
648+
640649
## Motivation
641650

642651
There are many powerful query languages out there, so why the need to develop `jsonquery`? There are a couple of reasons for this.

test-suite/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# JSON Query Test Suite
2+
3+
This test suite contains the reference tests for the JSON Query language in a language agnostic JSON format. These tests can be used to implement JSON Query in a new programming language or environment.
4+
5+
The test-suite contains three sections:
6+
- [`compile.test.json`](./compile.test.json) tests verifying the behavior of the compiler, the query engine, i.e.:
7+
8+
```js
9+
import { compile } from '@jsonquerylang/jsonquery'
10+
11+
const queryIt = compile(["sort"])
12+
const result = queryIt([3, 1, 5])
13+
// result should be [1, 3, 5]
14+
```
15+
16+
- [`parse.test.json`](./parse.test.json) tests verifying the parser that parses the text format into the JSON format, i.e.:
17+
18+
```js
19+
import { parse } from '@jsonquerylang/jsonquery'
20+
21+
const query = parse('filter(.age > 65)')
22+
// query should be ["filter", ["gt", ["get", "age"], 65]]
23+
```
24+
25+
- [`stringify.test.json`](./stringify.test.json) tests converting the JSON format into the test format (including indentation), i.e.:
26+
27+
```js
28+
import { stringify } from '@jsonquerylang/jsonquery'
29+
30+
const text = stringify(["sort", ["get", "age"], "desc"])
31+
// text should be 'sort(.age, "desc")'
32+
```
33+
34+
The test suites are accompanied by a `.d.ts` file containing the TypeScript models of the test suites, and a `.schema.json` file containing a JSON schema file matching the test suites. These can be of help when implementing a model for the test suites in a new language.

0 commit comments

Comments
 (0)