(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestComprehension(t *testing.T) { |
| 187 | fac := ast.NewExprFactory() |
| 188 | expr := fac.NewComprehension(1, |
| 189 | fac.NewList(2, []ast.Expr{ |
| 190 | fac.NewLiteral(3, types.Int(1)), |
| 191 | fac.NewLiteral(4, types.Int(2)), |
| 192 | }, []int32{}), |
| 193 | "i", |
| 194 | "__result__", |
| 195 | fac.NewLiteral(5, types.False), |
| 196 | fac.NewLiteral(6, types.True), |
| 197 | fac.NewCall(7, "_||_", |
| 198 | fac.NewAccuIdent(8), |
| 199 | fac.NewCall(9, "<", fac.NewIdent(10, "i"), fac.NewLiteral(11, types.Int(3))), |
| 200 | ), |
| 201 | fac.NewAccuIdent(12), |
| 202 | ) |
| 203 | comp := expr.AsComprehension() |
| 204 | if comp.IterRange().Kind() != ast.ListKind { |
| 205 | t.Errorf("IterRange() got %v, wanted list", comp.IterRange().Kind()) |
| 206 | } |
| 207 | if comp.AccuInit().Kind() != ast.LiteralKind { |
| 208 | t.Errorf("AccuInit() got %v, wanted literal", comp.AccuInit().Kind()) |
| 209 | } |
| 210 | if comp.LoopCondition().Kind() != ast.LiteralKind { |
| 211 | t.Errorf("LoopCondition() got %v, wanted literal", comp.LoopCondition().Kind()) |
| 212 | } |
| 213 | if comp.LoopStep().Kind() != ast.CallKind { |
| 214 | t.Errorf("LoopStep() got %v, wanted call", comp.LoopStep().Kind()) |
| 215 | } |
| 216 | if comp.Result().Kind() != ast.IdentKind { |
| 217 | t.Errorf("Result() got %v, wanted identifier", comp.Result().Kind()) |
| 218 | } |
| 219 | expr.RenumberIDs(testIDGen(100)) |
| 220 | if expr.ID() != 101 { |
| 221 | t.Errorf("Renumbering an unspecified expression mutated the value: %v", expr) |
| 222 | } |
| 223 | comp = expr.AsComprehension() |
| 224 | if comp.IterRange().ID() != 102 { |
| 225 | t.Errorf("IterRange() got %v, wanted list", comp.IterRange().ID()) |
| 226 | } |
| 227 | if comp.AccuInit().ID() != 105 { |
| 228 | t.Errorf("AccuInit() got %v, wanted literal", comp.AccuInit().ID()) |
| 229 | } |
| 230 | if comp.LoopCondition().ID() != 106 { |
| 231 | t.Errorf("LoopCondition() got %v, wanted literal", comp.LoopCondition().ID()) |
| 232 | } |
| 233 | if comp.LoopStep().ID() != 107 { |
| 234 | t.Errorf("LoopStep() got %v, wanted call", comp.LoopStep().ID()) |
| 235 | } |
| 236 | if comp.Result().ID() != 112 { |
| 237 | t.Errorf("Result() got %v, wanted identifier", comp.Result().ID()) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func TestComprehensionNil(t *testing.T) { |
| 242 | expr := nilTestExpr(t) |
nothing calls this directly
no test coverage detected