| 54 | } |
| 55 | |
| 56 | func TestSectionSet(t *testing.T) { |
| 57 | t.Parallel() |
| 58 | |
| 59 | sections := iniSectionSet{} |
| 60 | assert.Equal(t, sections.String(), "") |
| 61 | |
| 62 | sections["db"] = iniMultiSet{"x": []string{"y"}} |
| 63 | assert.Equal(t, sections.String(), |
| 64 | "\n[db]\nx = y\n") |
| 65 | |
| 66 | sections["db:backup"] = iniMultiSet{"x": []string{"w"}} |
| 67 | assert.Equal(t, sections.String(), |
| 68 | "\n[db]\nx = y\n\n[db:backup]\nx = w\n", |
| 69 | "expected subcommand after its stanza") |
| 70 | |
| 71 | sections["another"] = iniMultiSet{"x": []string{"z"}} |
| 72 | assert.Equal(t, sections.String(), |
| 73 | "\n[another]\nx = z\n\n[db]\nx = y\n\n[db:backup]\nx = w\n", |
| 74 | "expected alphabetical stanzas") |
| 75 | |
| 76 | sections["global"] = iniMultiSet{"x": []string{"t"}} |
| 77 | assert.Equal(t, sections.String(), |
| 78 | "\n[global]\nx = t\n\n[another]\nx = z\n\n[db]\nx = y\n\n[db:backup]\nx = w\n", |
| 79 | "expected global before stanzas") |
| 80 | |
| 81 | sections["global:command"] = iniMultiSet{"t": []string{"v"}} |
| 82 | assert.Equal(t, sections.String(), |
| 83 | strings.Join([]string{ |
| 84 | "\n[global]\nx = t\n", |
| 85 | "\n[global:command]\nt = v\n", |
| 86 | "\n[another]\nx = z\n", |
| 87 | "\n[db]\nx = y\n", |
| 88 | "\n[db:backup]\nx = w\n", |
| 89 | }, ""), |
| 90 | "expected global subcommand after global") |
| 91 | |
| 92 | t.Run("PrettyYAML", func(t *testing.T) { |
| 93 | sections["last"] = iniMultiSet{"z": []string{""}} |
| 94 | b, err := yaml.Marshal(sections.String()) |
| 95 | |
| 96 | assert.NilError(t, err) |
| 97 | assert.Assert(t, strings.HasPrefix(string(b), `|`), |
| 98 | "expected literal block scalar, got:\n%s", b) |
| 99 | }) |
| 100 | } |