this repo has no description
at master 305 lines 5.0 kB view raw
1# generated from the original tests. 2# Henceforth it may be nicer to group tests into separate files. 3-- in.cue -- 4import "encoding/json" 5 6validate: [string]: { 7 str: string | *"{\"a\":10}" 8 schema: _ 9 result: json.Validate(str, schema) 10} 11validate: t1: schema: {b: string} 12validate: t2: schema: {a: <3} 13 14validate: disjunctionRequired: schema: {a!: int} | {b!: int} 15validate: disjunctionClosed: schema: close({a: int}) | close({b: int}) 16 17validate: invalidDisjuntion: schema: {a: 1 | 2} 18 19// Issue #2395 20validate: enforceRequired: { 21 str: "{}" 22 schema: {x!: int} 23} 24 25issue3932: { 26 f: json.Validate({name!: string}) 27 f: json.Marshal({name: "foo"}) 28} 29 30valid: [string]: { 31 string // input 32 #result: json.Valid(string) 33} 34valid: t1: "1" 35 36compact: [string]: X={ 37 _ // input 38 #result: json.Compact(X) 39} 40compact: t1: "[1, 2]" 41 42indent: [string]: X={ 43 string // input 44 #initial: *"" | string 45 #indent: *" " | string 46 #result: json.Indent(X, #initial, #indent) 47} 48indent: t1: #"{"a": 1, "b": 2}"# 49 50unmarshal: [string]: X={ 51 string // input 52 #result: json.Unmarshal(X) 53} 54unmarshal: t1: "1" 55unmarshal: { 56 trailingValid: #"{"a": 1}{"b": 2}"# 57 trailingInvalid: #"{"a": 1}}invalid json"# 58} 59 60marshalStream: [string]: X={ 61 [...] // input 62 #result: json.MarshalStream(X) 63} 64marshalStream: t1: [{a: 1}, {b: 2}] 65marshalStream: t2: [{a: 1}, {b: int | *2}] 66marshalStream: t3: [{a: #"\ " & < >"#}, {b: ""}] 67 68 69marshal: [string]: X={ 70 _ // input 71 #result: json.Marshal(X) 72} 73marshal: t1: { 74 #x: int 75 a: #x 76} 77 78marshal: t2: {a: #"\ " & < >"#} 79 80htmlEscape: [string]: X={ 81 string // input 82 #result: json.HTMLEscape(X) 83} 84htmlEscape: t1: marshal.t2.#result 85htmlEscape: t2: marshalStream.t3.#result 86 87unmarshalStream: [string]: X={ 88 string | bytes // input 89 #result: json.UnmarshalStream(X) 90} 91unmarshalStream: { 92 t1: #"{"a": 1}{"b": 2}"# 93 t2: #'{"a": 1}{"b": 2}'# 94 empty1: '' 95 empty2: "" 96 nums1: '1 2' 97 nums2: "1 2" 98} 99-- out/json -- 100Errors: 101validate.invalidDisjuntion.result: error in call to encoding/json.Validate: 2 errors in empty disjunction:: 102 ./in.cue:6:10 103validate.t2.result: error in call to encoding/json.Validate: invalid value 10 (out of bound <3): 104 ./in.cue:6:10 105 ./in.cue:9:27 106 json.Validate:1:6 107unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 108 ./in.cue:49:11 109unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 110 ./in.cue:49:11 111 112Result: 113import "encoding/json" 114 115validate: { 116 t1: { 117 str: *"{\"a\":10}" | string 118 schema: { 119 b: string 120 } 121 result: true 122 } 123 t2: { 124 str: *"{\"a\":10}" | string 125 schema: { 126 a: <3 127 } 128 result: _|_ // validate.t2.result: error in call to encoding/json.Validate: validate.t2.result.a: invalid value 10 (out of bound <3) 129 } 130 disjunctionRequired: { 131 str: *"{\"a\":10}" | string 132 schema: { 133 a!: int 134 } | { 135 b!: int 136 } 137 result: true 138 } 139 disjunctionClosed: { 140 str: *"{\"a\":10}" | string 141 schema: { 142 a: int 143 } | { 144 b: int 145 } 146 result: true 147 } 148 invalidDisjuntion: { 149 str: *"{\"a\":10}" | string 150 schema: { 151 a: 1 | 2 152 } 153 result: _|_ // validate.invalidDisjuntion.result: error in call to encoding/json.Validate: validate.invalidDisjuntion.result.a: 2 errors in empty disjunction: (and 2 more errors) 154 } 155 156 // Issue #2395 157 enforceRequired: { 158 str: "{}" 159 schema: { 160 x!: int 161 } 162 result: json.Validate(str, schema) 163 } 164} 165issue3932: { 166 f: "{\"name\":\"foo\"}" 167} 168valid: { 169 t1: { 170 "1" 171 #result: json.Valid(string) 172 } 173} 174compact: { 175 t1: { 176 "[1, 2]" 177 #result: "[1,2]" 178 } 179} 180indent: { 181 t1: { 182 "{\"a\": 1, \"b\": 2}" 183 #initial: *"" | string 184 #indent: *" " | string 185 #result: """ 186 { 187 "a": 1, 188 "b": 2 189 } 190 """ 191 } 192} 193unmarshal: { 194 t1: { 195 "1" 196 #result: 1 197 } 198 trailingValid: { 199 #result: _|_ // unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 200 } 201 trailingInvalid: { 202 #result: _|_ // unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 203 } 204} 205marshalStream: { 206 t1: { 207 #result: """ 208 {"a":1} 209 {"b":2} 210 211 """ 212 [{ 213 a: 1 214 }, { 215 b: 2 216 }] 217 } 218 t2: { 219 #result: """ 220 {"a":1} 221 {"b":2} 222 223 """ 224 [{ 225 a: 1 226 }, { 227 b: *2 | int 228 }] 229 } 230 t3: { 231 #result: """ 232 {"a":"\\\\ \\" & < >"} 233 {"b":""} 234 235 """ 236 [{ 237 a: "\\ \" & < >" 238 }, { 239 b: "" 240 }] 241 } 242} 243marshal: { 244 t1: { 245 #result: json.Marshal(X) 246 #x: int 247 a: int 248 } 249 t2: { 250 #result: "{\"a\":\"\\\\ \\\" & < >\"}" 251 a: "\\ \" & < >" 252 } 253} 254htmlEscape: { 255 t1: { 256 "{\"a\":\"\\\\ \\\" & < >\"}" 257 #result: "{\"a\":\"\\\\ \\\" \\u0026 \\u003c \\u003e\"}" 258 } 259 t2: { 260 """ 261 {"a":"\\\\ \\" & < >"} 262 {"b":""} 263 264 """ 265 #result: """ 266 {"a":"\\\\ \\" \\u0026 \\u003c \\u003e"} 267 {"b":""} 268 269 """ 270 } 271} 272unmarshalStream: { 273 t1: { 274 "{\"a\": 1}{\"b\": 2}" 275 #result: [{ 276 a: 1 277 }, { 278 b: 2 279 }] 280 } 281 t2: { 282 '{"a": 1}{"b": 2}' 283 #result: [{ 284 a: 1 285 }, { 286 b: 2 287 }] 288 } 289 empty1: { 290 '' 291 #result: [] 292 } 293 empty2: { 294 "" 295 #result: [] 296 } 297 nums1: { 298 '1 2' 299 #result: [1, 2] 300 } 301 nums2: { 302 "1 2" 303 #result: [1, 2] 304 } 305}