1 module orelang.operator.AssertOperator; 2 import orelang.operator.IOperator, 3 orelang.Engine, 4 orelang.Value; 5 6 class AssertOperator : IOperator { 7 /** 8 * call 9 */ 10 public Value call(Engine engine, Value[] args) { 11 Value evaled = engine.eval(args[0]); 12 bool flag; 13 14 switch (evaled.type) with (ValueType) { 15 case Bool: 16 flag = evaled.getBool; 17 break; 18 case Numeric: 19 flag = cast(bool)evaled.getNumeric; 20 break; 21 default: 22 flag = true; 23 break; 24 } 25 26 if (!flag) { 27 throw new Exception("Assertion failed: " ~ args[0].toString); 28 } 29 30 return new Value(true); 31 } 32 }