/
util.go
36 lines (31 loc) · 819 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package test
import (
"fmt"
"testing"
"github.com/evanw/esbuild/internal/fs"
"github.com/evanw/esbuild/internal/logger"
)
func AssertEqual(t *testing.T, observed interface{}, expected interface{}) {
t.Helper()
if observed != expected {
t.Fatalf("%s != %s", observed, expected)
}
}
func AssertEqualWithDiff(t *testing.T, observed interface{}, expected interface{}) {
t.Helper()
if observed != expected {
stringA := fmt.Sprintf("%v", observed)
stringB := fmt.Sprintf("%v", expected)
color := !fs.CheckIfWindows()
t.Fatal("\n" + diff(stringB, stringA, color))
}
}
func SourceForTest(contents string) logger.Source {
return logger.Source{
Index: 0,
KeyPath: logger.Path{Text: "<stdin>"},
PrettyPath: "<stdin>",
Contents: contents,
IdentifierName: "stdin",
}
}