Skip to content

Commit 5fa984a

Browse files
Merge pull request #1791 from brackendawson/YAMLEq-document-multidoc
assert.YAMLEq: Document mutlidoc behavior
2 parents b9167da + 2b945c3 commit 5fa984a

File tree

6 files changed

+129
-8
lines changed

6 files changed

+129
-8
lines changed

assert/assertion_format.go

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assertion_forward.go

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assertions.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,19 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
18801880
return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...)
18811881
}
18821882

1883-
// YAMLEq asserts that two YAML strings are equivalent.
1883+
// YAMLEq asserts that the first documents in the two YAML strings are equivalent.
1884+
//
1885+
// expected := `---
1886+
// key: value
1887+
// ---
1888+
// key: this is a second document, it is not evaluated
1889+
// `
1890+
// actual := `---
1891+
// key: value
1892+
// ---
1893+
// key: this is a subsequent document, it is not evaluated
1894+
// `
1895+
// assert.YAMLEq(t, expected, actual)
18841896
func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {
18851897
if h, ok := t.(tHelper); ok {
18861898
h.Helper()

assert/assertions_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,6 +2868,31 @@ func TestYAMLEq_ArraysOfDifferentOrder(t *testing.T) {
28682868
False(t, YAMLEq(mockT, `["foo", {"hello": "world", "nested": "hash"}]`, `[{ "hello": "world", "nested": "hash"}, "foo"]`))
28692869
}
28702870

2871+
func TestYAMLEq_OnlyFirstDocument(t *testing.T) {
2872+
t.Parallel()
2873+
2874+
mockT := new(testing.T)
2875+
True(t, YAMLEq(mockT,
2876+
`---
2877+
doc1: same
2878+
---
2879+
doc2: different
2880+
`,
2881+
`---
2882+
doc1: same
2883+
---
2884+
doc2: notsame
2885+
`,
2886+
))
2887+
}
2888+
2889+
func TestYAMLEq_InvalidIdenticalYAML(t *testing.T) {
2890+
t.Parallel()
2891+
2892+
mockT := new(testing.T)
2893+
False(t, YAMLEq(mockT, `}`, `}`))
2894+
}
2895+
28712896
type diffTestingStruct struct {
28722897
A string
28732898
B int

require/require.go

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

require/require_forward.go

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)