void FindsProperty(string code, Func <ClassDeclaration, bool> classFinder, Func <PropertyDeclaration, bool> propFinder) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); var errors = new ErrorHandling(); ModuleInventory mi = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(classFinder); Assert.IsNotNull(classDecl, "null class"); PropertyDeclaration propDecl = classDecl.Members.OfType <PropertyDeclaration> ().FirstOrDefault(propFinder); Assert.IsNotNull(propDecl, "null property"); FunctionDeclaration getter = propDecl.GetGetter(); Assert.IsNotNull(getter, "null getter"); FunctionDeclaration setter = propDecl.GetSetter(); Assert.IsNotNull(setter, "null setter"); TLFunction tlgetter = XmlToTLFunctionMapper.ToTLFunction(getter, mi); Assert.IsNotNull(tlgetter, "null tlgetter"); TLFunction tlsetter = XmlToTLFunctionMapper.ToTLFunction(setter, mi); Assert.IsNotNull(tlsetter, "null tlsetter"); }
public void FindsPropertyGetterAndSetterFuncs() { string code = "public class Bar { public var x:Int = 0; }"; CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(cl => cl.Name == "Bar"); Assert.IsNotNull(classDecl); PropertyDeclaration propDecl = classDecl.Members.OfType <PropertyDeclaration> ().FirstOrDefault(p => p.Name == "x"); Assert.IsNotNull(propDecl); FunctionDeclaration getter = propDecl.GetGetter(); Assert.IsNotNull(getter); FunctionDeclaration setter = propDecl.GetSetter(); Assert.IsNotNull(setter); }
void CanFindThing(string code, Func <ClassDeclaration, bool> classFinder, Func <FunctionDeclaration, bool> funcFinder, Func <TLFunction, bool> tlVerifier) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); var errors = new ErrorHandling(); ModuleInventory mi = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(classFinder); Assert.IsNotNull(classDecl, "nominal type not found"); FunctionDeclaration funcDecl = classDecl.AllMethodsNoCDTor().FirstOrDefault(funcFinder); Assert.IsNotNull(funcDecl, "func decl not found"); // see the note in the implementation of CanFindThing above TLFunction func = XmlToTLFunctionMapper.ToTLFunction(funcDecl, mi, null); Assert.IsNotNull(func, "TLFunction not found"); Assert.IsTrue(tlVerifier(func), "verifier failed"); }
void CanFindThing(string code, Func <FunctionDeclaration, bool> funcFinder, Func <TLFunction, bool> tlVerifier) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); var errors = new ErrorHandling(); ModuleInventory mi = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; FunctionDeclaration funcDecl = mod.Functions.FirstOrDefault(funcFinder); Assert.IsNotNull(funcDecl, "no function found"); TLFunction func = XmlToTLFunctionMapper.ToTLFunction(funcDecl, mi); Assert.IsNotNull(func, $"failed to find TLFunction for {funcDecl.Name}"); Assert.IsTrue(tlVerifier(func), "verifier failed"); }
void CanFindThing(string code, Func <FunctionDeclaration, bool> funcFinder, Func <TLFunction, bool> tlVerifier) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind"); var errors = new ErrorHandling(); ModuleInventory mi = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors); ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath }, new string [] { compiler.DirectoryPath }, null, "CanFind") [0]; FunctionDeclaration funcDecl = mod.Functions.FirstOrDefault(funcFinder); Assert.IsNotNull(funcDecl, "no function found"); // note: if you get an NRE from here then you are testing an argument that includes // an associated type path from a generic. Don't do that. You need much more infrastructure to // do that than you really want here. TLFunction func = XmlToTLFunctionMapper.ToTLFunction(funcDecl, mi, null); Assert.IsNotNull(func, $"failed to find TLFunction for {funcDecl.Name}"); Assert.IsTrue(tlVerifier(func), "verifier failed"); }
List <ModuleDeclaration> ReflectToModules(string code, string moduleName) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: moduleName); return(compiler.ReflectToModules(null, null, null, moduleName)); }
Stream ReflectToXml(string code, string moduleName) { CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: moduleName); return(compiler.ReflectToStream(null, null, null, moduleName)); }