MarshalMatches converts actual to YAML and compares that to expected.
(actual any, expected string)
| 83 | |
| 84 | // MarshalMatches converts actual to YAML and compares that to expected. |
| 85 | func MarshalMatches(actual any, expected string) Comparison { |
| 86 | b, err := yaml.Marshal(actual) |
| 87 | if err != nil { |
| 88 | return func() gotest.Result { return gotest.ResultFromError(err) } |
| 89 | } |
| 90 | return gotest.DeepEqual(string(b), dedentLines( |
| 91 | strings.TrimLeft(strings.TrimRight(expected, "\t\n"), "\n"), 2, |
| 92 | )) |
| 93 | } |
| 94 | |
| 95 | // Or is an alias to [stdcmp.Or] in the standard library: |
| 96 | // - It returns the leftmost argument that is not zero. |