This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac5a5f1
commit 534f9d5
Showing
4 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package template | ||
|
||
import ( | ||
"testing" | ||
|
||
heredoc "github.com/makenowjust/heredoc/v2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSplitYAML(t *testing.T) { | ||
var tests = []struct { | ||
desc string | ||
inBytes []byte | ||
outBytes [][]byte | ||
err error | ||
}{ | ||
{ | ||
desc: "a simple YAML file with no leading document separator", | ||
inBytes: []byte(heredoc.Doc(` | ||
a: Easy | ||
b: | ||
c: 2 | ||
d: | ||
- 3 | ||
- 4 | ||
`)), | ||
outBytes: [][]byte{[]byte(heredoc.Doc(` | ||
a: Easy | ||
b: | ||
c: 2 | ||
d: | ||
- 3 | ||
- 4 | ||
`))}, | ||
err: nil, | ||
}, | ||
{ | ||
desc: "a simple YAML file with a leading document separator", | ||
inBytes: []byte(heredoc.Doc(` | ||
--- | ||
a: Easy | ||
b: | ||
c: 2 | ||
d: | ||
- 3 | ||
- 4 | ||
`)), | ||
outBytes: [][]byte{[]byte(heredoc.Doc(` | ||
a: Easy | ||
b: | ||
c: 2 | ||
d: | ||
- 3 | ||
- 4 | ||
`))}, | ||
err: nil, | ||
}, | ||
{ | ||
desc: "a YAML file with no leading document separator but a string value containing ---", | ||
inBytes: []byte(heredoc.Doc(` | ||
a: Easy | ||
b: | ||
c: 2 --- | ||
d: | ||
- 3 | ||
- 4 | ||
`)), | ||
outBytes: [][]byte{[]byte(heredoc.Doc(` | ||
a: Easy | ||
b: | ||
c: 2 --- | ||
d: | ||
- 3 | ||
- 4 | ||
`))}, | ||
err: nil, | ||
}, | ||
{ | ||
desc: "a YAML file with both a leading document separator and a string value containing ---", | ||
inBytes: []byte(heredoc.Doc(` | ||
--- | ||
a: Easy | ||
b: | ||
c: 2 --- | ||
d: | ||
- 3 | ||
- 4 | ||
`)), | ||
outBytes: [][]byte{[]byte(heredoc.Doc(` | ||
a: Easy | ||
b: | ||
c: 2 --- | ||
d: | ||
- 3 | ||
- 4 | ||
`))}, | ||
err: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.desc, func(t *testing.T) { | ||
outBytes, err := splitYAML(tt.inBytes) | ||
if tt.err == nil { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
assert.Equal(t, tt.outBytes, outBytes) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters