1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 var queryTests
= []struct {
16 {`Abcdef`, `"Abc" "bcd" "cde" "def"`},
17 {`(abc)(def)`, `"abc" "bcd" "cde" "def"`},
18 {`abc.*(def|ghi)`, `"abc" ("def"|"ghi")`},
19 {`abc(def|ghi)`, `"abc" ("bcd" "cde" "def")|("bcg" "cgh" "ghi")`},
20 {`a+hello`, `"ahe" "ell" "hel" "llo"`},
21 {`(a+hello|b+world)`, `("ahe" "ell" "hel" "llo")|("bwo" "orl" "rld" "wor")`},
28 {`ab[cde]f`, `("abc" "bcf")|("abd" "bdf")|("abe" "bef")`},
29 {`(abc|bac)de`, `"cde" ("abc" "bcd")|("acd" "bac")`},
31 // These don't have enough letters for a trigram, so they return the
32 // always matching query "+".
42 {`(abc|abc)`, `"abc"`},
43 {`(ab|ab)c`, `"abc"`},
44 {`ab(cab|cat)`, `"abc" "bca" ("cab"|"cat")`},
45 {`(z*(abc|def)z*)(z*(abc|def)z*)`, `("abc"|"def")`},
46 {`(z*abcz*defz*)|(z*abcz*defz*)`, `"abc" "def"`},
47 {`(z*abcz*defz*(ghi|jkl)z*)|(z*abcz*defz*(mno|prs)z*)`,
48 `"abc" "def" ("ghi"|"jkl"|"mno"|"prs")`},
49 {`(z*(abcz*def)|(ghiz*jkl)z*)|(z*(mnoz*prs)|(tuvz*wxy)z*)`,
50 `("abc" "def")|("ghi" "jkl")|("mno" "prs")|("tuv" "wxy")`},
51 {`(z*abcz*defz*)(z*(ghi|jkl)z*)`, `"abc" "def" ("ghi"|"jkl")`},
52 {`(z*abcz*defz*)|(z*(ghi|jkl)z*)`, `("ghi"|"jkl")|("abc" "def")`},
54 // analyze keeps track of multiple possible prefix/suffixes.
55 {`[ab][cd][ef]`, `("ace"|"acf"|"ade"|"adf"|"bce"|"bcf"|"bde"|"bdf")`},
56 {`ab[cd]e`, `("abc" "bce")|("abd" "bde")`},
58 // Different sized suffixes.
59 {`(a|ab)cde`, `"cde" ("abc" "bcd")|("acd")`},
60 {`(a|b|c|d)(ef|g|hi|j)`, `+`},
65 {`(?i)a~~`, `("A~~"|"a~~")`},
66 {`(?i)ab~`, `("AB~"|"Ab~"|"aB~"|"ab~")`},
67 {`(?i)abc`, `("ABC"|"ABc"|"AbC"|"Abc"|"aBC"|"aBc"|"abC"|"abc")`},
68 {`(?i)abc|def`, `("ABC"|"ABc"|"AbC"|"Abc"|"DEF"|"DEf"|"DeF"|"Def"|"aBC"|"aBc"|"abC"|"abc"|"dEF"|"dEf"|"deF"|"def")`},
69 {`(?i)abcd`, `("ABC"|"ABc"|"AbC"|"Abc"|"aBC"|"aBc"|"abC"|"abc") ("BCD"|"BCd"|"BcD"|"Bcd"|"bCD"|"bCd"|"bcD"|"bcd")`},
70 {`(?i)abc|abc`, `("ABC"|"ABc"|"AbC"|"Abc"|"aBC"|"aBc"|"abC"|"abc")`},
83 func TestQuery(t
*testing
.T
) {
84 for _
, tt
:= range queryTests
{
85 re
, err
:= syntax
.Parse(tt
.re
, syntax
.Perl
)
89 q
:= RegexpQuery(re
).String()
91 t
.Errorf("RegexpQuery(%#q) = %#q, want %#q", tt
.re
, q
, tt
.q
)