github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/pkg/encoding/json/testdata/gen.txtar (about)

     1  # generated from the original tests.
     2  # Henceforth it may be nicer to group tests into separate files.
     3  -- in.cue --
     4  import "encoding/json"
     5  
     6  t1: json.Validate("{\"a\":10}", {b: string})
     7  t2: json.Validate("{\"a\":10}", {a: <3})
     8  t3: json.Valid("1")
     9  t4: json.Compact("[1, 2]")
    10  t5: json.Indent(#"{"a": 1, "b": 2}"#, "", "  ")
    11  t6: json.Unmarshal("1")
    12  t7: json.MarshalStream([{a: 1}, {b: 2}])
    13  t8: {
    14  	x: int
    15  	y: json.Marshal({a: x})
    16  }
    17  t9: json.MarshalStream([{a: 1}, {b: int | *2}])
    18  
    19  unmarshalStream: {
    20  	t1:    json.UnmarshalStream(#"{"a": 1}{"b": 2}"#)
    21  	t1:    json.UnmarshalStream(#'{"a": 1}{"b": 2}'#)
    22  	empty: json.UnmarshalStream('')
    23  	empty: json.UnmarshalStream("")
    24  	nums:  json.UnmarshalStream('1 2')
    25  	nums:  json.UnmarshalStream("1 2")
    26  }
    27  -- out/json --
    28  Errors:
    29  a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3):
    30      ./in.cue:4:5
    31      ./in.cue:4:37
    32      json.Validate:1:6
    33  
    34  Result:
    35  import "encoding/json"
    36  
    37  t1: true
    38  t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3)
    39  t3: true
    40  t4: "[1,2]"
    41  t5: """
    42  	{
    43  	  "a": 1,
    44  	  "b": 2
    45  	}
    46  	"""
    47  t6: 1
    48  t7: """
    49  	{"a":1}
    50  	{"b":2}
    51  
    52  	"""
    53  t8: {
    54  	x: int
    55  	y: json.Marshal({
    56  		a: x
    57  	})
    58  }
    59  t9: """
    60  	{"a":1}
    61  	{"b":2}
    62  
    63  	"""
    64  unmarshalStream: {
    65  	t1: [{
    66  		a: 1
    67  	}, {
    68  		b: 2
    69  	}]
    70  	empty: []
    71  	nums: [1, 2]
    72  }
    73