...

Source file src/gotest.tools/v3/assert/example_test.go

Documentation: gotest.tools/v3/assert

     1  package assert_test
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"testing"
     7  
     8  	"gotest.tools/v3/assert"
     9  	"gotest.tools/v3/assert/cmp"
    10  )
    11  
    12  var t = &testing.T{}
    13  
    14  func ExampleAssert_customComparison() {
    15  	regexPattern := func(value string, pattern string) cmp.Comparison {
    16  		return func() cmp.Result {
    17  			re := regexp.MustCompile(pattern)
    18  			if re.MatchString(value) {
    19  				return cmp.ResultSuccess
    20  			}
    21  			return cmp.ResultFailure(
    22  				fmt.Sprintf("%q did not match pattern %q", value, pattern))
    23  		}
    24  	}
    25  	assert.Assert(t, regexPattern("12345.34", `\d+.\d\d`))
    26  }
    27  

View as plain text