github.com/Comcast/plax@v0.8.32/dsl/regexp_test.go (about) 1 package dsl 2 3 import ( 4 "testing" 5 ) 6 7 func TestRegexpMatch(t *testing.T) { 8 p := `(?P<first>[a-zA-Z]+) and (?P<Last>[a-zA-Z]+)` 9 bss, err := RegexpMatch(p, "Tacos and queso") 10 if err != nil { 11 t.Fatal(err) 12 } 13 14 if len(bss) != 1 { 15 t.Fatal(bss) 16 } 17 bs := bss[0] 18 19 if x, have := bs["?*first"]; !have { 20 t.Fatal("?*first") 21 } else { 22 if s, is := x.(string); !is { 23 t.Fatal(x) 24 } else if s != "Tacos" { 25 t.Fatal(s) 26 } 27 } 28 29 if x, have := bs["?Last"]; !have { 30 t.Fatal("?Last") 31 } else { 32 if s, is := x.(string); !is { 33 t.Fatal(x) 34 } else if s != "queso" { 35 t.Fatal(s) 36 } 37 } 38 }