(sctx *super.Context, lhs, rhs Evaluator, operator string)
| 284 | } |
| 285 | |
| 286 | func NewCompareRelative(sctx *super.Context, lhs, rhs Evaluator, operator string) (*Compare, error) { |
| 287 | c := &Compare{sctx: sctx, numeric: newNumeric(sctx, lhs, rhs), operator: operator} |
| 288 | switch operator { |
| 289 | case "<": |
| 290 | c.convert = func(v int) bool { return v < 0 } |
| 291 | case "<=": |
| 292 | c.convert = func(v int) bool { return v <= 0 } |
| 293 | case ">": |
| 294 | c.convert = func(v int) bool { return v > 0 } |
| 295 | case ">=": |
| 296 | c.convert = func(v int) bool { return v >= 0 } |
| 297 | default: |
| 298 | return nil, fmt.Errorf("unknown comparison operator: %s", operator) |
| 299 | } |
| 300 | return c, nil |
| 301 | } |
| 302 | |
| 303 | func (c *Compare) result(result int) super.Value { |
| 304 | return super.NewBool(c.convert(result)) |
no test coverage detected