public void PropertyRegionTest() { const string code = "class T {\n\tint Prop {\n\t\tget { return f; }\n\t\tset { f = value; }\n\t}\n}\n"; int line2Pos = code.IndexOf("\tint Prop"); int line3Pos = code.IndexOf("\t\tget"); int line4Pos = code.IndexOf("\t\tset"); CSharpParser parser = new CSharpParser(); CompilationUnit cu = parser.Parse(new StringReader(code)); PropertyDeclaration pd = (PropertyDeclaration)cu.Children.Single().GetChildByRole(TypeDeclaration.MemberRole); Assert.AreEqual(new AstLocation(2, code.IndexOf("{\n\t\tget") - line2Pos + 1), pd.GetChildByRole(AstNode.Roles.LBrace).StartLocation); Assert.AreEqual(new AstLocation(5, 3), pd.EndLocation); Assert.AreEqual(new AstLocation(3, code.IndexOf("{ return") - line3Pos + 1), pd.Getter.Body.StartLocation); Assert.AreEqual(new AstLocation(3, code.IndexOf("}\n\t\tset") + 1 - line3Pos + 1), pd.Getter.Body.EndLocation); Assert.AreEqual(new AstLocation(4, code.IndexOf("{ f =") - line4Pos + 1), pd.Setter.Body.StartLocation); Assert.AreEqual(new AstLocation(4, code.IndexOf("}\n\t}") + 1 - line4Pos + 1), pd.Setter.Body.EndLocation); }
public void PropertyRegionTest() { const string code = "class T {\n\tint Prop {\n\t\tget { return f; }\n\t\tset { f = value; }\n\t}\n}\n"; int line2Pos = code.IndexOf("\tint Prop"); int line3Pos = code.IndexOf("\t\tget"); int line4Pos = code.IndexOf("\t\tset"); CSharpParser parser = new CSharpParser(); SyntaxTree syntaxTree = parser.Parse(code); PropertyDeclaration pd = (PropertyDeclaration)syntaxTree.Children.Single(c => c.Role != Roles.NewLine).GetChildByRole(Roles.TypeMemberRole); Assert.AreEqual(new TextLocation(2, code.IndexOf("{\n\t\tget") - line2Pos + 1), pd.GetChildByRole(Roles.LBrace).StartLocation); Assert.AreEqual(new TextLocation(5, 3), pd.EndLocation); Assert.AreEqual(new TextLocation(3, code.IndexOf("{ return") - line3Pos + 1), pd.Getter.Body.StartLocation); Assert.AreEqual(new TextLocation(3, code.IndexOf("}\n\t\tset") + 1 - line3Pos + 1), pd.Getter.Body.EndLocation); Assert.AreEqual(new TextLocation(4, code.IndexOf("{ f =") - line4Pos + 1), pd.Setter.Body.StartLocation); Assert.AreEqual(new TextLocation(4, code.IndexOf("}\n\t}") + 1 - line4Pos + 1), pd.Setter.Body.EndLocation); }