public void OperatorCompositionNoInvoke()
        {
            var swiftCode =
                "infix operator ∘\n" +
                "    public func ∘<T>(left: @escaping (T) -> (T), right: @escaping (T) -> (T)) -> (T) -> (T) {\n" +
                "        return { (x) in\n" +
                "            left (right(x))\n" +
                "        }\n" +
                "}\n";

            var lbody1 = new CSCodeBlock();
            var lid    = new CSIdentifier("d");

            lbody1.Add(CSReturn.ReturnLine(lid * CSConstant.Val(2.0)));
            var pl = new CSParameterList();

            pl.Add(new CSParameter(CSSimpleType.Double, lid));
            var lam1   = new CSLambda(pl, lbody1);
            var lbody2 = new CSCodeBlock();

            lbody2.Add(CSReturn.ReturnLine(lid * CSConstant.Val(3.0)));
            var lam2 = new CSLambda(pl, lbody2);

            var compFunc = CSFunctionCall.FunctionCallLine("TopLevelEntities.InfixOperatorRing", false, lam1, lam2);
            var printIt  = CSFunctionCall.ConsoleWriteLine(CSConstant.Val(12.0));

            var callingCode = new CodeElementCollection <ICodeElement> {
                compFunc, printIt
            };

            TestRunning.TestAndExecute(swiftCode, callingCode, "12\n");
        }
        public void HandlesAutoclosure()
        {
            var swiftCode =
                "public func autoClosureCheck(a: @autoclosure ()->Bool) -> Bool {\n" +
                "    return a()\n" +
                "}\n";

            var callingCode = new CodeElementCollection <ICodeElement> ();

            var body = new CSCodeBlock();

            body.Add(CSReturn.ReturnLine(CSConstant.Val(true)));
            var lambda = new CSLambda(body);

            var printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.AutoClosureCheck", lambda));

            callingCode.Add(printer);

            TestRunning.TestAndExecute(swiftCode, callingCode, "True\n");
        }
        public void ClosureIdentity()
        {
            var swiftCode =
                "public func closureIdentity(a: @escaping () -> ()) -> () -> () {\n" +
                "    return a\n" +
                "}\n";

            var callingCode = new CodeElementCollection <ICodeElement> ();
            var body        = new CSCodeBlock();

            body.Add(CSFunctionCall.ConsoleWriteLine(CSConstant.Val("Success")));
            var lambda = new CSLambda(body);

            callingCode.Add(CSVariableDeclaration.VarLine(new CSSimpleType("Action"), "lam", lambda));
            callingCode.Add(CSVariableDeclaration.VarLine(new CSSimpleType("Action"), "lamreturn",
                                                          new CSFunctionCall("TopLevelEntities.ClosureIdentity", false, new CSIdentifier("lam"))));
            callingCode.Add(CSFunctionCall.FunctionCallLine("lamreturn", false));

            TestRunning.TestAndExecute(swiftCode, callingCode, "Success\n");
        }
        public void ClosureIdentityIntBool()
        {
            var swiftCode =
                "public func closureIdentityIntBool(a: @escaping (Int) -> Bool) -> (Int) -> (Bool) {\n" +
                "    return a\n" +
                "}\n";

            var callingCode = new CodeElementCollection <ICodeElement> ();
            var body        = new CSCodeBlock();

            body.Add(CSFunctionCall.ConsoleWriteLine((CSIdentifier)"i"));
            body.Add(CSReturn.ReturnLine(CSConstant.Val(true)));
            var lambda     = new CSLambda(body, "i");
            var returnType = new CSSimpleType("Func", false, new CSSimpleType("nint"), CSSimpleType.Bool);

            callingCode.Add(CSVariableDeclaration.VarLine(returnType, "lam", lambda));
            callingCode.Add(CSVariableDeclaration.VarLine(returnType, "lamreturn",
                                                          new CSFunctionCall("TopLevelEntities.ClosureIdentityIntBool", false, new CSIdentifier("lam"))));
            callingCode.Add(CSFunctionCall.FunctionCallLine("lamreturn", false, CSConstant.Val(17)));

            TestRunning.TestAndExecute(swiftCode, callingCode, "17\n");
        }
        public void ClosureActionStringString()
        {
            var swiftCode =
                "public func closureIdentityStringString (a: @escaping (String, String)->()) -> (String, String) -> () {\n" +
                " return a\n" +
                "}\n";

            var callingCode = new CodeElementCollection <ICodeElement> ();
            var body        = new CSCodeBlock();

            body.Add(CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("stra.ToString") + CSFunctionCall.Function("strb.ToString")));
            var lambda     = new CSLambda(body, "stra", "strb");
            var returnType = new CSSimpleType("Action", false, new CSSimpleType("SwiftString"), new CSSimpleType("SwiftString"));

            callingCode.Add(CSVariableDeclaration.VarLine(returnType, "lam", lambda));
            callingCode.Add(CSVariableDeclaration.VarLine(returnType, "lamreturn",
                                                          new CSFunctionCall("TopLevelEntities.ClosureIdentityStringString", false, new CSIdentifier("lam"))));
            callingCode.Add(CSFunctionCall.FunctionCallLine("lamreturn", false, new CSFunctionCall("SwiftString.FromString", false, CSConstant.Val("hi ")),
                                                            new CSFunctionCall("SwiftString.FromString", false, CSConstant.Val("mom"))));

            TestRunning.TestAndExecute(swiftCode, callingCode, "hi mom\n");
        }
        public void ClosureIdentityDoubleDoubleDouble()
        {
            var swiftCode =
                "public func closureIdentityDoubleDoubleDouble(a: @escaping (Double, Double) -> Double) -> (Double, Double) -> Double {\n" +
                "    return a\n" +
                "}\n";

            var callingCode = new CodeElementCollection <ICodeElement> ();
            var body        = new CSCodeBlock();
            var aId         = new CSIdentifier("a");
            var bId         = new CSIdentifier("b");

            body.Add(CSFunctionCall.ConsoleWriteLine(aId + bId));
            body.Add(CSReturn.ReturnLine(aId + bId));
            var lambda     = new CSLambda(body, "a", "b");
            var returnType = new CSSimpleType("Func", false, CSSimpleType.Double, CSSimpleType.Double, CSSimpleType.Double);

            callingCode.Add(CSVariableDeclaration.VarLine(returnType, "lam", lambda));
            callingCode.Add(CSVariableDeclaration.VarLine(returnType, "lamreturn",
                                                          new CSFunctionCall("TopLevelEntities.ClosureIdentityDoubleDoubleDouble", false, new CSIdentifier("lam"))));
            callingCode.Add(CSFunctionCall.FunctionCallLine("lamreturn", false, CSConstant.Val(3.1), CSConstant.Val(4.0)));

            TestRunning.TestAndExecute(swiftCode, callingCode, "7.1\n");
        }