public void ObjCRefProtocolArg() { var swiftCode = "import Foundation\n" + "@objc\n" + "public protocol LifeTheUniverseAnd {\n" + " @objc func Everything () -> Int\n" + "}\n" + "@objc\n" + "internal class Liff : NSObject, LifeTheUniverseAnd {\n" + " private var x: Int\n" + " public init (z: Int) {\n" + " x = z\n" + " }\n" + " @objc func Everything () -> Int {\n" + " return x\n" + " }\n" + "}\n" + "public func makeIt (a: Int) -> LifeTheUniverseAnd {\n" + " return Liff(z: a)\n" + "}\n" + "public func setIt (a:inout LifeTheUniverseAnd) {\n" + " a = Liff(z: 42)\n" + "}\n"; var inst = CSVariableDeclaration.VarLine(CSSimpleType.Var, "liff", new CSFunctionCall("TopLevelEntities.MakeIt", false, CSConstant.Val(17))); var morphIt = CSFunctionCall.FunctionCallLine("TopLevelEntities.SetIt", false, new CSIdentifier("ref liff")); var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("liff.Everything")); var callingCode = CSCodeBlock.Create(inst, morphIt, printIt); TestRunning.TestAndExecute(swiftCode, callingCode, "42\n", platform: PlatformName.macOS); }
public void TestCharacterConstructors() { var swiftCode = @"public func Echo (c: Character) -> Character { return c; }"; var callingCode = new CodeElementCollection <ICodeElement> (); StringBuilder expected = new StringBuilder(); foreach (string c in TestCases) { CSIdentifier testIdentifier = (CSIdentifier)$@"""{c}"""; var ctorCall = CSFunctionCall.Ctor("SwiftCharacter", testIdentifier); var fromCall = CSFunctionCall.Function("SwiftCharacter.FromCharacter", testIdentifier); var implicitCall = new CSCastExpression((CSSimpleType)"SwiftCharacter", testIdentifier); foreach (var call in new CSBaseExpression [] { ctorCall, fromCall, implicitCall }) { CSLine print = CSFunctionCall.FunctionLine("Console.Write", CSFunctionCall.Function("TopLevelEntities.Echo", call)); callingCode.Add(print); expected.Append(c); } } TestRunning.TestAndExecute(swiftCode, callingCode, expected.ToString()); }
public void OperatorComposition() { 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 = CSVariableDeclaration.VarLine(new CSSimpleType("Func", false, CSSimpleType.Double, CSSimpleType.Double), "compLam", new CSFunctionCall("TopLevelEntities.InfixOperatorRing", false, lam1, lam2)); var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("compLam", CSConstant.Val(2.0))); var callingCode = new CodeElementCollection <ICodeElement> { compFunc, printIt }; TestRunning.TestAndExecute(swiftCode, callingCode, "12\n"); }
public void TestCharacterCreation() { var swiftCode = @" public class CharacterHolder { public var C: Character; public init (c: Character) {C = c } }"; var callingCode = new CodeElementCollection <ICodeElement> (); StringBuilder expected = new StringBuilder(); foreach (string c in TestCases) { CSIdentifier testIdentifier = (CSIdentifier)$@"""{c}"""; Action <ICSExpression> testCharacter = creation => { CSCodeBlock block = new CSCodeBlock(); block.Add(CSVariableDeclaration.VarLine((CSSimpleType)"SwiftCharacter", (CSIdentifier)"Char", creation)); block.Add(CSVariableDeclaration.VarLine((CSSimpleType)"CharacterHolder", (CSIdentifier)"Foo", CSFunctionCall.Ctor("CharacterHolder", (CSIdentifier)"Char"))); block.Add(CSFunctionCall.FunctionLine("Console.Write", (CSIdentifier)"(string)Foo.C")); expected.Append(c); callingCode.Add(block); }; testCharacter(CSFunctionCall.Function("SwiftCharacter.FromCharacter", (testIdentifier))); testCharacter(new CSCastExpression((CSSimpleType)"SwiftCharacter", testIdentifier)); } TestRunning.TestAndExecute(swiftCode, callingCode, expected.ToString()); }
public void WrapVirtualSubscriptProtocol() { string swiftCode = "public protocol Thingy {\n" + " func whoAmI () -> String\n" + "}\n" + "public class Popeye : Thingy {\n" + " public init() { }\n" + " public func whoAmI () -> String\n {" + " return \"who I yam\"\n" + " }\n" + "}\n" + "open class Scripto {\n" + " private var x:Thingy = Popeye()\n" + " public init() { }\n" + " open subscript (index: Int) -> Thingy {\n" + " get {\n" + " return x\n" + " }\n" + " set(newValue) {\n" + " x = newValue\n" + " }\n" + " }\n" + "}\n"; var decl = CSVariableDeclaration.VarLine(new CSSimpleType("Scripto"), "sub", new CSFunctionCall("Scripto", true)); var decl2 = CSVariableDeclaration.VarLine(CSSimpleType.Var, "pop", new CSIndexExpression("sub", false, CSConstant.Val(0))); var printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("pop.WhoAmI")); var callingCode = CSCodeBlock.Create(decl, decl2, printer); TestRunning.TestAndExecute(swiftCode, callingCode, "who I yam\n", platform: PlatformName.macOS); }
public void ObjCInvokeProp() { var swiftCode = "import Foundation\n" + "@objc\n" + "public protocol HandProp {\n" + " @objc var whichHand:Int { get }\n" + "}\n" + "public func doWhichHand(a:HandProp) -> Int {\n" + " return a.whichHand\n" + "}\n"; var altClass = new CSClass(CSVisibility.Public, "MyHandsProp"); altClass.Inheritance.Add(new CSIdentifier("NSObject")); altClass.Inheritance.Add(new CSIdentifier("IHandProp")); var whichHandProp = CSProperty.PublicGetBacking(new CSSimpleType("nint"), new CSIdentifier("WhichHand"), new CSIdentifier("42")); altClass.Properties.Add(whichHandProp); var altCtor = new CSMethod(CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList(), new CSBaseExpression [0], true, new CSCodeBlock()); altClass.Constructors.Add(altCtor); var altInst = CSVariableDeclaration.VarLine(CSSimpleType.Var, "lefty", new CSFunctionCall("MyHandsProp", true)); var caller = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.DoWhichHand", new CSIdentifier("lefty"))); var callingCode = CSCodeBlock.Create(altInst, caller); TestRunning.TestAndExecute(swiftCode, callingCode, "42\n", otherClass: altClass, platform: PlatformName.macOS); }
public void TestSetRemove(string swiftType, string cstype, string val) { var variant = swiftType; var swiftCode = $"public func makeSetTR{variant}() -> Set<{swiftType}> {{\n" + " return Set()\n" + "}\n"; var callingCode = new CodeElementCollection <ICodeElement> (); var setID = new CSIdentifier("theSet"); var setDecl = CSVariableDeclaration.VarLine(new CSSimpleType("SwiftSet", false, new CSSimpleType(cstype)), setID, new CSFunctionCall($"TopLevelEntities.MakeSetTR{variant}", false)); var valID = new CSIdentifier("theVal"); var valDecl = CSVariableDeclaration.VarLine(new CSSimpleType(cstype), valID, new CSIdentifier(val)); var containsLine = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("theSet.Contains", (CSIdentifier)val)); var addLine = CSFunctionCall.FunctionCallLine("theSet.Insert", false, valID); var removeLine = CSFunctionCall.FunctionCallLine("theSet.Remove", false, valID); callingCode.Add(setDecl); callingCode.Add(valDecl); callingCode.Add(containsLine); callingCode.Add(addLine); callingCode.Add(containsLine); callingCode.Add(removeLine); callingCode.Add(containsLine); TestRunning.TestAndExecute(swiftCode, callingCode, "False\nTrue\nFalse\n", testName: $"TestSetRemove{variant}"); }
public void TopLevelFunctionAllUnicode1() { string swiftCode = "public func f\x3004() -> Int {\n" + " return 3\n" + "}\n"; var callingCode = new CodeElementCollection <ICodeElement> (); callingCode.Add(CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.FU3004"))); TestRunning.TestAndExecute(swiftCode, callingCode, "3\n"); }
public void NSObjectSubclassableMethodTest3() { string swiftCode = "import Foundation\n" + "@objc\n" + "open class Subclassable3 : NSObject {\n" + " public override init () { }\n" + " open var returnsTrue:Bool {\n" + " get { return true\n } " + " }\n" + "}\n" + "public func callIt (a: Subclassable3) -> Bool {\n" + " return a.returnsTrue\n" + "}\n"; var theSub = new CSClass(CSVisibility.Public, "TheSub3"); var ctor = new CSMethod(CSVisibility.Public, CSMethodKind.None, null, theSub.Name, new CSParameterList(), new CSBaseExpression [0], true, new CSCodeBlock()); theSub.Constructors.Add(ctor); theSub.Inheritance.Add(new CSIdentifier("Subclassable3")); var theBody = new CSCodeBlock(); theBody.Add(CSReturn.ReturnLine(CSConstant.Val(false))); LineCodeElementCollection <ICodeElement> getCode = new LineCodeElementCollection <ICodeElement> ( new ICodeElement [] { CSReturn.ReturnLine(CSConstant.Val(false)) }, false, true); CSProperty returnsFalse = new CSProperty(CSSimpleType.Bool, CSMethodKind.Override, new CSIdentifier("ReturnsTrue"), CSVisibility.Public, new CSCodeBlock(getCode), CSVisibility.Public, null); theSub.Properties.Add(returnsFalse); var callingCode = new CodeElementCollection <ICodeElement> (); var objID = new CSIdentifier("subTest"); var objDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, objID, new CSFunctionCall("TheSub3", true)); var call = CSFunctionCall.ConsoleWriteLine(objID.Dot((CSIdentifier)"ReturnsTrue")); var call2 = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.CallIt", objID)); callingCode.Add(objDecl); callingCode.Add(call); callingCode.Add(call2); TestRunning.TestAndExecute(swiftCode, callingCode, "False\nFalse\n", otherClass: theSub, platform: PlatformName.macOS); }
public void UnicodeInOperatorName() { string swiftCode = "infix operator \x2295\x2295\n" + "public func \x2295\x2295 (left:Int, right: Int) -> Int {\n" + " return left + right\n" + "}\n"; var callingCode = new CodeElementCollection <ICodeElement> { CSVariableDeclaration.VarLine((CSSimpleType)"nint", "x", CSFunctionCall.Function("TopLevelEntities.InfixOperatorCirclePlusCirclePlus", CSConstant.Val(3), CSConstant.Val(4))), CSFunctionCall.ConsoleWriteLine((CSIdentifier)"x") }; TestRunning.TestAndExecute(swiftCode, callingCode, "7\n"); }
public void OperatorSmokeTest1() { var swiftCode = "prefix operator *-\n" + "public prefix func *- (arg: Int) -> Int {\n" + " return -1 * arg\n" + "}\n"; var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.PrefixOperatorStarMinus", CSConstant.Val(47))); var callingCode = new CodeElementCollection <ICodeElement> { printIt }; TestRunning.TestAndExecute(swiftCode, callingCode, "-47\n"); }
public void OperatorSmokeTest2() { var swiftCode = "postfix operator -*\n" + "public postfix func -* (arg: Int) -> Int {\n" + " return -1 * arg\n" + "}\n"; var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.PostfixOperatorMinusStar", CSConstant.Val(88))); var callingCode = new CodeElementCollection <ICodeElement> { printIt }; TestRunning.TestAndExecute(swiftCode, callingCode, "-88\n"); }
public void OperatorSmokeTest3() { var swiftCode = "postfix operator ^^\n" + "public postfix func ^^ (arg: String) -> String {\n" + " return \"//\" + arg + \"//\"\n" + "}\n"; var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.PostfixOperatorHatHat", CSFunctionCall.Function("SwiftString.FromString", CSConstant.Val("nothing")))); var callingCode = new CodeElementCollection <ICodeElement> { printIt }; TestRunning.TestAndExecute(swiftCode, callingCode, "//nothing//\n"); }
public void OperatorSmokeTest0() { var swiftCode = "import Darwin\n" + "infix operator ** : MultiplicationPrecedence\n" + "public func ** (left: Double, right: Double) -> Double {\n" + " return pow(left, right)\n" + "}\n"; var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.InfixOperatorStarStar", CSConstant.Val(2.0), CSConstant.Val(8.0))); var callingCode = new CodeElementCollection <ICodeElement> { printIt }; TestRunning.TestAndExecute(swiftCode, callingCode, "256\n"); }
public void WrapVirtClassNonVirtMethod() { string swiftCode = "open class VirtClassNVM {\n" + " public init() { }\n" + " public func returns17() -> Int {\n" + " return 17" + " }\n" + "}\n"; var decl = CSVariableDeclaration.VarLine(new CSSimpleType("VirtClassNVM"), "cl", new CSFunctionCall("VirtClassNVM", true)); var printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("cl.Returns17")); var callingCode = CSCodeBlock.Create(decl, printer); TestRunning.TestAndExecute(swiftCode, callingCode, "17\n"); }
public void UnicodeInStructName() { string swiftCode = "public struct s\x1800 {\n" + " public init() { }\n" + " public func doIt() -> Int {\n" + " return 3\n" + " }\n" + "}\n"; var callingCode = new CodeElementCollection <ICodeElement> { CSVariableDeclaration.VarLine((CSSimpleType)"SU1800", "st", CSFunctionCall.Ctor("SU1800")), CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("st.DoIt")) }; TestRunning.TestAndExecute(swiftCode, callingCode, "3\n"); }
public void UnicodeInClassNameAndMethod() { string swiftCode = "public class cc1\x1800 {\n" + " public init() { }\n" + " public func doIt\x3004() -> Int {\n" + " return 3\n" + " }\n" + "}\n"; var callingCode = new CodeElementCollection <ICodeElement> { CSVariableDeclaration.VarLine((CSSimpleType)"Cc1U1800", "cl", CSFunctionCall.Ctor("Cc1U1800")), CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("cl.DoItU3004")) }; TestRunning.TestAndExecute(swiftCode, callingCode, "3\n"); }
public void EmptyProtocolTest() { var swiftCode = @" public protocol ThisServesAsATrait { } public func isThisATrait (a: ThisServesAsATrait) -> Bool { return true; } "; var auxClass = new CSClass(CSVisibility.Public, "Traitor"); auxClass.Inheritance.Add(new CSIdentifier("IThisServesAsATrait")); var decl = CSVariableDeclaration.VarLine(CSSimpleType.Var, "trait", new CSFunctionCall("Traitor", true)); var printIt = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.IsThisATrait", new CSIdentifier("trait"))); var callingCode = CSCodeBlock.Create(decl, printIt); TestRunning.TestAndExecute(swiftCode, callingCode, "True\n", otherClass: auxClass); }
void ClosureSumFunc(string swiftType, string csVal1, string csVal2, string output, bool escaping) { string escapingAttribute = escaping ? "@escaping" : ""; string swiftCode = $"public func sumIt{swiftType}{escaping}(a:{swiftType}, b:{swiftType}, f:{escapingAttribute}({swiftType},{swiftType})->{swiftType}) -> {swiftType} {{\n" + " return f(a, b)\n" + "}"; CodeElementCollection <ICodeElement> callingCode = new CodeElementCollection <ICodeElement> (); CSCodeBlock body = new CSCodeBlock(); body.Add(CSReturn.ReturnLine(new CSIdentifier("val1") + new CSIdentifier("val2"))); CSLine invoker = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function($"TopLevelEntities.SumIt{swiftType}{escaping}", (CSIdentifier)csVal1, (CSIdentifier)csVal2, new CSLambda(body, "val1", "val2"))); callingCode.Add(invoker); TestRunning.TestAndExecute(swiftCode, callingCode, output, testName: $"ClosureSumFunc{swiftType}{escaping}"); }
void ClosureConstantFunc(string appendage, string swiftType, string csVal, string output, bool escaping) { appendage += escaping.ToString(); string escapingAttribute = escaping ? "@escaping" : ""; string swiftCode = $"public func callClosureCCF{appendage}(f:{escapingAttribute}()->{swiftType}) -> {swiftType} {{\n" + " return f()\n" + "}"; CodeElementCollection <ICodeElement> callingCode = new CodeElementCollection <ICodeElement> (); CSCodeBlock body = new CSCodeBlock(); body.Add(CSReturn.ReturnLine(new CSIdentifier(csVal))); CSLine invoker = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function($"TopLevelEntities.CallClosureCCF{appendage}", new CSLambda(body))); callingCode.Add(invoker); TestRunning.TestAndExecute(swiftCode, callingCode, output, testName: $"ClosureConstantFunc{appendage}"); }
void WrapOptionalReturn(string type1, string cstype1, string val1, string expected, bool isFinal = true, string distinguisher = "") { string finalStr = isFinal ? "final" : ""; string staticStr = isFinal ? "static" : ""; string appendage = (type1 + expected).Replace('.', '_').Replace('\n', '_').Replace(' ', '_') + distinguisher; string swiftCode = $"public {finalStr} class MontyWOR{appendage} {{ public init() {{ }}\n public {staticStr} func makeOpt() -> {type1}?\n {{\n return {val1};\n }}\n }}\n"; CSLine csopt = CSVariableDeclaration.VarLine(new CSSimpleType("SwiftOptional", false, new CSSimpleType(cstype1)), "opt", new CSFunctionCall(isFinal ? $"MontyWOR{appendage}.MakeOpt" : $"new MontyWOR{appendage}().MakeOpt", false)); CSLine printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("opt.ToString")); CSCodeBlock callingCode = CSCodeBlock.Create(csopt, printer); TestRunning.TestAndExecute(swiftCode, callingCode, expected, testName: $"WrapOptionalReturn{type1}{distinguisher}"); }
public void NSObjectObjCMethodTest1() { string swiftCode = "import Foundation\n" + "@objc\n" + "open class ItsLessSimple : NSObject {\n" + " public override init () { }\n" + " @objc open func returns15() -> Int {\n" + " return 15\n" + " }\n" + "}\n"; var objID = new CSIdentifier("obj"); var objDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, objID, CSFunctionCall.Ctor("ItsLessSimple")); var printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function(objID.Name + ".Returns15")); var callingCode = CSCodeBlock.Create(objDecl, printer); TestRunning.TestAndExecute(swiftCode, callingCode, "15\n", platform: PlatformName.macOS); }
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"); }
void ClosureClassTest(string appendage, string swiftType, string csVal, string output, bool escaping) { appendage += escaping.ToString(); string escapingAttribute = escaping ? "@escaping" : ""; string swiftCode = $"public final class FooCCT{appendage} {{\n" + " public init() { }\n" + $" public func runIt(f:{escapingAttribute}()->{swiftType}) -> {swiftType}\n" + "{ return f(); }\n" + "}"; CodeElementCollection <ICodeElement> callingCode = new CodeElementCollection <ICodeElement> (); callingCode.Add(CSVariableDeclaration.VarLine(new CSSimpleType($"FooCCT{appendage}"), new CSIdentifier("x"), new CSFunctionCall($"FooCCT{appendage}", true))); CSLine invoker = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("x.RunIt", new CSLambda((CSIdentifier)csVal))); callingCode.Add(invoker); TestRunning.TestAndExecute(swiftCode, callingCode, output, testName: $"ClosureClassTest{appendage}"); }
public void WrapOptionalVirtMethod() { string swiftCode = "open class OptMethClass {\n" + " private var x:Int? = 17\n" + " public init () {\n" + " }\n" + " open func referenceFunc () -> Int? {\n" + " return x\n" + " }" + "}\n"; var classID = new CSIdentifier("cl"); var classDecl = CSVariableDeclaration.VarLine(new CSSimpleType("OptMethClass"), classID, new CSFunctionCall("OptMethClass", true)); var printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("cl.ReferenceFunc")); var callingCode = CSCodeBlock.Create(classDecl, printer); TestRunning.TestAndExecute(swiftCode, callingCode, "17\n", platform: PlatformName.macOS); }
void WrapGenStructReturnFunc(string appendage, string cstype, string val1, string expected) { string swiftCode = $"public struct BarWGSRF{appendage} {{\npublic var X:Int32 = 0;\npublic init(x:Int32) {{\n X = x;\n}}\n}}\n" + $"public struct FooWGSRF{appendage}<T> {{\nprivate var x:Int = 5\npublic init() {{ }}\npublic func Func(a:T)-> T {{\nreturn a;\n}}\n}}\n"; CSLine fooDecl = CSVariableDeclaration.VarLine(new CSSimpleType($"FooWGSRF{appendage}", false, new CSSimpleType(cstype)), "foo", new CSFunctionCall($"FooWGSRF{appendage}<{cstype}>", true, new CSFunctionCall("SwiftNominalCtorArgument", true))); CSLine printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("foo.Func", (CSIdentifier)val1)); CSCodeBlock callingCode = CSCodeBlock.Create(fooDecl, printer); TestRunning.TestAndExecute(swiftCode, callingCode, expected, testName: $"WrapGenStructReturnFunc{appendage}"); }
void WrapGenPrivField(string cstype, string val1, string expected) { string swiftCode = $"public struct BarWGPV{cstype} {{\npublic var X:Int32 = 0;\npublic init(x:Int32) {{\n X = x;\n}}\n}}\n" + $"public struct FooWGPV{cstype}<T> {{\nprivate var x:T\npublic init(a:T) {{\nx = a\n }}\n}}\n"; CSSimpleType fooType = new CSSimpleType($"FooWGPV{cstype}", false, cstype); CSLine fooDecl = CSVariableDeclaration.VarLine(new CSSimpleType($"FooWGPV{cstype}", false, new CSSimpleType(cstype)), "foo", new CSFunctionCall(fooType.ToString(), true, new CSIdentifier(val1))); CSLine printer = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("StructMarshal.Marshaler.Sizeof", CSFunctionCall.Function("foo.GetType"))); CSCodeBlock callingCode = CSCodeBlock.Create(fooDecl, printer); TestRunning.TestAndExecute(swiftCode, callingCode, expected, testName: $"WrapGenPrivField{cstype}"); }
static void UnicodeTestCore(string expectedName, bool runOnDevice, UnicodeMapper unicodeMapper) { string SwiftCode = @"public final class Mapple { public static func 🍎 () -> Int { return 42; } }"; CodeElementCollection <ICodeElement> callingCode = new CodeElementCollection <ICodeElement> (); callingCode.Add(CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function($"Mapple.{expectedName}"))); if (runOnDevice) { TestRunning.TestAndExecute(SwiftCode, callingCode, "42\n", testName: $"EndToEndUnicodeMapping{expectedName}", unicodeMapper: unicodeMapper); } else { TestRunning.TestAndExecuteNoDevice(SwiftCode, callingCode, "42\n", testName: $"EndToEndUnicodeMapping{expectedName}", unicodeMapper: unicodeMapper); } }
public void NSObjectSubclassableMethodTest1() { string swiftCode = "import Foundation\n" + "@objc\n" + "open class Subclassable1 : NSObject {\n" + " public override init () { }\n" + " open func returnsTrue () -> Bool {\n" + " return true\n" + " }\n" + "}\n"; var callingCode = new CodeElementCollection <ICodeElement> (); var objID = new CSIdentifier("subTest"); var objDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, objID, new CSFunctionCall("Subclassable1", true)); var call = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("subTest.ReturnsTrue")); callingCode.Add(objDecl); callingCode.Add(call); TestRunning.TestAndExecute(swiftCode, callingCode, "True\n", platform: PlatformName.macOS); }
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"); }