void TLArrayMethodRemove(string swiftType, string csType, string csValue, string csNewValue, string output) { string swiftCode = $"public class FooTLAMR{swiftType} {{\n" + $"public init() {{ }}\n" + $"public func makeArray(a:{swiftType}) -> [{swiftType}]\n {{\n return [{swiftType}](repeating:a, count:2) \n}}\n" + $"}}"; CodeElementCollection <ICodeElement> callingCode = new CodeElementCollection <ICodeElement> (); CSLine decl = CSVariableDeclaration.VarLine(new CSSimpleType("SwiftArray", false, new CSSimpleType(csType)), new CSIdentifier("arr"), new CSFunctionCall($"new FooTLAMR{swiftType}().MakeArray", false, new CSIdentifier(csValue))); CSLine addLine = CSFunctionCall.FunctionCallLine("arr.Insert", false, CSConstant.Val(1), new CSIdentifier(csNewValue)); CSLine remLine = CSFunctionCall.FunctionCallLine("arr.RemoveAt", false, CSConstant.Val(1)); CSLine call = CSFunctionCall.FunctionCallLine("Console.Write", false, new CSIdentifier("arr.Count")); CSForEach feach = new CSForEach(new CSSimpleType(csType), "x", new CSIdentifier("arr"), null); feach.Body.Add(CSFunctionCall.FunctionCallLine("Console.Write", false, CSConstant.Val(" {0}"), feach.Ident)); callingCode.Add(decl); callingCode.Add(addLine); callingCode.Add(remLine); callingCode.Add(call); callingCode.Add(feach); TestRunning.TestAndExecute(swiftCode, callingCode, output, testName: $"TLArrayMethodRemove{swiftType}"); }
public void TestVariadicParameters() { string swiftCode = @"public func intsAsArray (a:Int32 ... ) -> [Int32] { return a }"; var arrId = new CSIdentifier("arr"); var otherarrId = new CSIdentifier("otherarr"); var arrDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, arrId, new CSFunctionCall("SwiftArray<int>", true, CSConstant.Val(1), CSConstant.Val(2), CSConstant.Val(3))); var otherArrDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, otherarrId, new CSFunctionCall("TopLevelEntities.IntsAsArray", false, arrId)); var feach = new CSForEach(CSSimpleType.Var, "x", otherarrId, null); feach.Body.Add(CSFunctionCall.FunctionCallLine("Console.Write", false, feach.Ident)); var callingCode = CSCodeBlock.Create(arrDecl, otherArrDecl, feach); TestRunning.TestAndExecute(swiftCode, callingCode, "123"); }
public void TestVariadiacInOpenClass() { string swiftCode = @"open class OpenVarArr { public init () { } open func intsAsArray (a:Int32 ...) -> [Int32] { return a } } "; var arrId = new CSIdentifier("arr"); var otherarrId = new CSIdentifier("otherarr"); var varArrId = new CSIdentifier("vararr"); var arrDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, arrId, new CSFunctionCall("SwiftArray<int>", true, CSConstant.Val(1), CSConstant.Val(2), CSConstant.Val(3))); var varArrDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, varArrId, new CSFunctionCall("OpenVarArr", true)); var otherArrDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, otherarrId, new CSFunctionCall($"{varArrId.Name}.IntsAsArray", false, arrId)); var feach = new CSForEach(CSSimpleType.Var, "x", otherarrId, null); feach.Body.Add(CSFunctionCall.FunctionCallLine("Console.Write", false, feach.Ident)); var callingCode = CSCodeBlock.Create(arrDecl, varArrDecl, otherArrDecl, feach); TestRunning.TestAndExecute(swiftCode, callingCode, "123", platform: PlatformName.macOS); }