From 499974c27ec11e6559c7564933d4a54ddedf440c Mon Sep 17 00:00:00 2001 From: kenjones Date: Sat, 23 Sep 2017 09:36:17 -0400 Subject: [PATCH] Bugfix: Write empty array value When the value is `[]` set the value to empty array instead of `'[]'`. Resolves: #21 --- Makefile | 1 + commands_test.go | 16 ++++++++++++++++ yaml.go | 3 +++ 3 files changed, 20 insertions(+) diff --git a/Makefile b/Makefile index 9b4aa1ec..88e7d347 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,7 @@ install: build .PHONY: vendor vendor: tmp/dev_image_id ${DOCKRUN} bash ./scripts/vendor.sh + @chmod 664 vendor/vendor.json # ---------------------------------------------- # develop and test diff --git a/commands_test.go b/commands_test.go index 028bf1f1..2661d076 100644 --- a/commands_test.go +++ b/commands_test.go @@ -248,6 +248,22 @@ func TestWriteCmd(t *testing.T) { assertResult(t, expectedOutput, result.Output) } +func TestWriteCmd_EmptyArray(t *testing.T) { + content := `b: 3` + filename := writeTempYamlFile(content) + defer removeTempYamlFile(filename) + + cmd := getRootCommand() + result := runCmd(cmd, fmt.Sprintf("write %s a []", filename)) + if result.Error != nil { + t.Error(result.Error) + } + expectedOutput := `b: 3 +a: [] +` + assertResult(t, expectedOutput, result.Output) +} + func TestWriteCmd_Error(t *testing.T) { cmd := getRootCommand() result := runCmd(cmd, "write") diff --git a/yaml.go b/yaml.go index 114edd6e..9038bc1b 100644 --- a/yaml.go +++ b/yaml.go @@ -343,6 +343,9 @@ func parseValue(argument string) interface{} { if err == nil { return value } + if argument == "[]" { + return make([]interface{}, 0) + } return argument } return argument[1 : len(argument)-1]