예제 #1
0
 public void TestContains_Reflexive() {
     var xml = @"class Foo {
         int Bar(){return 0;}
     }";
     LibSrcMLRunner run = new LibSrcMLRunner();
     string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { }, false);
     var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Class).First();
     var classLoc = new SrcMLLocation(classElement, "Foo.cs");
     Assert.IsTrue(classLoc.Contains(classLoc));
 }
예제 #2
0
        public static XElement GetElement(SrcMLArchive archive, SrcMLLocation location)
        {
            string fileName = location.SourceFileName;
            string query    = location.XPath;

            var unit    = archive.GetXElementForSourceFile(fileName);
            var element = unit.XPathSelectElement(query, SrcMLNamespaces.Manager);

            return(element);
        }
예제 #3
0
 public static bool LocationsAreEqual(SrcMLLocation a, SrcMLLocation b)
 {
     if (a == b)
     {
         return(true);
     }
     return(a.IsReference == b.IsReference &&
            a.StartingColumnNumber == b.StartingColumnNumber &&
            a.SourceFileName == b.SourceFileName &&
            a.StartingLineNumber == b.StartingLineNumber &&
            a.XPath == b.XPath);
 }
예제 #4
0
        public void TestContains_Reflexive() {
            ////Foo.cs
            //class Foo {
            //    int Bar(){return 0;}
            //}
            var xml = @"<class pos:line=""1"" pos:column=""1"">class <name pos:line=""1"" pos:column=""7"">Foo</name> <block pos:line=""1"" pos:column=""11"">{
    <function><type><name pos:line=""2"" pos:column=""5"">int</name></type> <name pos:line=""2"" pos:column=""9"">Bar</name><parameter_list pos:line=""2"" pos:column=""12"">()</parameter_list><block pos:line=""2"" pos:column=""14"">{<return pos:line=""2"" pos:column=""15"">return <expr><lit:literal type=""number"" pos:line=""2"" pos:column=""22"">0</lit:literal></expr>;</return>}</block></function>
}</block></class>";
            var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Class).First();
            var classLoc = new SrcMLLocation(classElement, "Foo.cs");
            Assert.IsTrue(classLoc.Contains(classLoc));
        }
예제 #5
0
        public static XElement GetElement(ISrcMLArchive archive, SrcMLLocation location)
        {
            string fileName = location.SourceFileName;
            string query    = location.XPath;

            var unit = archive.GetXElementForSourceFile(fileName);

            var startingLength = fileName.Length + 23;
            var path           = query.Substring(startingLength);
            var element        = unit.XPathSelectElement(path, SrcMLNamespaces.Manager);

            return(element);
        }
예제 #6
0
        public void TestContains_Reflexive()
        {
            var            xml   = @"class Foo {
                int Bar(){return 0;}
            }";
            LibSrcMLRunner run   = new LibSrcMLRunner();
            string         srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection <UInt32>()
            {
            }, false);
            var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Class).First();
            var classLoc     = new SrcMLLocation(classElement, "Foo.cs");

            Assert.IsTrue(classLoc.Contains(classLoc));
        }
        public void TestContains_Reflexive()
        {
            ////Foo.cs
            //class Foo {
            //    int Bar(){return 0;}
            //}
            var xml          = @"<class pos:line=""1"" pos:column=""1"">class <name pos:line=""1"" pos:column=""7"">Foo</name> <block pos:line=""1"" pos:column=""11"">{
    <function><type><name pos:line=""2"" pos:column=""5"">int</name></type> <name pos:line=""2"" pos:column=""9"">Bar</name><parameter_list pos:line=""2"" pos:column=""12"">()</parameter_list><block pos:line=""2"" pos:column=""14"">{<return pos:line=""2"" pos:column=""15"">return <expr><lit:literal type=""number"" pos:line=""2"" pos:column=""22"">0</lit:literal></expr>;</return>}</block></function>
}</block></class>";
            var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Class).First();
            var classLoc     = new SrcMLLocation(classElement, "Foo.cs");

            Assert.IsTrue(classLoc.Contains(classLoc));
        }
예제 #8
0
 public void TestContains_TwoLevel() {
     var xml = @"namespace Example {
         class Foo {
             int Bar(){return 0;}
         }
     }";
     LibSrcMLRunner run = new LibSrcMLRunner();
     string srcML = run.GenerateSrcMLFromString(xml, "Example.cs", Language.CSharp, new Collection<UInt32>() { }, false);
     var namespaceElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Example.cs").Element(SRC.Namespace);
     var methodElement = namespaceElement.Descendants(SRC.Function).First();
     var namespaceLoc = new SrcMLLocation(namespaceElement, "Example.cs");
     var methodLoc = new SrcMLLocation(methodElement, "Example.cs");
     Assert.IsTrue(namespaceLoc.Contains(methodLoc));
 }
예제 #9
0
 public void TestContains_Sibling() {
     var xml = @"class Foo {
         string Bar(){
             string a = 'Hello, world!';
             return a;
         }
         int Baz(){ return 0; }
     }";
     LibSrcMLRunner run = new LibSrcMLRunner();
     string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { }, false);
     var methodElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Function).First();
     var declElement = methodElement.Descendants(SRC.DeclarationStatement).First();
     var methodLoc = new SrcMLLocation(methodElement, "Foo.cs");
     var declLoc = new SrcMLLocation(declElement, "Foo.cs");
     Assert.IsTrue(methodLoc.Contains(declLoc));
 }
예제 #10
0
        public void TestContains_TwoLevel()
        {
            var            xml   = @"namespace Example {
                class Foo {
                    int Bar(){return 0;}
                }
            }";
            LibSrcMLRunner run   = new LibSrcMLRunner();
            string         srcML = run.GenerateSrcMLFromString(xml, "Example.cs", Language.CSharp, new Collection <UInt32>()
            {
            }, false);
            var namespaceElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Example.cs").Element(SRC.Namespace);
            var methodElement    = namespaceElement.Descendants(SRC.Function).First();
            var namespaceLoc     = new SrcMLLocation(namespaceElement, "Example.cs");
            var methodLoc        = new SrcMLLocation(methodElement, "Example.cs");

            Assert.IsTrue(namespaceLoc.Contains(methodLoc));
        }
예제 #11
0
        public void TestContains_Sibling()
        {
            var            xml   = @"class Foo {
                string Bar(){
                    string a = 'Hello, world!';
                    return a;
                }
                int Baz(){ return 0; }
            }";
            LibSrcMLRunner run   = new LibSrcMLRunner();
            string         srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection <UInt32>()
            {
            }, false);
            var methodElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Function).First();
            var declElement   = methodElement.Descendants(SRC.DeclarationStatement).First();
            var methodLoc     = new SrcMLLocation(methodElement, "Foo.cs");
            var declLoc       = new SrcMLLocation(declElement, "Foo.cs");

            Assert.IsTrue(methodLoc.Contains(declLoc));
        }
예제 #12
0
 private static void LocationsAreEqual(SrcMLLocation expected, SrcMLLocation actual, string propertyName)
 {
     if (expected != actual)
     {
         try {
             IsTrue(expected != null, "expected!null");
             IsTrue(actual != null, "actual!null");
             IsTrue(expected.IsReference == actual.IsReference, "IsReference");
             IsTrue(expected.SourceFileName == actual.SourceFileName, "SourceFileName");
             IsTrue(expected.StartingLineNumber == actual.StartingLineNumber, "StartingLineNumber");
             IsTrue(expected.StartingColumnNumber == actual.StartingColumnNumber, "StartingColumnNumber");
             IsTrue(expected.EndingLineNumber == actual.EndingLineNumber, "EndingLineNumber");
             IsTrue(expected.EndingColumnNumber == actual.EndingColumnNumber, "EndingColumnNumber");
             IsTrue(expected.XPath == actual.XPath, "XPath");
         } catch (DataAssertionException e) {
             e.Add(propertyName);
             throw e;
         }
     }
 }
        public void TestContains_TwoLevel()
        {
            ////Example.cs
            //namespace Example {
            //    class Foo {
            //        int Bar(){return 0;}
            //    }
            //}
            var xml = @"<namespace pos:line=""1"" pos:column=""1"">namespace <name pos:line=""1"" pos:column=""11"">Example</name> <block pos:line=""1"" pos:column=""19"">{
    <class pos:line=""2"" pos:column=""5"">class <name pos:line=""2"" pos:column=""11"">Foo</name> <block pos:line=""2"" pos:column=""15"">{
        <function><type><name pos:line=""3"" pos:column=""9"">int</name></type> <name pos:line=""3"" pos:column=""13"">Bar</name><parameter_list pos:line=""3"" pos:column=""16"">()</parameter_list><block pos:line=""3"" pos:column=""18"">{<return pos:line=""3"" pos:column=""19"">return <expr><lit:literal type=""number"" pos:line=""3"" pos:column=""26"">0</lit:literal></expr>;</return>}</block></function>
    }</block></class>
}</block></namespace>";
            var namespaceElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Example.cs").Element(SRC.Namespace);
            var methodElement    = namespaceElement.Descendants(SRC.Function).First();
            var namespaceLoc     = new SrcMLLocation(namespaceElement, "Example.cs");
            var methodLoc        = new SrcMLLocation(methodElement, "Example.cs");

            Assert.IsTrue(namespaceLoc.Contains(methodLoc));
        }
예제 #14
0
        public void TestContains_Sibling() {
            ////Foo.cs
            //class Foo {
            //    string Bar(){
            //        string a = "Hello, world!";
            //        return a;
            //    }
            //    int Baz(){ return 0; }
            //}
            var xml = @"<class pos:line=""1"" pos:column=""1"">class <name pos:line=""1"" pos:column=""7"">Foo</name> <block pos:line=""1"" pos:column=""11"">{
    <function><type><name pos:line=""2"" pos:column=""5"">string</name></type> <name pos:line=""2"" pos:column=""12"">Bar</name><parameter_list pos:line=""2"" pos:column=""15"">()</parameter_list><block pos:line=""2"" pos:column=""17"">{
        <decl_stmt><decl><type><name pos:line=""3"" pos:column=""9"">string</name></type> <name pos:line=""3"" pos:column=""16"">a</name> =<init pos:line=""3"" pos:column=""19""> <expr><lit:literal type=""string"" pos:line=""3"" pos:column=""20"">""Hello, world!""</lit:literal></expr></init></decl>;</decl_stmt>
        <return pos:line=""4"" pos:column=""9"">return <expr><name pos:line=""4"" pos:column=""16"">a</name></expr>;</return>
    }</block></function>
    <function><type><name pos:line=""6"" pos:column=""5"">int</name></type> <name pos:line=""6"" pos:column=""9"">Baz</name><parameter_list pos:line=""6"" pos:column=""12"">()</parameter_list><block pos:line=""6"" pos:column=""14"">{ <return pos:line=""6"" pos:column=""16"">return <expr><lit:literal type=""number"" pos:line=""6"" pos:column=""23"">0</lit:literal></expr>;</return> }</block></function>
}</block></class>";
            var methodElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Function).First();
            var declElement = methodElement.Descendants(SRC.DeclarationStatement).First();
            var methodLoc = new SrcMLLocation(methodElement, "Foo.cs");
            var declLoc = new SrcMLLocation(declElement, "Foo.cs");
            Assert.IsTrue(methodLoc.Contains(declLoc));
        }
        public void TestContains_Sibling()
        {
            ////Foo.cs
            //class Foo {
            //    string Bar(){
            //        string a = "Hello, world!";
            //        return a;
            //    }
            //    int Baz(){ return 0; }
            //}
            var xml           = @"<class pos:line=""1"" pos:column=""1"">class <name pos:line=""1"" pos:column=""7"">Foo</name> <block pos:line=""1"" pos:column=""11"">{
    <function><type><name pos:line=""2"" pos:column=""5"">string</name></type> <name pos:line=""2"" pos:column=""12"">Bar</name><parameter_list pos:line=""2"" pos:column=""15"">()</parameter_list><block pos:line=""2"" pos:column=""17"">{
        <decl_stmt><decl><type><name pos:line=""3"" pos:column=""9"">string</name></type> <name pos:line=""3"" pos:column=""16"">a</name> =<init pos:line=""3"" pos:column=""19""> <expr><lit:literal type=""string"" pos:line=""3"" pos:column=""20"">""Hello, world!""</lit:literal></expr></init></decl>;</decl_stmt>
        <return pos:line=""4"" pos:column=""9"">return <expr><name pos:line=""4"" pos:column=""16"">a</name></expr>;</return>
    }</block></function>
    <function><type><name pos:line=""6"" pos:column=""5"">int</name></type> <name pos:line=""6"" pos:column=""9"">Baz</name><parameter_list pos:line=""6"" pos:column=""12"">()</parameter_list><block pos:line=""6"" pos:column=""14"">{ <return pos:line=""6"" pos:column=""16"">return <expr><lit:literal type=""number"" pos:line=""6"" pos:column=""23"">0</lit:literal></expr>;</return> }</block></function>
}</block></class>";
            var methodElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Function).First();
            var declElement   = methodElement.Descendants(SRC.DeclarationStatement).First();
            var methodLoc     = new SrcMLLocation(methodElement, "Foo.cs");
            var declLoc       = new SrcMLLocation(declElement, "Foo.cs");

            Assert.IsTrue(methodLoc.Contains(declLoc));
        }
예제 #16
0
 /// <summary>
 /// Tests that two locations are identical
 /// </summary>
 /// <param name="expected">The expected location</param>
 /// <param name="actual">The actual location</param>
 public static void LocationsAreEqual(SrcMLLocation expected, SrcMLLocation actual)
 {
     LocationsAreEqual(expected, actual, string.Empty);
 }
예제 #17
0
        public void TestContains_TwoLevel() {
            ////Example.cs
            //namespace Example {
            //    class Foo {
            //        int Bar(){return 0;}
            //    }
            //}
            var xml = @"<namespace pos:line=""1"" pos:column=""1"">namespace <name pos:line=""1"" pos:column=""11"">Example</name> <block pos:line=""1"" pos:column=""19"">{
    <class pos:line=""2"" pos:column=""5"">class <name pos:line=""2"" pos:column=""11"">Foo</name> <block pos:line=""2"" pos:column=""15"">{
        <function><type><name pos:line=""3"" pos:column=""9"">int</name></type> <name pos:line=""3"" pos:column=""13"">Bar</name><parameter_list pos:line=""3"" pos:column=""16"">()</parameter_list><block pos:line=""3"" pos:column=""18"">{<return pos:line=""3"" pos:column=""19"">return <expr><lit:literal type=""number"" pos:line=""3"" pos:column=""26"">0</lit:literal></expr>;</return>}</block></function>
    }</block></class>
}</block></namespace>";
            var namespaceElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Example.cs").Element(SRC.Namespace);
            var methodElement = namespaceElement.Descendants(SRC.Function).First();
            var namespaceLoc = new SrcMLLocation(namespaceElement, "Example.cs");
            var methodLoc = new SrcMLLocation(methodElement, "Example.cs");
            Assert.IsTrue(namespaceLoc.Contains(methodLoc));
        }