(t *testing.T)
| 178 | } |
| 179 | |
| 180 | func TestWhitespaceHanlding(t *testing.T) { |
| 181 | |
| 182 | testCases := []struct { |
| 183 | matchID string |
| 184 | want string |
| 185 | }{ |
| 186 | { |
| 187 | matchID: "folded_unambiguous", |
| 188 | want: "a string expression that is folded", |
| 189 | }, |
| 190 | { |
| 191 | matchID: "folded_line_break", |
| 192 | // 8 spaces (4 indents) |
| 193 | want: "a string expression that\n is folded", |
| 194 | }, |
| 195 | { |
| 196 | matchID: "folded_line_break_indent", |
| 197 | // 10 spaces (5 indents) |
| 198 | want: "a string expression that\n is folded", |
| 199 | }, |
| 200 | { |
| 201 | matchID: "literal_unambiguous", |
| 202 | want: "a string expression that is a literal block", |
| 203 | }, |
| 204 | { |
| 205 | matchID: "literal_line_break", |
| 206 | // 8 spaces (4 indents) |
| 207 | want: "a string expression that\n is a literal block", |
| 208 | }, |
| 209 | { |
| 210 | matchID: "literal_line_break_indent", |
| 211 | // 10 spaces (5 indents) |
| 212 | want: "a string expression that\n is a literal block", |
| 213 | }, |
| 214 | } |
| 215 | |
| 216 | policy := parsePolicy(t, "yaml_parsing", []ParserOption{}) |
| 217 | env, ast, iss := compile(t, "yaml_parsing", policy, []cel.EnvOption{}, []CompilerOption{}) |
| 218 | if iss.Err() != nil { |
| 219 | t.Fatalf("compile('yaml_parsing') failed, %s", iss.Err().Error()) |
| 220 | } |
| 221 | |
| 222 | p, err := env.PlanProgram(ast.NativeRep()) |
| 223 | |
| 224 | if err != nil { |
| 225 | t.Fatalf("env.PlanProgram() failed, %s", err.Error()) |
| 226 | } |
| 227 | |
| 228 | for _, tst := range testCases { |
| 229 | t.Run(tst.matchID, func(t *testing.T) { |
| 230 | |
| 231 | in := map[string]any{"match_id": types.String(tst.matchID)} |
| 232 | |
| 233 | result, _, err := p.Eval(in) |
| 234 | if err != nil { |
| 235 | t.Fatalf("p.Eval(match_id: '%s') failed, %s", tst.matchID, err.Error()) |
| 236 | } |
| 237 | s, ok := result.(types.String) |
nothing calls this directly
no test coverage detected