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