...

Source file src/github.com/goph/emperror/wrap_format_test.go

Documentation: github.com/goph/emperror

     1  package emperror
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func testFormatRegexp(t *testing.T, n int, arg interface{}, format, want string) {
    11  	got := fmt.Sprintf(format, arg)
    12  	gotLines := strings.SplitN(got, "\n", -1)
    13  	wantLines := strings.SplitN(want, "\n", -1)
    14  
    15  	if len(wantLines) > len(gotLines) {
    16  		t.Errorf("test %d: wantLines(%d) > gotLines(%d):\n got: %q\nwant: %q", n+1, len(wantLines), len(gotLines), got, want)
    17  		return
    18  	}
    19  
    20  	for i, w := range wantLines {
    21  		match, err := regexp.MatchString(w, gotLines[i])
    22  		if err != nil {
    23  			t.Fatal(err)
    24  		}
    25  		if !match {
    26  			t.Errorf("test %d: line %d: fmt.Sprintf(%q, err):\n got: %q\nwant: %q", n+1, i+1, format, got, want)
    27  		}
    28  	}
    29  }
    30  

View as plain text