public void TestBasic() { ValueFunctionOverload overload = new ValueFunctionOverload(); IScope scope = new ScopeChain(); { // add a single function & make sure it's called at right time & fails at right time ValueFunction numInt = new Add(ValueType.Number, ValueType.Int, 0); overload.Add(numInt); Value a = overload.Eval(null, MakePair(3, 4, true, true), scope, scope, null, null); Assert.AreEqual(7, a.AsInt); Value b = overload.Eval(null, MakePair(3, 5, false, true), scope, scope, null, null); Assert.AreEqual(8, b.AsFloat); bool bThrew = false; try { overload.Eval(null, MakePair(3, 4, false, false), scope, scope, null, null); } catch (Loki3Exception) { bThrew = true; } Assert.IsTrue(bThrew); } { // add a second function & make sure both succeed & fail at right time // this one is more specific so should get called first when signature matches ValueFunction intInt = new Add(ValueType.Int, ValueType.Int, 1); overload.Add(intInt); Value a = overload.Eval(null, MakePair(3, 4, true, true), scope, scope, null, null); Assert.AreEqual(8, a.AsInt); // calls 2nd version Value b = overload.Eval(null, MakePair(3, 5, false, true), scope, scope, null, null); Assert.AreEqual(8, b.AsFloat); // calls 1st version bool bThrew = false; try { // still no match for this one overload.Eval(null, MakePair(3, 4, false, false), scope, scope, null, null); } catch (Loki3Exception) { bThrew = true; } Assert.IsTrue(bThrew); } { // try adding a postfix function to the overload bool bThrew = false; try { ValueFunction post = new Post(); overload.Add(post); } catch (Loki3Exception e) { Assert.AreEqual("prefix", e.Errors[Loki3Exception.keyExpectedFix].ToString()); Assert.AreEqual("postfix", e.Errors[Loki3Exception.keyActualFix].ToString()); bThrew = true; } Assert.IsTrue(bThrew); } }