2020-11-02 02:05:23 -08:00
|
|
|
// Package assert provides testing helpers.
|
2020-09-18 05:38:09 -07:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
2020-11-02 01:03:05 -08:00
|
|
|
"strings"
|
2020-09-18 05:38:09 -07:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
g "github.com/maragudk/gomponents"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Equal checks for equality between the given expected string and the rendered Node string.
|
|
|
|
func Equal(t *testing.T, expected string, actual g.Node) {
|
2021-10-06 11:49:43 -07:00
|
|
|
t.Helper()
|
|
|
|
|
2020-11-02 01:03:05 -08:00
|
|
|
var b strings.Builder
|
|
|
|
_ = actual.Render(&b)
|
|
|
|
if expected != b.String() {
|
2022-09-21 01:37:44 -07:00
|
|
|
t.Fatalf(`expected "%v" but got "%v"`, expected, b.String())
|
2020-09-18 05:38:09 -07:00
|
|
|
}
|
|
|
|
}
|
2020-11-02 01:03:05 -08:00
|
|
|
|
|
|
|
// Error checks for a non-nil error.
|
|
|
|
func Error(t *testing.T, err error) {
|
2021-10-06 11:49:43 -07:00
|
|
|
t.Helper()
|
|
|
|
|
2020-11-02 01:03:05 -08:00
|
|
|
if err == nil {
|
2021-10-06 11:49:43 -07:00
|
|
|
t.Fatal("error is nil")
|
2020-11-02 01:03:05 -08:00
|
|
|
}
|
|
|
|
}
|