mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Remove unused function UpdateYamlValue
This commit is contained in:
parent
a199ed1396
commit
02611dad7c
2 changed files with 0 additions and 189 deletions
|
@ -8,113 +8,6 @@ import (
|
|||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestUpdateYamlValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
path []string
|
||||
value string
|
||||
expectedOut string
|
||||
expectedErr string
|
||||
}{
|
||||
{
|
||||
name: "update value",
|
||||
in: "foo: bar\n",
|
||||
path: []string{"foo"},
|
||||
value: "baz",
|
||||
expectedOut: "foo: baz\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "add new key and value",
|
||||
in: "foo: bar\n",
|
||||
path: []string{"foo2"},
|
||||
value: "baz",
|
||||
expectedOut: "foo: bar\nfoo2: baz\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "add new key and value when document was empty",
|
||||
in: "",
|
||||
path: []string{"foo"},
|
||||
value: "bar",
|
||||
expectedOut: "foo: bar\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "preserve inline comment",
|
||||
in: "foo: bar # my comment\n",
|
||||
path: []string{"foo2"},
|
||||
value: "baz",
|
||||
expectedOut: "foo: bar # my comment\nfoo2: baz\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "nested update",
|
||||
in: "foo:\n bar: baz\n",
|
||||
path: []string{"foo", "bar"},
|
||||
value: "qux",
|
||||
expectedOut: "foo:\n bar: qux\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "nested where parents doesn't exist yet",
|
||||
in: "",
|
||||
path: []string{"foo", "bar", "baz"},
|
||||
value: "qux",
|
||||
expectedOut: "foo:\n bar:\n baz: qux\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "don't rewrite file if value didn't change",
|
||||
in: "foo:\n bar: baz\n",
|
||||
path: []string{"foo", "bar"},
|
||||
value: "baz",
|
||||
expectedOut: "foo:\n bar: baz\n",
|
||||
expectedErr: "",
|
||||
},
|
||||
|
||||
// Error cases
|
||||
{
|
||||
name: "existing document is not a dictionary",
|
||||
in: "42\n",
|
||||
path: []string{"foo"},
|
||||
value: "bar",
|
||||
expectedOut: "42\n",
|
||||
expectedErr: "yaml document is not a dictionary",
|
||||
},
|
||||
{
|
||||
name: "trying to update a note that is not a scalar",
|
||||
in: "foo: [1, 2, 3]\n",
|
||||
path: []string{"foo"},
|
||||
value: "bar",
|
||||
expectedOut: "foo: [1, 2, 3]\n",
|
||||
expectedErr: "yaml node is not a scalar",
|
||||
},
|
||||
{
|
||||
name: "not all path elements are dictionaries",
|
||||
in: "foo:\n bar: [1, 2, 3]\n",
|
||||
path: []string{"foo", "bar", "baz"},
|
||||
value: "qux",
|
||||
expectedOut: "foo:\n bar: [1, 2, 3]\n",
|
||||
expectedErr: "yaml node in path is not a dictionary",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
out, actualErr := UpdateYamlValue([]byte(test.in), test.path, test.value)
|
||||
if test.expectedErr == "" {
|
||||
assert.NoError(t, actualErr)
|
||||
} else {
|
||||
assert.EqualError(t, actualErr, test.expectedErr)
|
||||
}
|
||||
|
||||
assert.Equal(t, test.expectedOut, string(out))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenameYamlKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue