cuelang.org/go@v0.13.0/pkg/encoding/toml/testdata/marshal.txtar (about) 1 -- in.cue -- 2 import "encoding/toml" 3 4 marshal: { 5 _input: { 6 rootKey: r1: "foo" 7 rootKeys: { 8 r1: "foo" 9 r2: "bar" 10 r3: "baz" 11 } 12 rootKeysDots: { 13 a1: "foo" 14 b1: b2: "bar" 15 c1: c2: c3: "baz" 16 } 17 subtables: { 18 tables: [ 19 {table1: "foo"}, 20 {table2: "bar"}, 21 {subtable: {sub1: "baz"}} 22 ] 23 } 24 complexKeys: "123-456": " foo bar ": "value" 25 defaults: key: string | *"default" 26 27 failIncomplete: key: string | "nondefault" 28 failRequired: key!: "foo" 29 } 30 for name, value in _input { 31 output: (name): toml.Marshal(value) 32 } 33 } 34 35 unmarshal: { 36 _input: { 37 rootKeysDots: """ 38 a1 = "A" 39 b1.b2 = "B" 40 c1.c2.c3 = "C" 41 """ 42 subtables: """ 43 [[tables]] 44 table1 = 'foo' 45 [[tables]] 46 table2 = 'bar' 47 [[tables]] 48 [tables.subtable] 49 sub1 = 'baz' 50 """ 51 complexKeys: """ 52 [123-456] 53 ' foo bar ' = 'value' 54 """ 55 defaultEmpty: string | *"" 56 57 failIncomplete: string | "" 58 failBadSyntax: """ 59 = "no key name" 60 """ 61 failDuplicate: """ 62 foo = "same key" 63 foo = "same key" 64 """ 65 } 66 for name, value in _input { 67 output: (name): toml.Unmarshal(value) 68 } 69 } 70 71 -- out/toml -- 72 Errors: 73 unmarshal.output.failBadSyntax: error in call to encoding/toml.Unmarshal: invalid character at start of key: =: 74 ./in.cue:66:19 75 1:1 76 unmarshal.output.failDuplicate: error in call to encoding/toml.Unmarshal: duplicate key: foo: 77 ./in.cue:66:19 78 2:1 79 80 Result: 81 import "encoding/toml" 82 83 marshal: { 84 output: { 85 rootKey: """ 86 r1 = 'foo' 87 88 """ 89 rootKeys: """ 90 r1 = 'foo' 91 r2 = 'bar' 92 r3 = 'baz' 93 94 """ 95 rootKeysDots: """ 96 a1 = 'foo' 97 98 [b1] 99 b2 = 'bar' 100 101 [c1] 102 [c1.c2] 103 c3 = 'baz' 104 105 """ 106 subtables: """ 107 [[tables]] 108 table1 = 'foo' 109 110 [[tables]] 111 table2 = 'bar' 112 113 [[tables]] 114 [tables.subtable] 115 sub1 = 'baz' 116 117 """ 118 complexKeys: """ 119 [123-456] 120 ' foo bar ' = 'value' 121 122 """ 123 defaults: """ 124 key = 'default' 125 126 """ 127 failIncomplete: toml.Marshal(value) 128 failRequired: toml.Marshal(value) 129 } 130 } 131 unmarshal: { 132 output: { 133 rootKeysDots: { 134 a1: "A" 135 b1: { 136 b2: "B" 137 } 138 c1: { 139 c2: { 140 c3: "C" 141 } 142 } 143 } 144 subtables: { 145 tables: [{ 146 table1: "foo" 147 }, { 148 table2: "bar" 149 }, { 150 subtable: { 151 sub1: "baz" 152 } 153 }] 154 } 155 complexKeys: { 156 "123-456": { 157 " foo bar ": "value" 158 } 159 } 160 defaultEmpty: {} 161 failIncomplete: toml.Unmarshal(value) 162 failBadSyntax: _|_ // unmarshal.output.failBadSyntax: error in call to encoding/toml.Unmarshal: invalid character at start of key: = 163 failDuplicate: _|_ // unmarshal.output.failDuplicate: error in call to encoding/toml.Unmarshal: duplicate key: foo 164 } 165 }