Fix scanner tests on Windows

This is necessary because of the effects of autocrlf on Windows.
This commit is contained in:
James Nugent 2016-03-20 23:14:42 +00:00
parent fdad785730
commit 4b7727828a
2 changed files with 18 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"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) {
@ -88,12 +89,12 @@ func TestDecode_interface(t *testing.T) {
{ {
"multiline.hcl", "multiline.hcl",
false, false,
map[string]interface{}{"foo": "bar\nbaz\n"}, map[string]interface{}{"foo": testhelper.Unix2dos("bar\nbaz\n")},
}, },
{ {
"multiline_no_eof.hcl", "multiline_no_eof.hcl",
false, false,
map[string]interface{}{"foo": "bar\nbaz\n", "key": "value"}, map[string]interface{}{"foo": testhelper.Unix2dos("bar\nbaz\n"), "key": "value"},
}, },
{ {
"multiline.json", "multiline.json",

15
testhelper/unix2dos.go Normal file
View File

@ -0,0 +1,15 @@
package testhelper
import (
"runtime"
"strings"
)
// Converts the line endings when on Windows
func Unix2dos(unix string) string {
if runtime.GOOS != "windows" {
return unix
}
return strings.Replace(unix, "\n", "\r\n", -1)
}