public void AssertDiffType(string prevgenFilename, string userFilename, string templateFilename, TypeOfDiff typeOfDiff) { CodeRoot prevgen = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, prevgenFilename)); CodeRoot template = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, templateFilename)); CodeRoot user = GetCodeRoot(Path.Combine(RESOURCES_FOLDER, userFilename)); CodeRootMap map = new CodeRootMap(); if (prevgen != null) { map.AddCodeRoot(prevgen, Version.PrevGen); } if (template != null) { map.AddCodeRoot(template, Version.NewGen); } if (user != null) { map.AddCodeRoot(user, Version.User); } TypeOfDiff diff = map.Diff(); Assert.That(diff, Is.EqualTo(typeOfDiff)); }
private CodeRootMap CreateBasicMap(out Class cl2) { CodeRootMap map = new CodeRootMap(); Class cl = new Class(controller, "Class1"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.PrevGen); cl = new Class(controller, "Class1"); ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); cl2 = new Class(controller, "Class2"); ns.AddChild(cl2); root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.NewGen); return(map); }
public void Constant() { Constant con = new Constant(controller); con.DataType = new DataType(controller, "int"); con.Modifiers.Add("public"); con.Name = "CONSTANT1"; con.Expression = "5"; CodeRoot root = CreateClassAndNamespace(con); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "public const int CONSTANT1 = 5;"); }
public void Enumeration() { Enumeration inter = new Enumeration(controller); inter.Name = "File"; inter.Modifiers.Add("public"); inter.Members.Add(new Enumeration.EnumMember(controller, "Read")); inter.Members.Add(new Enumeration.EnumMember(controller, "Write")); CodeRoot root = CreateClassAndNamespace(inter); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assert.That(result.Contains("Read"), Is.True, "Contains Read enum value"); Assert.That(result.Contains("Write"), Is.True, "Contains Write enum value"); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "Read"); Assertions.StringContains(result, "Write"); Assertions.StringContains(result, "public enum File"); }
private CodeRoot GetPrevGenOrNewGenRoot() { Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); // Create another class to match to the user one. Class c3 = new Class(controller, "Class3"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c3); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return(root); }
public void Matching_Successful() { CodeRootMap map = new CodeRootMap(); CodeRoot userroot = CreateBasicRoot(); map.AddCodeRoot(userroot, Version.User); CodeRoot prevroot = CreateBasicRoot(); map.AddCodeRoot(prevroot, Version.PrevGen); CodeRoot templateroot = CreateBasicRoot(); map.AddCodeRoot(templateroot, Version.NewGen); string result = map.GetMergedCodeRoot().ToString(); Assertions.StringContains(result, "class Class1", 1); Assertions.StringContains(result, "namespace ArchAngel.Tests", 1); map.MatchConstructs(map.GetExactNode(userroot.Namespaces[0]), userroot.Namespaces[0].Classes[0], null, prevroot.Namespaces[0].Classes[0]); map.Diff(); Assert.That(map.ChildNodes[0].ChildNodes, Has.Count(2)); Assert.That(map.ChildNodes[0].ChildNodes[0].DetermineMissingConstructs(), Is.EqualTo(MissingObject.User | MissingObject.PrevGen)); Assert.That(map.ChildNodes[0].ChildNodes[1].DetermineMissingConstructs(), Is.EqualTo(MissingObject.NewGen)); ICodeRoot merged = map.GetMergedCodeRoot(); result = merged.ToString(); Assertions.StringContains(result, "class Class1", 2); Assertions.StringContains(result, "namespace ArchAngel.Tests", 1); }
public void InterfaceProperty() { InterfaceProperty inter = new InterfaceProperty(controller, "InterfaceProperty1"); inter.Name = "File"; inter.DataType = new DataType(controller, "int"); InterfaceAccessor acc = new InterfaceAccessor(controller); acc.AccessorType = InterfaceAccessor.AccessorTypes.Get; inter.AddChild(acc); acc = new InterfaceAccessor(controller); acc.AccessorType = InterfaceAccessor.AccessorTypes.Set; inter.AddChild(acc); CodeRoot root = CreateNamespaceAndInterface(inter); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "public interface Interface1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "int File"); Assertions.StringContains(result, "get;"); Assertions.StringContains(result, "set;"); }
public void Indexer_Renamed_Params() { CodeRoot root = CreateIndexer("i"); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); CodeRoot userRoot = CreateIndexer("i1"); map.AddCodeRoot(userRoot, Version.User); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.Not.EqualTo(root.ToString())); Assert.That(result, Is.EqualTo(userRoot.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "int this [int i1]"); Assertions.StringContains(result, "get{ return file[i]; }"); Assertions.StringContains(result, "set{ file[i] = value; }"); }
public void Class() { Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); }
protected CodeRoot CreateClassAndNamespace(IEnumerable <IBaseConstruct> children) { Class cl = new Class(controller, "Class1"); foreach (IBaseConstruct child in children) { cl.AddChild(child); } cl.Index = 10; AttributeSection attrs = new AttributeSection(controller); attrs.Index = 5; Attribute attr = new Attribute(controller); attr.Index = 6; attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Index = 0; ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot userRoot = new CodeRoot(controller); userRoot.AddChild(ns); return(userRoot); }
private static List <Function> GetFunctionsInFileWithAttribute(string file, string attributeName) { List <Function> functions = new List <Function>(); string code = Slyce.Common.Utility.ReadTextFile(file); CSharpParser csf = new CSharpParser(); csf.FormatSettings.CommentLinesAsCommentBlock = true; csf.ParseCode(code); if (csf.ErrorOccurred) { // TODO: what do we do here? throw new Exception("Parser error. Please contact [email protected]"); } CodeRoot root = (CodeRoot)csf.CreatedCodeRoot; foreach (Namespace ns in root.Namespaces) { foreach (Class c in ns.Classes) { functions.AddRange(GetFunctionsInClassWithAttribute(c, attributeName)); } } foreach (Class c in root.Classes) { functions.AddRange(GetFunctionsInClassWithAttribute(c, attributeName)); } return(functions); }
public void Nested_Regions_Around_A_Method() { const string code = @" public class Class1 { #region DEBUG #region DEBUG2 public void Method1() { } #endregion #endregion } "; const string expected = @" public class Class1 { #region DEBUG #region DEBUG2 public void Method1() { } #endregion #endregion }"; CSharpParser parser = TestFullText(code, expected); CodeRoot codeRoot = (CodeRoot)parser.CreatedCodeRoot; Assert.That(codeRoot.Classes[0].Functions.Count, Is.EqualTo(1), "Should be able to access functions inside nested regions from the class."); Assert.That(codeRoot.Classes[0].Functions[0].Name, Is.EqualTo("Method1")); }
public void Constructor() { Constructor constructor = new Constructor(controller); constructor.Modifiers.Add("public"); constructor.Name = "Class1"; constructor.BodyText = "{ }"; Parameter param = new Parameter(controller); param.Name = "i"; param.DataType = "int"; constructor.Parameters.Add(param); CodeRoot root = CreateClassAndNamespace(constructor); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "public Class1"); Assertions.StringContains(result, "{ }"); }
public void Delegate() { Delegate inter = new Delegate(controller); inter.Name = "File"; inter.Modifiers.Add("public"); inter.ReturnType = new DataType(controller, "int"); Parameter param = new Parameter(controller); param.Name = "i"; param.DataType = "int"; inter.Parameters.Add(param); CodeRoot root = CreateClassAndNamespace(inter); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "public delegate int File"); }
protected CodeRoot CreateFunctionAndClass(string functionParameterName, out Function createdFunction) { createdFunction = CreateFunction(FunctionName, functionParameterName, 10); CodeRoot userRoot = CreateClassAndNamespace(createdFunction); return(userRoot); }
public Namespace(Controller controller, BaseConstruct parentObject, string name, CodeRoot parentCodeRoot, CodeLanguage language, int nodeIndex) : this(controller) { ParentObject = parentObject; Name = name; ParentCodeRoot = parentCodeRoot; Language = language; Index = nodeIndex; }
public void Matching_Successful() { controller.Reorder = true; Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); Class c2 = new Class(controller, "Class2"); // Extra class in user AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c2); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.PrevGen); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.NewGen); bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3"); Assert.That(matchResult, Is.True); string result = map.GetMergedCodeRoot().ToString(); Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly)); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "Class2"); Assertions.StringContains(result, "Class3", 0); int count = 0; foreach (CodeRootMapNode node in map.AllNodes) { if (node.IsTheSameReference(c2)) { count++; } } Assert.That(count, Is.EqualTo(1)); }
public void MatchesSavedSuccessfully() { XmlDocument doc = new XmlDocument(); Controller controller = new CSharpController(); controller.Reorder = true; CodeRootMap map = new CodeRootMap(); CodeRoot userCR = new CodeRoot(controller); CodeRoot newgenCR = new CodeRoot(controller); CodeRoot prevgenCR = new CodeRoot(controller); Class clazz = new Class(controller, "Class1"); clazz.AddChild(new Class(controller, "InnerClass")); userCR.AddChild(clazz); clazz = new Class(controller, "Class2"); clazz.AddChild(new Class(controller, "InnerClass")); newgenCR.AddChild(clazz); clazz = new Class(controller, "Class3"); clazz.AddChild(new Class(controller, "InnerClass")); prevgenCR.AddChild(clazz); map.AddCodeRoot(userCR, Version.User); map.AddCodeRoot(newgenCR, Version.NewGen); map.AddCodeRoot(prevgenCR, Version.PrevGen); Assert.That(map.MatchConstructs("Class1", "Class2", "Class3"), "Matching constructs", Is.True); CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor(); processor.SaveCustomMappings(doc, map, "Test.cs"); XmlNodeList nodes = doc.SelectNodes("Manifest/Mappings/CodeRootMappings/CodeRootMap"); Assert.IsNotNull(nodes, "Couldn't find the CodeRootMap nodes"); Assert.That(nodes.Count, Is.EqualTo(1)); Assert.That(nodes.Item(0).Attributes["filename"].Value, Is.EqualTo("Test.cs")); XmlNode mappingElement = nodes.Item(0); XmlNode userNode = mappingElement.SelectSingleNode(ManifestConstants.UserObjectElement); XmlNode newgNode = mappingElement.SelectSingleNode(ManifestConstants.NewGenObjectElement); XmlNode prevNode = mappingElement.SelectSingleNode(ManifestConstants.PrevGenObjectElement); Assert.That(userNode, Is.Not.Null); Assert.That(newgNode, Is.Not.Null); Assert.That(prevNode, Is.Not.Null); Assert.That(userNode.InnerText, Is.EqualTo("Class1")); Assert.That(newgNode.InnerText, Is.EqualTo("Class2")); Assert.That(prevNode.InnerText, Is.EqualTo("Class3")); }
public void AddParsedFile(string filename, CodeRoot codeRoot) { parsedFiles.Add(filename, codeRoot); foreach (var topLevelClass in codeRoot.Classes) { parsedClasses.Add("", topLevelClass); } ProcessNewNamespaces("", codeRoot.Namespaces); }
protected CodeRoot CreateBasicRoot() { Class cl = new Class(controller, "Class1"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return root; }
public void PrevGen_Is_Skipped_Where_No_Template_Or_User_Exist() { Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); Class c2 = new Class(controller, "Class2"); // Extra class in prevgen AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c2); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.PrevGen); cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); attrs = new AttributeSection(controller); attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); // make sure that the deleted class Class2 was not included int he merged code root. Assertions.StringContains(result, "Class2", 0); }
protected CodeRoot CreateFieldAndClass(string fieldName, out Field createdField) { createdField = new Field(controller); createdField.Name = fieldName; createdField.Modifiers.Add("public"); createdField.DataType = new DataType(controller, "int"); createdField.InitialValue = "5"; CodeRoot userRoot = CreateClassAndNamespace(createdField); return(userRoot); }
protected CodeRoot CreateBasicRoot() { Class cl = new Class(controller, "Class1"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return(root); }
public void Function() { CodeRootMap map = new CodeRootMap(); CodeRoot root = CreateFunctionAndClass("i"); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "public int GetVal(int i)"); Assertions.StringContains(result, "{ return 5; }"); }
public void InterfaceMethod() { CodeRoot root = CreateInterfaceAndMethod("i"); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "public interface Interface1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "int Method1 (int i);"); }
public void Attributes() { AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); CodeRoot root = new CodeRoot(controller); root.AddChild(attrs); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "[Serializable(true)]"); }
public void Operator() { CodeRoot root = CreateClassAndOperator("i"); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "public static int operator +(Class1 self, int i)"); Assertions.StringContains(result, "{ return 5; }"); }
public void User_Is_Missing_Others_Are_Exact_Copy() { Function func = new Function(controller); func.Name = "Method1"; func.Modifiers.Add("public"); func.ReturnType = new DataType(controller, "void"); func.BodyText = "{ }"; Class cl = new Class(controller, "Class1"); cl.AddChild(func); cl.IsPartial = true; cl.GenericTypes.Add("T"); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.PrevGen); map.AddCodeRoot(root, Version.NewGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "public void Method1()"); Assertions.StringContains(result, "{ }"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); }
public void UsingStatements() { CodeRoot root = CreateClassAndNamespace(new IBaseConstruct[0]); UsingStatement st = new UsingStatement(controller, "", "System"); st.Index = 0; root.AddChild(st); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "using System;"); }
public void EmptyPlaceholder() { EmptyPlaceholder inter = new EmptyPlaceholder(controller, "asdfasd", 2); CodeRoot root = CreateClassAndNamespace(inter); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "asdfasd", 0); }
protected CodeRoot ConstructRootWithClass(IBaseConstruct childOfClass) { Class cl = new Class(controller, "Class1"); cl.AddChild(childOfClass); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return(root); }
public void Test_Script_Base_Class() { string resourcePath = "Resources/CSharp/ScriptBase.cs".Replace('/', Path.DirectorySeparatorChar); string fileText = File.ReadAllText(resourcePath); CSharpParser parser = new CSharpParser(); parser.ParseCode(fileText); if (parser.ErrorOccurred) { Assert.Fail("Parsing failed"); } CodeRoot codeRoot = (CodeRoot)parser.CreatedCodeRoot; Namespace ns = codeRoot.Namespaces[0]; Class scriptBase = ns.Classes[0]; Assert.That(scriptBase.Functions.Count, Is.EqualTo(13)); }
public VBController() { Root = new CodeRoot(this); dict = new Dictionary<Type, Func<IPrintable, IPrinter>>() { {typeof (Attribute), bc => new VBAttributePrinter(bc as Attribute)}, {typeof (AttributeSection), bc => new VBAttributeSectionPrinter(bc as AttributeSection)}, {typeof (BaseConstruct), bc => new VBBaseConstructPrinter(bc as BaseConstruct)}, {typeof (Class), bc => new VBClassPrinter(bc as Class)}, {typeof (CodeRoot), bc => new VBCodeRootPrinter(bc as CodeRoot)}, {typeof (Constant), bc => new VBConstantPrinter(bc as Constant)}, {typeof (Constructor), bc => new VBConstructorPrinter(bc as Constructor)}, {typeof (DataType), bc => new VBDataTypePrinter(bc as DataType)}, {typeof (Delegate), bc => new VBDelegatePrinter(bc as Delegate)}, {typeof (Destructor), bc => new VBDestructorPrinter(bc as Destructor)}, {typeof (EmptyPlaceholder), bc => new VBEmptyPlaceholderPrinter(bc as EmptyPlaceholder)}, {typeof (Enumeration), bc => new VBEnumerationPrinter(bc as Enumeration)}, {typeof (Event), bc => new VBEventPrinter(bc as Event)}, {typeof (Field), bc => new VBFieldPrinter(bc as Field)}, {typeof (Function), bc => new VBFunctionPrinter(bc as Function)}, {typeof (Indexer), bc => new VBIndexerPrinter(bc as Indexer)}, {typeof (Interface), bc => new VBInterfacePrinter(bc as Interface)}, {typeof (InterfaceAccessor), bc => new VBInterfaceAccessorPrinter(bc as InterfaceAccessor)}, {typeof (InterfaceEvent), bc => new VBInterfaceEventPrinter(bc as InterfaceEvent)}, {typeof (InterfaceIndexer), bc => new VBInterfaceIndexerPrinter(bc as InterfaceIndexer)}, {typeof (InterfaceMethod), bc => new VBInterfaceMethodPrinter(bc as InterfaceMethod)}, {typeof (InterfaceProperty), bc => new VBInterfacePropertyPrinter(bc as InterfaceProperty)}, {typeof (Namespace), bc => new VBNamespacePrinter(bc as Namespace)}, {typeof (Operator), bc => new VBOperatorPrinter(bc as Operator)}, {typeof (Parameter), bc => new VBParameterPrinter(bc as Parameter)}, {typeof (Property), bc => new VBPropertyPrinter(bc as Property)}, {typeof (PropertyAccessor), bc => new VBPropertyAccessorPrinter(bc as PropertyAccessor)}, {typeof (Region), bc => new VBRegionPrinter(bc as Region)}, {typeof (RegionStart), bc => new VBRegionStartPrinter(bc as RegionStart)}, {typeof (RegionEnd), bc => new VBRegionEndPrinter(bc as RegionEnd)}, {typeof (Struct), bc => new VBStructPrinter(bc as Struct)}, {typeof (UsingStatement), bc => new VBUsingStatementPrinter(bc as UsingStatement)}, }; }
private CodeRootMap CreateBasicMap(out Class cl2) { CodeRootMap map = new CodeRootMap(); Class cl = new Class(controller, "Class1"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.PrevGen); cl = new Class(controller, "Class1"); ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); cl2 = new Class(controller, "Class2"); ns.AddChild(cl2); root = new CodeRoot(controller); root.AddChild(ns); map.AddCodeRoot(root, Version.NewGen); return map; }
protected CodeRoot CreateNamespaceAndInterface(IBaseConstruct inter) { Interface interface1 = new Interface(controller, "Interface1"); interface1.Modifiers.Add("public"); interface1.AddChild(inter); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); interface1.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(interface1); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return root; }
public VBCodeRootPrinter(CodeRoot obj) { this.obj = obj; }
public void Namespace() { Namespace inter = new Namespace(controller); inter.Name = "ArchAngel.Tests"; inter.AddChild(new UsingStatement(controller, "", "System")); CodeRoot root = new CodeRoot(controller); root.AddChild(inter); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); map.AddCodeRoot(root, Version.NewGen); map.AddCodeRoot(root, Version.PrevGen); string result = map.GetMergedCodeRoot().ToString(); Assert.That(result, Is.EqualTo(root.ToString())); Assertions.StringContains(result, "using System"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); }
protected CodeRoot ConstructRootWithClass(IBaseConstruct childOfClass) { Class cl = new Class(controller, "Class1"); cl.AddChild(childOfClass); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return root; }
protected CodeRoot CreateClassAndNamespace(IEnumerable<IBaseConstruct> children) { Class cl = new Class(controller, "Class1"); foreach(IBaseConstruct child in children) cl.AddChild(child); cl.Index = 10; AttributeSection attrs = new AttributeSection(controller); attrs.Index = 5; Attribute attr = new Attribute(controller); attr.Index = 6; attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Index = 0; ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); CodeRoot userRoot = new CodeRoot(controller); userRoot.AddChild(ns); return userRoot; }
public CodeRootBaseConstructAdapter(CodeRoot wrappedCodeRoot) : base(wrappedCodeRoot.Controller) { this.wrappedCodeRoot = wrappedCodeRoot; }
public override void Reset() { Root = new CodeRoot(this); }
public void Matching_Successful() { controller.Reorder = true; Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); Class c2 = new Class(controller, "Class2"); // Extra class in user AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c2); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); CodeRootMap map = new CodeRootMap(); map.AddCodeRoot(root, Version.User); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.PrevGen); root = GetPrevGenOrNewGenRoot(); map.AddCodeRoot(root, Version.NewGen); bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3"); Assert.That(matchResult, Is.True); string result = map.GetMergedCodeRoot().ToString(); Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly)); Assertions.StringContains(result, "class Class1"); Assertions.StringContains(result, "[Serializable(true)]"); Assertions.StringContains(result, "namespace ArchAngel.Tests"); Assertions.StringContains(result, "Class2"); Assertions.StringContains(result, "Class3", 0); int count = 0; foreach (CodeRootMapNode node in map.AllNodes) { if (node.IsTheSameReference(c2)) count++; } Assert.That(count, Is.EqualTo(1)); }
private CodeRoot GetPrevGenOrNewGenRoot() { Class cl = new Class(controller, "Class1"); cl.IsPartial = true; cl.GenericTypes.Add("T"); AttributeSection attrs = new AttributeSection(controller); Attribute attr = new Attribute(controller); attr.PositionalArguments.Add("true"); attr.Name = "Serializable"; attrs.AddAttribute(attr); cl.AddAttributeSection(attrs); // Create another class to match to the user one. Class c3 = new Class(controller, "Class3"); Namespace ns = new Namespace(controller); ns.Name = "ArchAngel.Tests"; ns.AddChild(cl); ns.AddChild(c3); CodeRoot root = new CodeRoot(controller); root.AddChild(ns); return root; }
public void Matching_Successful() { CodeRootMap map = new CodeRootMap(); Class cl = new Class(controller, "Class1"); Namespace ns1 = new Namespace(controller); ns1.Name = "ArchAngel.Tests"; ns1.AddChild(cl); CodeRoot root = new CodeRoot(controller); root.AddChild(ns1); map.AddCodeRoot(root, Version.User); cl = new Class(controller, "Class1"); Namespace ns2 = new Namespace(controller); ns2.Name = "Slyce.Tests"; ns2.AddChild(cl); root = new CodeRoot(controller); root.AddChild(ns2); map.AddCodeRoot(root, Version.PrevGen); cl = new Class(controller, "Class1"); Namespace ns3 = new Namespace(controller); ns3.Name = "Slyce.Tests"; ns3.AddChild(cl); root = new CodeRoot(controller); root.AddChild(ns3); map.AddCodeRoot(root, Version.NewGen); map.MatchConstructs(map, ns1, ns3, ns2); foreach (CodeRootMapNode child in map.AllNodes) { Assert.That(child.PrevGenObj, Is.Not.Null, string.Format("PrevGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName)); Assert.That(child.NewGenObj, Is.Not.Null, string.Format("NewGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName)); Assert.That(child.UserObj, Is.Not.Null, string.Format("User in {0} is null", child.GetFirstValidBaseConstruct().ShortName)); } string result = map.GetMergedCodeRoot().ToString(); Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly)); Assertions.StringContains(result, "class Class1", 1); Assertions.StringContains(result, "namespace ArchAngel.Tests", 1); Assertions.StringContains(result, "namespace Slyce.Tests", 0); int count = 0; foreach (CodeRootMapNode node in map.AllNodes) { if (node.IsTheSameReference(ns1)) count++; } Assert.That(count, Is.EqualTo(1)); }