Do not rely on map order for tests
diff --git a/command_test.go b/command_test.go
index 67ced9f..8507782 100644
--- a/command_test.go
+++ b/command_test.go
@@ -279,7 +279,7 @@
} `command:"cmd"`
}{}
- assertParseFail(t, ErrRequired, fmt.Sprintf("the required flags `%cv' and `%smissing' were not specified", defaultShortOptDelimiter, defaultLongOptDelimiter), &opts, "cmd")
+ assertParseFail(t, ErrRequired, fmt.Sprintf("the required flags `%smissing' and `%cv' were not specified", defaultLongOptDelimiter, defaultShortOptDelimiter), &opts, "cmd")
}
func TestDefaultOnCommand(t *testing.T) {
diff --git a/ini_private.go b/ini_private.go
index 64f8fb8..8b2bb9b 100644
--- a/ini_private.go
+++ b/ini_private.go
@@ -6,6 +6,7 @@
"io"
"os"
"reflect"
+ "sort"
"strings"
)
@@ -111,9 +112,19 @@
fmt.Fprintf(writer, "; %s =\n", oname)
}
case reflect.Map:
- for _, key := range val.MapKeys() {
- k, _ := convertToString(key, option.tag)
- v, _ := convertToString(val.MapIndex(key), option.tag)
+ mkeys := val.MapKeys()
+ keys := make([]string, len(val.MapKeys()))
+ kkmap := make(map[string]reflect.Value)
+
+ for i, k := range mkeys {
+ keys[i], _ = convertToString(k, option.tag)
+ kkmap[keys[i]] = k
+ }
+
+ sort.Strings(keys)
+
+ for _, k := range keys {
+ v, _ := convertToString(val.MapIndex(kkmap[k]), option.tag)
fmt.Fprintf(writer, "%s%s = %s:%s\n", commentOption, oname, k, v)
}
diff --git a/ini_test.go b/ini_test.go
index b8fcd26..2920e56 100644
--- a/ini_test.go
+++ b/ini_test.go
@@ -50,8 +50,8 @@
DefaultArray = Another value
; Testdefault map value
-DefaultMap = some:value
DefaultMap = another:value
+DefaultMap = some:value
; Option only available in ini
only-ini =
@@ -91,8 +91,8 @@
; DefaultArray = Another value
; Testdefault map value
-; DefaultMap = some:value
; DefaultMap = another:value
+; DefaultMap = some:value
; Option only available in ini
; only-ini =
diff --git a/parser_private.go b/parser_private.go
index 8d29b6b..006f267 100644
--- a/parser_private.go
+++ b/parser_private.go
@@ -4,6 +4,7 @@
"bytes"
"fmt"
"os"
+ "sort"
"strings"
"unicode/utf8"
)
@@ -54,6 +55,8 @@
names = append(names, "`"+k.String()+"'")
}
+ sort.Strings(names)
+
var msg string
if len(names) == 1 {