summaryrefslogtreecommitdiff
path: root/tests/draft-next/if-then-else.json
blob: 70576c42e7032738f47db792521b9b0c4f07cd00 (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
[
    {
        "description": "ignore if without then or else",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "if": {
                "const": 0
            }
        },
        "tests": [
            {
                "description": "valid when valid against lone if",
                "data": 0,
                "valid": true
            },
            {
                "description": "valid when invalid against lone if",
                "data": "hello",
                "valid": true
            }
        ]
    },
    {
        "description": "ignore then without if",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "then": {
                "const": 0
            }
        },
        "tests": [
            {
                "description": "valid when valid against lone then",
                "data": 0,
                "valid": true
            },
            {
                "description": "valid when invalid against lone then",
                "data": "hello",
                "valid": true
            }
        ]
    },
    {
        "description": "ignore else without if",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "else": {
                "const": 0
            }
        },
        "tests": [
            {
                "description": "valid when valid against lone else",
                "data": 0,
                "valid": true
            },
            {
                "description": "valid when invalid against lone else",
                "data": "hello",
                "valid": true
            }
        ]
    },
    {
        "description": "if and then without else",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "if": {
                "exclusiveMaximum": 0
            },
            "then": {
                "minimum": -10
            }
        },
        "tests": [
            {
                "description": "valid through then",
                "data": -1,
                "valid": true
            },
            {
                "description": "invalid through then",
                "data": -100,
                "valid": false
            },
            {
                "description": "valid when if test fails",
                "data": 3,
                "valid": true
            }
        ]
    },
    {
        "description": "if and else without then",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "if": {
                "exclusiveMaximum": 0
            },
            "else": {
                "multipleOf": 2
            }
        },
        "tests": [
            {
                "description": "valid when if test passes",
                "data": -1,
                "valid": true
            },
            {
                "description": "valid through else",
                "data": 4,
                "valid": true
            },
            {
                "description": "invalid through else",
                "data": 3,
                "valid": false
            }
        ]
    },
    {
        "description": "validate against correct branch, then vs else",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "if": {
                "exclusiveMaximum": 0
            },
            "then": {
                "minimum": -10
            },
            "else": {
                "multipleOf": 2
            }
        },
        "tests": [
            {
                "description": "valid through then",
                "data": -1,
                "valid": true
            },
            {
                "description": "invalid through then",
                "data": -100,
                "valid": false
            },
            {
                "description": "valid through else",
                "data": 4,
                "valid": true
            },
            {
                "description": "invalid through else",
                "data": 3,
                "valid": false
            }
        ]
    },
    {
        "description": "non-interference across combined schemas",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "allOf": [
                {
                    "if": {
                        "exclusiveMaximum": 0
                    }
                },
                {
                    "then": {
                        "minimum": -10
                    }
                },
                {
                    "else": {
                        "multipleOf": 2
                    }
                }
            ]
        },
        "tests": [
            {
                "description": "valid, but would have been invalid through then",
                "data": -100,
                "valid": true
            },
            {
                "description": "valid, but would have been invalid through else",
                "data": 3,
                "valid": true
            }
        ]
    },
    {
        "description": "if with boolean schema true",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "if": true,
            "then": { "const": "then" },
            "else": { "const": "else" }
        },
        "tests": [
            {
                "description": "boolean schema true in if always chooses the then path (valid)",
                "data": "then",
                "valid": true
            },
            {
                "description": "boolean schema true in if always chooses the then path (invalid)",
                "data": "else",
                "valid": false
            }
        ]
    },
    {
        "description": "if with boolean schema false",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "if": false,
            "then": { "const": "then" },
            "else": { "const": "else" }
        },
        "tests": [
            {
                "description": "boolean schema false in if always chooses the else path (invalid)",
                "data": "then",
                "valid": false
            },
            {
                "description": "boolean schema false in if always chooses the else path (valid)",
                "data": "else",
                "valid": true
            }
        ]
    },
    {
        "description": "if appears at the end when serialized (keyword processing sequence)",
        "schema": {
            "$schema": "https://json-schema.org/draft/next/schema",
            "then": { "const": "yes" },
            "else": { "const": "other" },
            "if": { "maxLength": 4 }
        },
        "tests": [
            {
                "description": "yes redirects to then and passes",
                "data": "yes",
                "valid": true
            },
            {
                "description": "other redirects to else and passes",
                "data": "other",
                "valid": true
            },
            {
                "description": "no redirects to then and fails",
                "data": "no",
                "valid": false
            },
            {
                "description": "invalid redirects to else and fails",
                "data": "invalid",
                "valid": false
            }
        ]
    }
]