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
Copy file name to clipboardExpand all lines: TEST_FORMAT.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,21 @@ A test case should be a JSON object with the following fields:
9
9
-**`description`***(string, required)*: A short, human-readable description of the test case that explains its purpose.
10
10
-**`rule`***(any, required)*: The JSON Logic rule to be tested.
11
11
-**`data`***(any, required)*: The input data that the rule will evaluate against.
12
+
13
+
And either:
14
+
12
15
-**`result`***(any, required)*: The expected result after evaluating the rule with the provided data.
13
16
17
+
OR
18
+
19
+
-**`error`***(Partial\<Error\>, required)* - Communicates that it is expected that the logic will fail due to a hard error. This object must partial match against the error emitted.
20
+
14
21
`any` refers to any valid [RFC8259](https://datatracker.ietf.org/doc/html/rfc8259) value.
15
22
16
23
`string` refers to [strings in RFC8259](https://datatracker.ietf.org/doc/html/rfc8259#section-7).
17
24
25
+
`Error`, at this time, is defined as a JSON Object with a `type` property, defined as a string (e.g. `{ "type": "NaN" }`).
26
+
18
27
The test cases are stored as an array of these objects, allowing for multiple tests in a single file.
19
28
20
29
## Example Test Cases
@@ -74,6 +83,25 @@ Below are examples demonstrating how to format JSON Logic test cases:
74
83
]
75
84
```
76
85
86
+
### Error Logic Test
87
+
88
+
```json
89
+
[
90
+
{
91
+
"description": "Checks if division by zero fails",
92
+
"rule": { "/": [0, 0] },
93
+
"error": { "type": "NaN" },
94
+
"data": null
95
+
},
96
+
{
97
+
"description": "Checks if throw can be embedded in another operator",
98
+
"rule": { "+": [1, { "throw": "Some error" }] },
99
+
"error": { "type": "Some error" },
100
+
"data": null
101
+
}
102
+
]
103
+
```
104
+
77
105
## Commentary and Section Headers
78
106
79
107
Strings in the root array will be ignored by the JSON Logic test processor. This allows you to add comments or declare section headers to provide human-readable information in your test-suite.
0 commit comments