Don't convert windows newlines

If the canonical newline is a single LF, don't insert CRLF in tests
This commit is contained in:
James Bardin 2016-12-01 10:22:15 -05:00
parent a97a4ff95f
commit aaca009935

View File

@ -9,7 +9,6 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/hashicorp/hcl/hcl/ast" "github.com/hashicorp/hcl/hcl/ast"
"github.com/hashicorp/hcl/testhelper"
) )
func TestDecode_interface(t *testing.T) { func TestDecode_interface(t *testing.T) {
@ -89,8 +88,7 @@ func TestDecode_interface(t *testing.T) {
{ {
"multiline_literal_with_hil.hcl", "multiline_literal_with_hil.hcl",
false, false,
map[string]interface{}{"multiline_literal_with_hil": testhelper.Unix2dos(`${hello map[string]interface{}{"multiline_literal_with_hil": "${hello\n world}"},
world}`)},
}, },
{ {
"multiline_no_marker.hcl", "multiline_no_marker.hcl",
@ -100,22 +98,22 @@ func TestDecode_interface(t *testing.T) {
{ {
"multiline.hcl", "multiline.hcl",
false, false,
map[string]interface{}{"foo": testhelper.Unix2dos("bar\nbaz\n")}, map[string]interface{}{"foo": "bar\nbaz\n"},
}, },
{ {
"multiline_indented.hcl", "multiline_indented.hcl",
false, false,
map[string]interface{}{"foo": testhelper.Unix2dos(" bar\n baz\n")}, map[string]interface{}{"foo": " bar\n baz\n"},
}, },
{ {
"multiline_no_hanging_indent.hcl", "multiline_no_hanging_indent.hcl",
false, false,
map[string]interface{}{"foo": testhelper.Unix2dos(" baz\n bar\n foo\n")}, map[string]interface{}{"foo": " baz\n bar\n foo\n"},
}, },
{ {
"multiline_no_eof.hcl", "multiline_no_eof.hcl",
false, false,
map[string]interface{}{"foo": testhelper.Unix2dos("bar\nbaz\n"), "key": "value"}, map[string]interface{}{"foo": "bar\nbaz\n", "key": "value"},
}, },
{ {
"multiline.json", "multiline.json",
@ -394,31 +392,32 @@ func TestDecode_interface(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
t.Logf("Testing: %s", tc.File) t.Run(tc.File, func(t *testing.T) {
d, err := ioutil.ReadFile(filepath.Join(fixtureDir, tc.File)) d, err := ioutil.ReadFile(filepath.Join(fixtureDir, tc.File))
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
var out interface{} var out interface{}
err = Decode(&out, string(d)) err = Decode(&out, string(d))
if (err != nil) != tc.Err { if (err != nil) != tc.Err {
t.Fatalf("Input: %s\n\nError: %s", tc.File, err) t.Fatalf("Input: %s\n\nError: %s", tc.File, err)
} }
if !reflect.DeepEqual(out, tc.Out) { if !reflect.DeepEqual(out, tc.Out) {
t.Fatalf("Input: %s. Actual, Expected.\n\n%#v\n\n%#v", tc.File, out, tc.Out) t.Fatalf("Input: %s. Actual, Expected.\n\n%#v\n\n%#v", tc.File, out, tc.Out)
} }
var v interface{} var v interface{}
err = Unmarshal(d, &v) err = Unmarshal(d, &v)
if (err != nil) != tc.Err { if (err != nil) != tc.Err {
t.Fatalf("Input: %s\n\nError: %s", tc.File, err) t.Fatalf("Input: %s\n\nError: %s", tc.File, err)
} }
if !reflect.DeepEqual(v, tc.Out) { if !reflect.DeepEqual(v, tc.Out) {
t.Fatalf("Input: %s. Actual, Expected.\n\n%#v\n\n%#v", tc.File, out, tc.Out) t.Fatalf("Input: %s. Actual, Expected.\n\n%#v\n\n%#v", tc.File, out, tc.Out)
} }
})
} }
} }