(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func TestMatch(t *testing.T) { |
| 115 | err := Init(nil) |
| 116 | require.NoError(t, err) |
| 117 | |
| 118 | tests := []struct { |
| 119 | glob string |
| 120 | val string |
| 121 | ret bool |
| 122 | expr string |
| 123 | }{ |
| 124 | {"foo", "foo", true, `Match(pattern, name)`}, |
| 125 | {"foo", "bar", false, `Match(pattern, name)`}, |
| 126 | {"foo*", "foo", true, `Match(pattern, name)`}, |
| 127 | {"foo*", "foobar", true, `Match(pattern, name)`}, |
| 128 | {"foo*", "barfoo", false, `Match(pattern, name)`}, |
| 129 | {"foo*", "bar", false, `Match(pattern, name)`}, |
| 130 | {"*foo", "foo", true, `Match(pattern, name)`}, |
| 131 | {"*foo", "barfoo", true, `Match(pattern, name)`}, |
| 132 | {"foo*r", "foobar", true, `Match(pattern, name)`}, |
| 133 | {"foo*r", "foobazr", true, `Match(pattern, name)`}, |
| 134 | {"foo?ar", "foobar", true, `Match(pattern, name)`}, |
| 135 | {"foo?ar", "foobazr", false, `Match(pattern, name)`}, |
| 136 | {"foo?ar", "foobaz", false, `Match(pattern, name)`}, |
| 137 | {"*foo?ar?", "foobar", false, `Match(pattern, name)`}, |
| 138 | {"*foo?ar?", "foobare", true, `Match(pattern, name)`}, |
| 139 | {"*foo?ar?", "rafoobar", false, `Match(pattern, name)`}, |
| 140 | {"*foo?ar?", "rafoobare", true, `Match(pattern, name)`}, |
| 141 | } |
| 142 | for _, test := range tests { |
| 143 | env := map[string]any{ |
| 144 | "pattern": test.glob, |
| 145 | "name": test.val, |
| 146 | } |
| 147 | |
| 148 | vm, err := expr.Compile(test.expr, GetExprOptions(env)...) |
| 149 | if err != nil { |
| 150 | t.Fatalf("pattern:%s val:%s NOK %s", test.glob, test.val, err) |
| 151 | } |
| 152 | |
| 153 | ret, err := expr.Run(vm, env) |
| 154 | require.NoError(t, err) |
| 155 | |
| 156 | if isOk := assert.Equal(t, test.ret, ret); !isOk { |
| 157 | t.Fatalf("pattern:%s val:%s NOK %t != %t", test.glob, test.val, ret, test.ret) |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // just to verify that the function is available, real tests are in TestExtractQueryParam |
| 163 | func TestExtractQueryParamExpr(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…