public void TestStringParsing() { StringBuilder bld = new StringBuilder(); bld.AppendLine("#<classtype Name> func(arg1 FullName type, arg2 FullName type) => c++func(cppargtype, cppargtype)"); bld.AppendLine("ParseTest sin(System.Double) => sin(double)"); bld.AppendLine("ParseTest f1(System.Int32, System.Int32) => f1(int, int)"); bld.AppendLine("ParseTest f2(System.Double,System.Double) => f2(double,double)"); var target = new TypeHandlerReplacementCall(); target.Parse(new StringReader(bld.ToString())); var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) }); var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("f1"), new Expression[] { Expression.Constant((int)10), Expression.Constant((int)20) }); var e3 = Expression.Call(null, typeof(ParseTest).GetMethod("f2"), new Expression[] { Expression.Constant((double)10.3), Expression.Constant((double)20.3) }); var gc = new GeneratedCode(); var context = new CodeContext(); var result = CodeMethodCall(target, e1, gc); Assert.AreEqual("sin((double)10.3)", result.RawValue, "sin incorrect"); result = CodeMethodCall(target, e2, gc); Assert.AreEqual("f1((int)10,(int)20)", result.RawValue, "f1 incorrect"); result = CodeMethodCall(target, e3, gc); Assert.AreEqual("f2((double)10.3,(double)20.3)", result.RawValue, "f2 incorrect"); }
public void TestFunctionMerge() { StringBuilder bld = new StringBuilder(); bld.AppendLine("ParseTest sin(System.Double) => freak(double)"); var target = new TypeHandlerReplacementCall(); target.Parse(new StringReader(bld.ToString())); bld = new StringBuilder(); bld.AppendLine("ParseTest sin(System.Double) => sin(double)"); target.Parse(new StringReader(bld.ToString())); var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) }); var gc = new GeneratedCode(); var context = new CodeContext(); var result = CodeMethodCall(target, e1, gc); Assert.AreEqual("freak((double)10.3)", result.RawValue, "sin incorrect"); }
public void TestParseInclude() { StringBuilder bld = new StringBuilder(); bld.AppendLine("include: cmath1 cmath3"); bld.AppendLine("ParseTest sin(System.Double) => freak(double)"); bld.AppendLine("include: cmath2"); bld.AppendLine("ParseTest cos(System.Double) => cos(double)"); bld.AppendLine("include: "); bld.AppendLine("ParseTest tan(System.Double) => tan(double)"); var target = new TypeHandlerReplacementCall(); target.Parse(new StringReader(bld.ToString())); var gc = new GeneratedCode(); var context = new CodeContext(); var e0 = Expression.Call(null, typeof(ParseTest).GetMethod("tan"), new Expression[] { Expression.Constant((double)10.3) }); var result = CodeMethodCall(target, e0, gc); Assert.AreEqual(0, gc.IncludeFiles.Count(), "# include files after none should have been added"); var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("cos"), new Expression[] { Expression.Constant((double)10.3) }); result = CodeMethodCall(target, e1, gc); Assert.AreEqual(1, gc.IncludeFiles.Count(), "# include files"); Assert.AreEqual("cmath2", gc.IncludeFiles.First(), "include filename"); var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) }); result = CodeMethodCall(target, e2, gc); Assert.AreEqual(3, gc.IncludeFiles.Count(), "# include files"); Assert.IsTrue(gc.IncludeFiles.Contains("cmath1"), "cmath1 missing"); Assert.IsTrue(gc.IncludeFiles.Contains("cmath2"), "cmath1 missing"); Assert.IsTrue(gc.IncludeFiles.Contains("cmath3"), "cmath1 missing"); }
public void TestParseInclude() { StringBuilder bld = new StringBuilder(); bld.AppendLine("include: cmath1 cmath3"); bld.AppendLine("ParseTest sin(System.Double) => freak(double)"); bld.AppendLine("include: cmath2"); bld.AppendLine("ParseTest cos(System.Double) => cos(double)"); bld.AppendLine("include: "); bld.AppendLine("ParseTest tan(System.Double) => tan(double)"); var target = new TypeHandlerReplacementCall(); target.Parse(new StringReader(bld.ToString())); var gc = new GeneratedCode(); var context = new CodeContext(); var e0 = Expression.Call(null, typeof(ParseTest).GetMethod("tan"), new Expression[] { Expression.Constant((double)10.3) }); var result = CodeMethodCall(target, e0, gc); Assert.AreEqual(0, gc.IncludeFiles.Count(), "# include files after none should have been added"); var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("cos"), new Expression[] { Expression.Constant((double)10.3) }); result = CodeMethodCall(target, e1, gc); Assert.AreEqual(1, gc.IncludeFiles.Count(), "# include files"); Assert.AreEqual("cmath2", gc.IncludeFiles.First(), "include filename"); var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) }); result = CodeMethodCall(target, e2, gc); Assert.AreEqual(3, gc.IncludeFiles.Count(), "# include files"); Assert.IsTrue(gc.IncludeFiles.Contains("cmath1"), "cmath1 missing"); Assert.IsTrue(gc.IncludeFiles.Contains("cmath2"), "cmath1 missing"); Assert.IsTrue(gc.IncludeFiles.Contains("cmath3"), "cmath1 missing"); }
public void TestFunctionMerge() { StringBuilder bld = new StringBuilder(); bld.AppendLine("ParseTest sin(System.Double) => freak(double)"); var target = new TypeHandlerReplacementCall(); target.Parse(new StringReader(bld.ToString())); bld = new StringBuilder(); bld.AppendLine("ParseTest sin(System.Double) => sin(double)"); target.Parse(new StringReader(bld.ToString())); var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) }); var gc = new GeneratedCode(); var context = new CodeContext(); var result = CodeMethodCall(target, e1, gc); Assert.AreEqual("freak((double)10.3)", result.RawValue, "sin incorrect"); }
public void TestStringParsing() { StringBuilder bld = new StringBuilder(); bld.AppendLine("#<classtype Name> func(arg1 FullName type, arg2 FullName type) => c++func(cppargtype, cppargtype)"); bld.AppendLine("ParseTest sin(System.Double) => sin(double)"); bld.AppendLine("ParseTest f1(System.Int32, System.Int32) => f1(int, int)"); bld.AppendLine("ParseTest f2(System.Double,System.Double) => f2(double,double)"); var target = new TypeHandlerReplacementCall(); target.Parse(new StringReader(bld.ToString())); var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) }); var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("f1"), new Expression[] { Expression.Constant((int)10), Expression.Constant((int)20) }); var e3 = Expression.Call(null, typeof(ParseTest).GetMethod("f2"), new Expression[] { Expression.Constant((double)10.3), Expression.Constant((double)20.3) }); var gc = new GeneratedCode(); var context = new CodeContext(); var result = CodeMethodCall(target, e1, gc); Assert.AreEqual("sin((double)10.3)", result.RawValue, "sin incorrect"); result = CodeMethodCall(target, e2, gc); Assert.AreEqual("f1((int)10,(int)20)", result.RawValue, "f1 incorrect"); result = CodeMethodCall(target, e3, gc); Assert.AreEqual("f2((double)10.3,(double)20.3)", result.RawValue, "f2 incorrect"); }