| 1 | package internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/ |
| 2 | |
| 3 | import ( |
| 4 | "stringsscip-go gomod github.com/golang/go/src go1.25 strings/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.25 testing/" |
| 6 | ) |
| 7 | |
| 8 | // Tests for converting between KDL v1 and v2 syntax. |
| 9 | // These verify that: |
| 10 | // 1. v1 input produces the same AST as equivalent v2 input |
| 11 | // 2. Generating from either AST produces valid v2 output |
| 12 | // 3. Round-tripping through parse→generate→parse preserves semantics |
| 13 | |
| 14 | // --- v1 ↔ v2 equivalent AST tests --- |
| 15 | |
| 16 | func TestConvert_BooleansSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_BooleansSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 17 | // v1: true/false, v2: #true/#false — same AST |
| 18 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node true false") |
| 19 | if err != nil { |
| 20 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 21 | } |
| 22 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node #true #false") |
| 23 | if err != nil { |
| 24 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 25 | } |
| 26 | |
| 27 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 28 | } |
| 29 | |
| 30 | func TestConvert_NullSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_NullSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 31 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node null") |
| 32 | if err != nil { |
| 33 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 34 | } |
| 35 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node #null") |
| 36 | if err != nil { |
| 37 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 38 | } |
| 39 | |
| 40 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 41 | } |
| 42 | |
| 43 | func TestConvert_BooleanPropSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_BooleanPropSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 44 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node active=true disabled=false") |
| 45 | if err != nil { |
| 46 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 47 | } |
| 48 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node active=#true disabled=#false") |
| 49 | if err != nil { |
| 50 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 51 | } |
| 52 | |
| 53 | assertSamePropValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSamePropValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 54 | } |
| 55 | |
| 56 | func TestConvert_NullPropSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_NullPropSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 57 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node val=null") |
| 58 | if err != nil { |
| 59 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 60 | } |
| 61 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node val=#null") |
| 62 | if err != nil { |
| 63 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 64 | } |
| 65 | |
| 66 | assertSamePropValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSamePropValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 67 | } |
| 68 | |
| 69 | func TestConvert_RawStringSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_RawStringSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 70 | // v1: r"hello", v2: #"hello"# |
| 71 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node r"hello"`) |
| 72 | if err != nil { |
| 73 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 74 | } |
| 75 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node #"hello"#`) |
| 76 | if err != nil { |
| 77 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 78 | } |
| 79 | |
| 80 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 81 | } |
| 82 | |
| 83 | func TestConvert_RawStringWithHashesSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_RawStringWithHashesSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 84 | // v1: r#"contains "quotes""#, v2: ##"contains "quotes""## |
| 85 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node r#"contains "quotes""#`) |
| 86 | if err != nil { |
| 87 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 88 | } |
| 89 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node ##"contains "quotes""##`) |
| 90 | if err != nil { |
| 91 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 92 | } |
| 93 | |
| 94 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 95 | } |
| 96 | |
| 97 | func TestConvert_RawStringNoEscapesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_RawStringNoEscapes().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 98 | // Both v1 and v2 raw strings should NOT process backslash escapes |
| 99 | docV1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node r"hello\nworld"`) |
| 100 | if err != nil { |
| 101 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 102 | } |
| 103 | docV2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node #"hello\nworld"#`) |
| 104 | if err != nil { |
| 105 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 106 | } |
| 107 | |
| 108 | // Both should have the literal text "hello\nworld" (no actual newline) |
| 109 | assertArgStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertArgString().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], 0, "hello\\nworld") |
| 110 | assertArgStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertArgString().(t, docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], 0, "hello\\nworld") |
| 111 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, docV1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], docV2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 112 | } |
| 113 | |
| 114 | // --- Shared syntax produces identical AST --- |
| 115 | |
| 116 | func TestConvert_SharedQuotedStringsSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_SharedQuotedStringsSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 117 | input := `node "hello world" "with\nnewline"` |
| 118 | doc1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 119 | if err != nil { |
| 120 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 121 | } |
| 122 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 123 | if err != nil { |
| 124 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 125 | } |
| 126 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, doc1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 127 | } |
| 128 | |
| 129 | func TestConvert_SharedNumbersSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_SharedNumbersSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 130 | input := "node 42 3.14 -10 0xff 0o77 0b1010 1_000" |
| 131 | doc1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 132 | if err != nil { |
| 133 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 134 | } |
| 135 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 136 | if err != nil { |
| 137 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 138 | } |
| 139 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, doc1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 140 | } |
| 141 | |
| 142 | func TestConvert_SharedChildrenSameASTscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_SharedChildrenSameAST().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 143 | input := "parent {\n child1 \"arg\"\n child2 42\n}" |
| 144 | doc1, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 145 | if err != nil { |
| 146 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 147 | } |
| 148 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 149 | if err != nil { |
| 150 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 151 | } |
| 152 | if len(doc1.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0].Childrenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Children.) != len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0].Childrenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Children.) { |
| 153 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("children count mismatch") |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // --- v1 input → v2 output (generate always outputs v2) --- |
| 158 | |
| 159 | func TestConvert_V1BooleansToV2Outputscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V1BooleansToV2Output().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 160 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node true false") |
| 161 | if err != nil { |
| 162 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 163 | } |
| 164 | out, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 165 | if err != nil { |
| 166 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 167 | } |
| 168 | // Output should use v2 syntax |
| 169 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(out, "#true") || !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(out, "#false") { |
| 170 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected v2 booleans in output, got:\n%s", out) |
| 171 | } |
| 172 | if stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(out, " true") && !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(out, "#true") { |
| 173 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("bare 'true' in output (should be #true)") |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func TestConvert_V1NullToV2Outputscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V1NullToV2Output().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 178 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().("node null") |
| 179 | if err != nil { |
| 180 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 181 | } |
| 182 | out, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 183 | if err != nil { |
| 184 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 185 | } |
| 186 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(out, "#null") { |
| 187 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #null in output, got:\n%s", out) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func TestConvert_V1RawStringToV2QuotedOutputscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V1RawStringToV2QuotedOutput().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 192 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(`node r"hello world"`) |
| 193 | if err != nil { |
| 194 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 195 | } |
| 196 | out, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 197 | if err != nil { |
| 198 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 199 | } |
| 200 | // Generator outputs regular quoted strings, not raw |
| 201 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(out, `"hello world"`) { |
| 202 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected quoted string in output, got:\n%s", out) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // --- Full v1→v2 round-trip --- |
| 207 | |
| 208 | func TestConvert_V1FullDocumentToV2scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V1FullDocumentToV2().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 209 | v1Input := `// A v1 document |
| 210 | name "Bob" |
| 211 | age 76 |
| 212 | active true |
| 213 | empty null |
| 214 | server { |
| 215 | host "localhost" |
| 216 | port 8080 |
| 217 | tls false |
| 218 | }` |
| 219 | |
| 220 | // Parse as v1 |
| 221 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v1Input) |
| 222 | if err != nil { |
| 223 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 224 | } |
| 225 | |
| 226 | // Generate as v2 |
| 227 | v2Output, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 228 | if err != nil { |
| 229 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 230 | } |
| 231 | |
| 232 | // v2 output should use #true/#false/#null |
| 233 | if stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, " true\n") && !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#true") { |
| 234 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #true in v2 output") |
| 235 | } |
| 236 | if stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, " false\n") && !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#false") { |
| 237 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #false in v2 output") |
| 238 | } |
| 239 | if stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, " null\n") && !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#null") { |
| 240 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #null in v2 output") |
| 241 | } |
| 242 | |
| 243 | // Re-parse the v2 output and verify same data |
| 244 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v2Output) |
| 245 | if err != nil { |
| 246 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("failed to re-parse v2 output: %v\nOutput:\n%s", err, v2Output) |
| 247 | } |
| 248 | |
| 249 | // Verify structure preserved |
| 250 | if len(doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) != len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) { |
| 251 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("node count mismatch: %d vs %d", len(doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.), len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.)) |
| 252 | } |
| 253 | |
| 254 | for i, n := range doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes. { |
| 255 | if n.Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name. != doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[i].Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name. { |
| 256 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("node %d: name mismatch: %q vs %q", i, n.Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name., doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[i].Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name.) |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // --- v2→v1 equivalent: parsing v2 output with v1 keywords --- |
| 262 | |
| 263 | func TestConvert_V2OutputReparsesCorrectlyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V2OutputReparsesCorrectly().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 264 | inputs := []string{ |
| 265 | "node #true #false #null", |
| 266 | "node 42 3.14 0xff", |
| 267 | `node "hello" key="val"`, |
| 268 | "parent {\n child 1\n}", |
| 269 | "a\nb\nc", |
| 270 | } |
| 271 | |
| 272 | for _, input := range inputs { |
| 273 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 274 | if err != nil { |
| 275 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("parse %q: %v", input, err) |
| 276 | } |
| 277 | |
| 278 | out, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 279 | if err != nil { |
| 280 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("generate %q: %v", input, err) |
| 281 | } |
| 282 | |
| 283 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(out) |
| 284 | if err != nil { |
| 285 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("reparse %q (output: %q): %v", input, out, err) |
| 286 | } |
| 287 | |
| 288 | if len(doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) != len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) { |
| 289 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("round-trip %q: node count %d vs %d", input, len(doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.), len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.)) |
| 290 | } |
| 291 | |
| 292 | for i := range doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes. { |
| 293 | if i >= len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) { |
| 294 | break |
| 295 | } |
| 296 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[i], doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[i]) |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // --- Mixed v1/v2 features in same document --- |
| 302 | |
| 303 | func TestConvert_MixedV1V2SyntaxSharedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_MixedV1V2SyntaxShared().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 304 | // Common syntax that works in both versions |
| 305 | input := `node "string" 42 3.14 key="val" { |
| 306 | child |
| 307 | }` |
| 308 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(input) |
| 309 | if err != nil { |
| 310 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 311 | } |
| 312 | |
| 313 | assertNodeNamescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertNodeName().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], "node") |
| 314 | assertArgStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertArgString().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], 0, "string") |
| 315 | assertArgIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertArgInt().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], 1, 42) |
| 316 | assertArgFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertArgFloat().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], 2, 3.14) |
| 317 | assertPropStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertPropString().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], "key", "val") |
| 318 | assertChildCountscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertChildCount().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], 1) |
| 319 | } |
| 320 | |
| 321 | // --- Real-world config conversion tests --- |
| 322 | |
| 323 | func TestConvert_ZellijConfigV1ToV2scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_ZellijConfigV1ToV2().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 324 | // Simplified Zellij-like config in v1 style |
| 325 | v1Config := `keybinds { |
| 326 | normal { |
| 327 | bind "Alt" "h" { |
| 328 | action "MoveFocusOrTab" "Left" |
| 329 | } |
| 330 | bind "Alt" "l" { |
| 331 | action "MoveFocusOrTab" "Right" |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | theme "dracula" |
| 336 | default_shell "zsh" |
| 337 | pane_frames true` |
| 338 | |
| 339 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v1Config) |
| 340 | if err != nil { |
| 341 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 342 | } |
| 343 | |
| 344 | // Generate v2 |
| 345 | v2Output, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 346 | if err != nil { |
| 347 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 348 | } |
| 349 | |
| 350 | // Verify v2 output uses #true |
| 351 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#true") { |
| 352 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #true in v2 output for pane_frames") |
| 353 | } |
| 354 | |
| 355 | // Re-parse and verify round-trip |
| 356 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v2Output) |
| 357 | if err != nil { |
| 358 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("re-parse failed: %v\nOutput:\n%s", err, v2Output) |
| 359 | } |
| 360 | |
| 361 | if len(doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) != len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.) { |
| 362 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("node count mismatch: %d vs %d", len(doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.), len(doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.)) |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | func TestConvert_PackageConfigV1ToV2scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_PackageConfigV1ToV2().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 367 | v1Config := `package { |
| 368 | name "my-app" |
| 369 | version "1.0.0" |
| 370 | description "A great app" |
| 371 | } |
| 372 | dependencies { |
| 373 | dep "react" "^18.0.0" |
| 374 | dep "typescript" "^5.0.0" |
| 375 | } |
| 376 | build { |
| 377 | minify true |
| 378 | sourcemap false |
| 379 | target "es2022" |
| 380 | }` |
| 381 | |
| 382 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v1Config) |
| 383 | if err != nil { |
| 384 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 385 | } |
| 386 | |
| 387 | v2Output, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 388 | if err != nil { |
| 389 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 390 | } |
| 391 | |
| 392 | // Should contain v2 booleans |
| 393 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#true") || !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#false") { |
| 394 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected v2 booleans, got:\n%s", v2Output) |
| 395 | } |
| 396 | |
| 397 | // Round-trip |
| 398 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v2Output) |
| 399 | if err != nil { |
| 400 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("re-parse failed: %v", err) |
| 401 | } |
| 402 | |
| 403 | assertNodeCountscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertNodeCount().(t, &Documentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#{Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.: doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.}, 3) |
| 404 | } |
| 405 | |
| 406 | // --- Version marker conversion --- |
| 407 | |
| 408 | func TestConvert_V1MarkerDocumentToV2scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V1MarkerDocumentToV2().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 409 | v1Input := "/- kdl-version 1\nnode true false null" |
| 410 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v1Input) |
| 411 | if err != nil { |
| 412 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 413 | } |
| 414 | |
| 415 | v2Output, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 416 | if err != nil { |
| 417 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 418 | } |
| 419 | |
| 420 | // Verify v2 keywords in output |
| 421 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#true") { |
| 422 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #true in converted output") |
| 423 | } |
| 424 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#false") { |
| 425 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #false in converted output") |
| 426 | } |
| 427 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(v2Output, "#null") { |
| 428 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected #null in converted output") |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | func TestConvert_V2MarkerDocumentRoundTripscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/TestConvert_V2MarkerDocumentRoundTrip().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 433 | v2Input := "/- kdl-version 2\nnode #true #false #null" |
| 434 | doc, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v2Input) |
| 435 | if err != nil { |
| 436 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 437 | } |
| 438 | |
| 439 | v2Output, err := GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().()) |
| 440 | if err != nil { |
| 441 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 442 | } |
| 443 | |
| 444 | doc2, err := Parsescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Parse().(v2Output) |
| 445 | if err != nil { |
| 446 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 447 | } |
| 448 | |
| 449 | assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t, doc.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0], doc2.Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.[0]) |
| 450 | } |
| 451 | |
| 452 | // --- Helpers --- |
| 453 | |
| 454 | func assertSameArgValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSameArgValues().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#, n1, n2 *Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#) { |
| 455 | t.Helperscip-go gomod github.com/golang/go/src go1.25 testing/common#Helper().() |
| 456 | if len(n1.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments.) != len(n2.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments.) { |
| 457 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("arg count mismatch: %d vs %d (node %q vs %q)", |
| 458 | len(n1.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments.), len(n2.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments.), n1.Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name., n2.Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name.) |
| 459 | } |
| 460 | for i := range n1.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. { |
| 461 | v1 := n1.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments.[i].Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value. |
| 462 | v2 := n2.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments.[i].Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value. |
| 463 | if v1 == nil && v2 == nil { |
| 464 | continue |
| 465 | } |
| 466 | if v1 == nil || v2 == nil { |
| 467 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("arg %d: value mismatch: %v vs %v", i, v1, v2) |
| 468 | continue |
| 469 | } |
| 470 | // Compare stringified values for simplicity with float edge cases |
| 471 | if !valuesEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/valuesEqual().(v1, v2) { |
| 472 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("arg %d: value mismatch: %v (%T) vs %v (%T)", i, v1, v1, v2, v2) |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | func assertSamePropValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/assertSamePropValues().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#, n1, n2 *Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#) { |
| 478 | t.Helperscip-go gomod github.com/golang/go/src go1.25 testing/common#Helper().() |
| 479 | if len(n1.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties.) != len(n2.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties.) { |
| 480 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("prop count mismatch: %d vs %d", len(n1.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties.), len(n2.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties.)) |
| 481 | } |
| 482 | for i := range n1.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties. { |
| 483 | p1 := n1.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties.[i] |
| 484 | p2 := n2.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties.[i] |
| 485 | if p1.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Key. != p2.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Key. { |
| 486 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("prop %d: key mismatch: %q vs %q", i, p1.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Key., p2.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Key.) |
| 487 | continue |
| 488 | } |
| 489 | if !valuesEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/valuesEqual().(p1.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Value..Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value., p2.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Value..Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.) { |
| 490 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("prop %q: value mismatch: %v vs %v", p1.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Key., p1.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Value..Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value., p2.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Value..Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.) |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | func valuesEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/valuesEqual().(a, b interface{}) bool { |
| 496 | if a == nil && b == nil { |
| 497 | return true |
| 498 | } |
| 499 | if a == nil || b == nil { |
| 500 | return false |
| 501 | } |
| 502 | // Direct comparison handles string, int64, bool |
| 503 | return a == b |
| 504 | } |