diff --git a/ABB.SrcML.Data.Test/BuiltInTypeFactoryTests.cs b/ABB.SrcML.Data.Test/BuiltInTypeFactoryTests.cs index 1c77d73..48b7c19 100644 --- a/ABB.SrcML.Data.Test/BuiltInTypeFactoryTests.cs +++ b/ABB.SrcML.Data.Test/BuiltInTypeFactoryTests.cs @@ -40,7 +40,7 @@ public void ClassSetup() { [Category("Todo")] public void TestCppBuiltIns_WithDoubleWord() { // #a.cpp #example: "unsigned int a;"; MODIFIER TYPE a; MODIFIER TYPE b; - string xmlFormat = @"{0} {1} a; {0} {1} b"; + string xmlFormat = @"{0} {1} a; {0} {1} b;"; foreach(var builtInModifier in new string[] { "unsigned", "signed", "long" }) { foreach(var builtIn in new string[] { "int", "double" }) { @@ -98,7 +98,7 @@ from declaration in stmt.GetExpressions().OfType() [Test] public void TestJavaBuiltIns() { // #a.java TYPE a; TYPE b; - string xmlFormat = @"TYPE a; TYPE b;"; + string xmlFormat = @"{0} a; {0} b;"; foreach(var builtIn in new string[] { "byte", "short", "int", "long", "float", "double", "boolean", "char" }) { LibSrcMLRunner run = new LibSrcMLRunner(); diff --git a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs index f4c5721..77c3ecc 100644 --- a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs @@ -17,29 +17,25 @@ using System.Linq; using System.Xml.Linq; -namespace ABB.SrcML.Data.Test -{ +namespace ABB.SrcML.Data.Test { [TestFixture] [Category("Build")] - public class CPlusPlusCodeParserTests - { + public class CPlusPlusCodeParserTests { private AbstractCodeParser codeParser; private SrcMLFileUnitSetup fileSetup; [TestFixtureSetUp] - public void ClassSetup() - { + public void ClassSetup() { codeParser = new CPlusPlusCodeParser(); fileSetup = new SrcMLFileUnitSetup(Language.CPlusPlus); } [Test] - public void TestCreateTypeDefinitions_Class() - { - string xml = "class A { };"; + public void TestCreateTypeDefinitions_Class() { + string xml = @"class A { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -54,11 +50,10 @@ public void TestCreateTypeDefinitions_Class() } [Test] - public void TestCreateTypeDefinitions_ClassDeclaration() - { - string xml = "class A;"; + public void TestCreateTypeDefinitions_ClassDeclaration() { + string xml = @"class A;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -73,14 +68,13 @@ public void TestCreateTypeDefinitions_ClassDeclaration() } [Test] - public void TestClassWithDeclaredVariable() - { - string xml = "class A {" + - " int a;" + - "};"; + public void TestClassWithDeclaredVariable() { + string xml = @"class A { + int a; + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -102,14 +96,13 @@ public void TestClassWithDeclaredVariable() [Test] - public void TestFreeStandingBlock() - { - string xml = "{" + - " int foo = 42;" + - " MethodCall(foo);" + - "}"; + public void TestFreeStandingBlock() { + string xml = @"{ + int foo = 42; + MethodCall(foo); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -126,11 +119,10 @@ public void TestFreeStandingBlock() } [Test] - public void TestExternStatement_Single() - { + public void TestExternStatement_Single() { string xml = "extern \"C\" int MyGlobalVar;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -144,14 +136,10 @@ public void TestExternStatement_Single() } [Test] - public void TestExternStatement_Block() - { - string xml = "extern \"C\" {" + - " int globalVar1;" + - " int globalVar2;" + - "}"; + public void TestExternStatement_Block() { + string xml = "extern \"C\" {\n int globalVar1; \nint globalVar2;}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -165,15 +153,14 @@ public void TestExternStatement_Block() } [Test] - public void TestConstructor_CallToSelf() - { - string xml = "class MyClass {" + - "public:" + - " MyClass() : MyClass(0) { } " + - " MyClass(int foo) { } " + - "};"; + public void TestConstructor_CallToSelf() { + string xml = @"class MyClass { + public: + MyClass() : MyClass(0) { } + MyClass(int foo) { } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(unit); @@ -194,16 +181,15 @@ public void TestConstructor_CallToSelf() } [Test] - public void TestConstructor_CallToSuperClass() - { - string xml = "class SuperClass {" + - "public:" + - "SuperClass(int foo) { } }; " + - "class SubClass : public SuperClass {" + - "public:" + - "SubClass(int foo) : SuperClass(foo) { } };"; + public void TestConstructor_CallToSuperClass() { + string xml = @"class SuperClass { + public: + SuperClass(int foo) { } }; + class SubClass : public SuperClass { + public: + SubClass(int foo) : SuperClass(foo) { } };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(unit); @@ -222,17 +208,16 @@ public void TestConstructor_CallToSuperClass() } [Test] - public void TestConstructor_InitializeBuiltinTypeField() - { + public void TestConstructor_InitializeBuiltinTypeField() { //"test.h" - string xml = "class Quux" + - "{" + - " int _my_int;" + - "public:" + - " Quux() : _my_int(5) { }" + - "};"; + string xml = @"class Quux + { + int _my_int; + public: + Quux() : _my_int(5) { } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -252,22 +237,21 @@ public void TestConstructor_InitializeBuiltinTypeField() } [Test] - public void TestConstructor_InitializeField() - { + public void TestConstructor_InitializeField() { //"test.h" - string xml = "class Foo" + - "{" + - "public:" + - " Foo(int a) { }" + - "};" + - "class Bar" + - "{" + - " Foo baz;" + - "public:" + - " Bar() : baz(42) { }" + - "};"; - LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string xml = @"class Foo + { + public: + Foo(int a) { } + }; + class Bar + { + Foo baz; + public: + Bar() : baz(42) { } + };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -283,12 +267,11 @@ public void TestConstructor_InitializeField() } [Test] - public void TestCreateAliasesForFiles_ImportClass() - { - string xml = "using A::Foo;"; + public void TestCreateAliasesForFiles_ImportClass() { + string xml = @"using A::Foo;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -302,12 +285,11 @@ public void TestCreateAliasesForFiles_ImportClass() } [Test] - public void TestCreateAliasesForFiles_ImportNamespace() - { - string xml = "using namespace x::y::z;"; + public void TestCreateAliasesForFiles_ImportNamespace() { + string xml = @"using namespace x::y::z;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -320,12 +302,11 @@ public void TestCreateAliasesForFiles_ImportNamespace() [Test] [Category("SrcMLUpdate")] - public void TestCreateAliasesForFiles_TypeAlias() - { - string xml = "using x = foo::bar::baz;"; + public void TestCreateAliasesForFiles_TypeAlias() { + string xml = @"using x = foo::bar::baz;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -338,24 +319,23 @@ public void TestCreateAliasesForFiles_TypeAlias() } [Test] - public void TestGetImports() - { + public void TestGetImports() { //A.cpp - string xmlA = "namespace x {" + - " namespace y {" + - " namespace z {}" + - " }" + - "}"; + string xmlA = @"namespace x { + namespace y { + namespace z {} + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using namespace x::y::z;" + - "foo = 17;"; + string xmlB = @"using namespace x::y::z; + foo = 17;"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -376,15 +356,14 @@ public void TestGetImports() } [Test] - public void TestGetImports_NestedImportNamespace() - { - string xml = "using namespace x::y::z;" + - "if(bar) {" + - " using namespace std;" + - " foo = 17;" + - "}"; + public void TestGetImports_NestedImportNamespace() { + string xml = @"using namespace x::y::z; + if(bar) { + using namespace std; + foo = 17; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -398,26 +377,25 @@ public void TestGetImports_NestedImportNamespace() } [Test] - public void TestGetAliases_NestedImportClass() - { + public void TestGetAliases_NestedImportClass() { //A.cpp - string xmlA = "namespace B {" + - " class Bar {}" + - "}"; + string xmlA = @"namespace B { + class Bar {} + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using namespace x::y::z;" + - "if(bar) {" + - " using B::Bar;" + - " foo = 17;" + - "}"; + string xmlB = @"using namespace x::y::z; + if(bar) { + using B::Bar; + foo = 17; + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -442,15 +420,14 @@ public void TestGetAliases_NestedImportClass() [Test] [Category("SrcMLUpdate")] - public void TestGetAliases_NestedTypeAlias() - { - string xml = "using namespace x::y::z;" + - "if(bar) {" + - " using x = foo::bar::baz;" + - " foo = 17;" + - "}"; + public void TestGetAliases_NestedTypeAlias() { + string xml = @"using namespace x::y::z; + if(bar) { + using x = foo::bar::baz; + foo = 17; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -459,43 +436,43 @@ public void TestGetAliases_NestedTypeAlias() Assert.IsNotNull(foo); var aliases = foo.GetAliases().ToList(); Assert.AreEqual(1, aliases.Count); - Assert.AreEqual("foo :: bar :: baz", aliases[0].Target.ToString()); + + Assert.AreEqual("foo::bar::baz", aliases[0].Target.ToString()); //This toString calls typeuse TODO: Anything wrong here? Assert.AreEqual("x", aliases[0].AliasName); var imports = foo.GetImports().ToList(); - Assert.AreEqual("x :: y :: z", imports[0].ImportedNamespace.ToString()); + Assert.AreEqual("x :: y :: z", imports[0].ImportedNamespace.ToString()); //this tostring calls expression TODO: Anything wrong here? } [Test] - public void TestImport_NameResolution() - { + public void TestImport_NameResolution() { //A.cpp - string xmlA = "using namespace Foo::Bar;" + + string xmlA = @"using namespace Foo::Bar; // - "namespace A {" + - " class Robot {" + - " public: " + - " Baz GetThingy() { " + - " Baz* b = new Baz();" + - " return *b;" + - " }" + - " }" + - "}"; + namespace A { + class Robot { + public: + Baz GetThingy() { + Baz* b = new Baz(); + return *b; + } + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "namespace Foo {" + - " namespace Bar {" + - " class Baz {" + - " public:" + - " Baz() { }" + - " }" + - "}"; + string xmlB = @"namespace Foo { + namespace Bar { + class Baz { + public: + Baz() { } + } + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -520,34 +497,33 @@ public void TestImport_NameResolution() } [Test] - public void TestAlias_NameResolution_ImportType() - { + public void TestAlias_NameResolution_ImportType() { //A.cpp - string xmlA = "namespace Foo {" + - " namespace Bar {" + - " class Baz {" + - " public:" + - " static void DoTheThing() { }" + - " }" + - "}"; + string xmlA = @"namespace Foo { + namespace Bar { + class Baz { + public: + static void DoTheThing() { } + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using Foo::Bar::Baz;" + - "namespace A {" + - " class B {" + - " public:" + - " B() {" + - " Baz::DoTheThing();" + - " }" + - " }" + - "}"; + string xmlB = @"using Foo::Bar::Baz; + namespace A { + class B { + public: + B() { + Baz::DoTheThing(); + } + } + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -570,32 +546,31 @@ public void TestAlias_NameResolution_ImportType() [Test] [Category("SrcMLUpdate")] - public void TestAlias_NameResolution_TypeAlias() - { + public void TestAlias_NameResolution_TypeAlias() { //A.cpp - string xmlA = "namespace Foo {" + - " namespace Bar {" + - " class Baz {" + - " public:" + - " static void DoTheThing() { }" + - " }" + - "}"; + string xmlA = @"namespace Foo { + namespace Bar { + class Baz { + public: + static void DoTheThing() { } + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using X = Foo::Bar::Baz;" + - "namespace A {" + - " class B {" + - " public:" + - " B() {" + - " X::DoTheThing();" + - " }" + - " }" + - "}"; + string xmlB = @"using X = Foo::Bar::Baz; + namespace A { + class B { + public: + B() { + X::DoTheThing(); + } + } + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -617,12 +592,11 @@ public void TestAlias_NameResolution_TypeAlias() } [Test] - public void TestCreateTypeDefinition_ClassInNamespace() - { - string xml = "namespace A { class B { }; }"; + public void TestCreateTypeDefinition_ClassInNamespace() { + string xml = @"namespace A { class B { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLB = runA.GenerateSrcMLFromString(xml, "B.h", Language.CSharp, new Collection() { }, false); + string srcMLB = runA.GenerateSrcMLFromString(xml, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.h"); @@ -637,14 +611,13 @@ public void TestCreateTypeDefinition_ClassInNamespace() } [Test] - public void TestCreateTypeDefinition_ClassWithMethodDeclaration() - { - string xml = " class A {" + - " public:" + - " int foo(int a); };"; + public void TestCreateTypeDefinition_ClassWithMethodDeclaration() { + string xml = @" class A { + public: + int foo(int a); };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -661,14 +634,13 @@ public void TestCreateTypeDefinition_ClassWithMethodDeclaration() } [Test] - public void TestCreateTypeDefinition_StaticMethod() - { - string xml = "class Example {" + - "public:" + - " static int Example::Foo(int bar) { return bar+1; }" + - "};"; + public void TestCreateTypeDefinition_StaticMethod() { + string xml = @"class Example { + public: + static int Example::Foo(int bar) { return bar+1; } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLstatic_method = runA.GenerateSrcMLFromString(xml, "static_method.h", Language.CSharp, new Collection() { }, false); + string srcMLstatic_method = runA.GenerateSrcMLFromString(xml, "static_method.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLstatic_method, "static_method.h"); var globalScope = codeParser.ParseFileUnit(fileUnit); @@ -684,12 +656,11 @@ public void TestCreateTypeDefinition_StaticMethod() [Test] - public void TestCreateTypeDefinitions_ClassInFunction() - { - string xml = "int main() { class A { }; }"; + public void TestCreateTypeDefinitions_ClassInFunction() { + string xml = @"int main() { class A { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLmain = runA.GenerateSrcMLFromString(xml, "main.cpp", Language.CSharp, new Collection() { }, false); + string srcMLmain = runA.GenerateSrcMLFromString(xml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLmain, "main.cpp"); var mainMethod = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as MethodDefinition; @@ -703,12 +674,11 @@ public void TestCreateTypeDefinitions_ClassInFunction() } [Test] - public void TestCreateTypeDefinitions_ClassWithInnerClass() - { - string xml = "class A { class B { }; };"; + public void TestCreateTypeDefinitions_ClassWithInnerClass() { + string xml = @"class A { class B { }; };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -723,12 +693,11 @@ public void TestCreateTypeDefinitions_ClassWithInnerClass() } [Test] - public void TestCreateTypeDefinitions_ClassWithParents() - { - string xml = "class A : B,C,D { };"; + public void TestCreateTypeDefinitions_ClassWithParents() { + string xml = @"class A : B,C,D { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -744,19 +713,17 @@ public void TestCreateTypeDefinitions_ClassWithParents() var tests = Enumerable.Zip(new[] { "B", "C", "D" }, parentNames, (e, a) => e == a ); - foreach (var parentMatchesExpected in tests) - { + foreach (var parentMatchesExpected in tests) { Assert.That(parentMatchesExpected); } } [Test] - public void TestCreateTypeDefinitions_ClassWithQualifiedParent() - { - string xml = "class D : A::B::C { }"; + public void TestCreateTypeDefinitions_ClassWithQualifiedParent() { + string xml = @"class D : A::B::C { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLD = runA.GenerateSrcMLFromString(xml, "D.h", Language.CSharp, new Collection() { }, false); + string srcMLD = runA.GenerateSrcMLFromString(xml, "D.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.h"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -778,12 +745,11 @@ public void TestCreateTypeDefinitions_ClassWithQualifiedParent() } [Test] - public void TestCreateTypeDefinitions_InnerClassWithNamespace() - { - string xml = "namespace A { class B { class C { }; }; }"; + public void TestCreateTypeDefinitions_InnerClassWithNamespace() { + string xml = @"namespace A { class B { class C { }; }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -804,12 +770,11 @@ public void TestCreateTypeDefinitions_InnerClassWithNamespace() } [Test] - public void TestCreateTypeDefinitions_Struct() - { - string xml = "struct A { };"; + public void TestCreateTypeDefinitions_Struct() { + string xml = @"struct A { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -821,13 +786,11 @@ public void TestCreateTypeDefinitions_Struct() } [Test] - public void TestCreateTypeDefinitions_Union() - { - string xml = " union A { int a; char b;" + - "};"; + public void TestCreateTypeDefinitions_Union() { + string xml = @" union A { int a; char b; };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -837,12 +800,11 @@ public void TestCreateTypeDefinitions_Union() } [Test] - public void TestGenericVariableDeclaration() - { - string xml = "vector a;"; + public void TestGenericVariableDeclaration() { + string xml = @"vector a;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -858,12 +820,11 @@ public void TestGenericVariableDeclaration() } [Test] - public void TestGenericVariableDeclarationWithPrefix() - { - string xml = "std::vector a;"; + public void TestGenericVariableDeclarationWithPrefix() { + string xml = @"std::vector a;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -881,11 +842,10 @@ public void TestGenericVariableDeclarationWithPrefix() } [Test] - public void TestMethodCallCreation_LengthyCallingExpression() - { - string xml = "a->b.Foo();"; + public void TestMethodCallCreation_LengthyCallingExpression() { + string xml = @"a->b.Foo();"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -915,17 +875,19 @@ public void TestMethodCallCreation_LengthyCallingExpression() } [Test] - public void TestMergeWithUsing() - { - string headerXml = " namespace A { class B { void Foo(); }; }"; + public void TestMergeWithUsing() { + string headerXml = @" namespace A { class B { void Foo(); }; }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string implementationXml = "using namespace A;" + - "void B::Foo() { }"; + string implementationXml = @"using namespace A; void B::Foo() { }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestc = runB.GenerateSrcMLFromString(implementationXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h")); - var implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp")); + var headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h")); + var implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "A.cpp")); var globalScope = headerScope.Merge(implementationScope); Assert.AreEqual(1, globalScope.ChildStatements.OfType().Count()); @@ -943,8 +905,8 @@ public void TestMergeWithUsing() Assert.AreEqual(0, methodFoo.ChildStatements.Count); Assert.AreEqual(2, methodFoo.Locations.Count); - headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h")); - implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp")); + headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h")); + implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "A.cpp")); var globalScope_implementationFirst = implementationScope.Merge(headerScope); @@ -963,25 +925,29 @@ public void TestMergeWithUsing() } [Test] - public void TestMethodCallCreation_WithConflictingMethodNames() - { + public void TestMethodCallCreation_WithConflictingMethodNames() { //# A.h - string a_xml = "class A {" + - " B b;" + - "public:" + - " bool Contains() { b.Contains(); }" + - "};"; + string a_xml = @"class A { + B b; + public: + bool Contains() { b.Contains(); } + };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); //# B.h - string b_xml = "class B {" + - "public:" + - " bool Contains() { return true; }" + - "};"; + string b_xml = @"class B { + public: + bool Contains() { return true; } + };"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(b_xml, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var fileUnitA = fileSetup.GetFileUnitForXmlSnippet(a_xml, "A.h"); - var fileUnitB = fileSetup.GetFileUnitForXmlSnippet(b_xml, "B.h"); + + var fileUnitA = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "A.h"); + var fileUnitB = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "B.h"); var scopeForA = codeParser.ParseFileUnit(fileUnitA); var scopeForB = codeParser.ParseFileUnit(fileUnitB); @@ -1007,18 +973,19 @@ public void TestMethodCallCreation_WithConflictingMethodNames() } [Test] - public void TestMethodCallCreation_WithThisKeyword() - { - string a_xml = "class A {" + - " void Bar() { }" + - " class B {" + - " int a;" + - " void Foo() { this->Bar(); }" + - " void Bar() { return this->a; }" + - " };" + - "};"; + public void TestMethodCallCreation_WithThisKeyword() { + string a_xml = @"class A { + void Bar() { } + class B { + int a; + void Foo() { this->Bar(); } + void Bar() { return this->a; } + }; + };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var fileUnit = fileSetup.GetFileUnitForXmlSnippet(a_xml, "A.cpp"); + var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.cpp"); var globalScope = codeParser.ParseFileUnit(fileUnit); var aDotBar = globalScope.GetNamedChildren("A").First().GetNamedChildren("Bar").FirstOrDefault(); @@ -1038,16 +1005,15 @@ public void TestMethodCallCreation_WithThisKeyword() } [Test] - public void TestMethodCallCreation_GlobalFunction() - { - string xml = "void foo(int a) { printf(a); }" + - "int main() {" + - " foo(5);" + - " return 0;" + - "}"; + public void TestMethodCallCreation_GlobalFunction() { + string xml = @"void foo(int a) { printf(a); } + int main() { + foo(5); + return 0; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1069,25 +1035,24 @@ public void TestMethodCallCreation_GlobalFunction() } [Test] - public void TestMethodCallCreation_CallGlobalNamespace() - { - string xml = "void Foo() {" + - " std::cout<<\"global::Foo\"<() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1117,22 +1082,28 @@ public void TestMethodCallCreation_CallGlobalNamespace() } [Test] - public void TestMethodCallFindMatches() - { - string headerXml = " # A.h class A { int context;" + - " public:" + - " A(); };"; + public void TestMethodCallFindMatches() { + string headerXml = @"class A { int context; + public: + A(); };"; + + string implementationXml = "#include \"A.h\"\n A::A() {}"; + + string mainXml = "#include \"A.h\"\n int main() { A* a = new A(); return 0; }"; + - string implementationXml = " # A.cpp #include \"A.h\"" + - " A: :A() {" + - " }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string mainXml = " # main.cpp #include \"A.h\" int main() { A a = A(); return 0; }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(implementationXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(mainXml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var headerElement = fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h"); - var implementationElement = fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp"); - var mainElement = fileSetup.GetFileUnitForXmlSnippet(mainXml, "main.cpp"); + var headerElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h"); + var implementationElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "A.cpp"); + var mainElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "main.cpp"); var header = codeParser.ParseFileUnit(headerElement); var implementation = codeParser.ParseFileUnit(implementationElement); @@ -1165,25 +1136,27 @@ orderby namedChild.Name } [Test] - public void TestMethodCallFindMatches_WithArguments() - { - string headerXml = " # A.h class A { int context;" + - " public:" + - " A(int value); };"; + public void TestMethodCallFindMatches_WithArguments() { + string headerXml = @"class A { int context; + public: + A(int value); };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string implementationXml = " # A.cpp #include \"A.h\"" + - " A: :A(int value) { context = value;" + - " }"; + string implementationXml = "#include \"A.h\"\n A::A(int value) { context = value;}"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(implementationXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string mainXml = " # main.cpp #include \"A.h\" int main() { int startingState = 0; A *a = new" + - " A(startingState); return startingState; }"; + string mainXml = "#include \"A.h\"\n int main() { int startingState = 0; A *a = new A(startingState);\n return startingState; }"; + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(mainXml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var headerElement = fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h"); - var implementationElement = fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp"); - var mainElement = fileSetup.GetFileUnitForXmlSnippet(mainXml, "main.cpp"); + var headerElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h"); + var implementationElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "A.cpp"); + var mainElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "main.cpp"); var header = codeParser.ParseFileUnit(headerElement); var implementation = codeParser.ParseFileUnit(implementationElement); @@ -1213,13 +1186,12 @@ orderby namedChild.Name } [Test] - public void TestMethodCallMatchToParameter() - { - string xml = "void CallFoo(B b) { b.Foo(); }" + - "class B { void Foo() { } }"; + public void TestMethodCallMatchToParameter() { + string xml = @"void CallFoo(B b) { b.Foo(); } + class B { void Foo() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1241,12 +1213,11 @@ public void TestMethodCallMatchToParameter() } [Test] - public void TestMethodDefinition_ReturnType() - { - string xml = "int Foo() { }"; + public void TestMethodDefinition_ReturnType() { + string xml = @"int Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1263,12 +1234,11 @@ public void TestMethodDefinition_ReturnType() } [Test] - public void TestMethodDefinition_ReturnTypeAndSpecifier() - { - string xml = "static int Foo() { }"; + public void TestMethodDefinition_ReturnTypeAndSpecifier() { + string xml = @"static int Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1282,12 +1252,11 @@ public void TestMethodDefinition_ReturnTypeAndSpecifier() } [Test] - public void TestMethodDefinition_Parameters() - { - string xml = "int Foo(int bar, char baz) { }"; + public void TestMethodDefinition_Parameters() { + string xml = @"int Foo(int bar, char baz) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1302,12 +1271,11 @@ public void TestMethodDefinition_Parameters() } [Test] - public void TestMethodDefinition_VoidParameter() - { - string xml = "void Foo(void) { }"; + public void TestMethodDefinition_VoidParameter() { + string xml = @"void Foo(void) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1320,12 +1288,11 @@ public void TestMethodDefinition_VoidParameter() } [Test] - public void TestMethodDefinition_FunctionPointerParameter() - { - string xml = "int Foo(char bar, int (*pInit)(Quux *theQuux)) {}"; + public void TestMethodDefinition_FunctionPointerParameter() { + string xml = @"int Foo(char bar, int (*pInit)(Quux *theQuux)) {}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1340,12 +1307,11 @@ public void TestMethodDefinition_FunctionPointerParameter() } [Test] - public void TestMethodDefinition_VoidReturn() - { - string xml = "void Foo() { }"; + public void TestMethodDefinition_VoidReturn() { + string xml = @"void Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1358,18 +1324,17 @@ public void TestMethodDefinition_VoidReturn() } [Test] - public void TestMethodDefinition_DefaultArguments() - { - string xml = "void foo(int a = 0);" + - "int main() {" + - " foo();" + - " foo(5);" + - " return 0;" + - "}" + - "void foo(int a) { }"; + public void TestMethodDefinition_DefaultArguments() { + string xml = @"void foo(int a = 0); + int main() { + foo(); + foo(5); + return 0; + } + void foo(int a) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(unit).Merge(new NamespaceDefinition()); @@ -1392,11 +1357,13 @@ public void TestMethodDefinition_DefaultArguments() } [Test] - public void TestTwoVariableDeclarations() - { - string testXml = "int a,b;"; + public void TestTwoVariableDeclarations() { + string testXml = @"int a,b;"; - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(testUnit); @@ -1411,10 +1378,12 @@ public void TestTwoVariableDeclarations() } [Test] - public void TestThreeVariableDeclarations() - { - string testXml = "int a,b,c;"; - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); + public void TestThreeVariableDeclarations() { + string testXml = @"int a,b,c;"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(testUnit); @@ -1431,13 +1400,15 @@ public void TestThreeVariableDeclarations() } [Test] - public void TestVariablesWithSpecifiers() - { - string testXml = "const int A;" + - "static int B;" + - "static const Foo C;" + - "extern Foo D;"; - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); + public void TestVariablesWithSpecifiers() { + string testXml = @"const int A; + static int B; + static const Foo C; + extern Foo D;"; + + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(testUnit); Assert.AreEqual(4, globalScope.ChildStatements.Count); @@ -1468,15 +1439,10 @@ public void TestVariablesWithSpecifiers() } [Test] - public void TestLiteralUse() - { - string xml = "a = 17;" + - "foo = watermelon" + - "if(true) { " + - " c = 'h';" + - "}"; + public void TestLiteralUse() { + string xml = "a = 17; foo = \"watermelon\"; if(true) { c = 'h';}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -1507,16 +1473,15 @@ public void TestLiteralUse() } [Test] - public void TestIfElse() - { - string xml = "if(a==b) {" + - " i = 17;" + - "} else {" + - " i = 42;" + - " ReportError();" + - "}"; + public void TestIfElse() { + string xml = @"if(a==b) { + i = 17; + } else { + i = 42; + ReportError(); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -1528,20 +1493,21 @@ public void TestIfElse() Assert.AreEqual(1, ifStmt.ChildStatements.Count); Assert.AreEqual(2, ifStmt.ElseStatements.Count); } - - [Test] - public void TestIfElseIf() - { - string xml = "if(a==b) {" + - " i = 17;" + - "} else if(a==c) {" + - " i = 42;" + - " foo();" + - "} else {" + - " ReportError();" + - "}"; + /// + /// Test is testing for proper nesting of else and if in srcML archive. + /// + [Test] + public void TestIfElseIf() { + string xml = @"if(a==b) { + i = 17; + } else if(a==c) { + i = 42; + foo(); + } else { + ReportError(); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1551,22 +1517,21 @@ public void TestIfElseIf() Assert.IsNull(ifStmt.Content); Assert.IsNotNull(ifStmt.Condition); Assert.AreEqual(1, ifStmt.ChildStatements.Count); - Assert.AreEqual(1, ifStmt.ElseStatements.Count); + Assert.AreEqual(2, ifStmt.ElseStatements.Count); var ifStmt2 = ifStmt.ElseStatements.First() as IfStatement; Assert.IsNotNull(ifStmt2); Assert.IsNull(ifStmt2.Content); Assert.IsNotNull(ifStmt2.Condition); Assert.AreEqual(2, ifStmt2.ChildStatements.Count); - Assert.AreEqual(1, ifStmt2.ElseStatements.Count); + Assert.AreEqual(0, ifStmt2.ElseStatements.Count); } [Test] - public void TestEmptyStatement() - { - string xml = ";"; + public void TestEmptyStatement() { + string xml = @";"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -1579,11 +1544,10 @@ public void TestEmptyStatement() } [Test] - public void TestVariableUse_Index() - { - string xml = "foo.bar[17];"; + public void TestVariableUse_Index() { + string xml = @"foo.bar[17];"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CSharp, new Collection() { }, false); + string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLa, "a.cpp"); @@ -1608,15 +1572,14 @@ public void TestVariableUse_Index() } [Test] - public void TestResolveVariable_Field() - { - string xml = "class A {" + - "public:" + - " int Foo;" + - " A() { Foo = 42; }" + - "};"; + public void TestResolveVariable_Field() { + string xml = @"class A { + public: + int Foo; + A() { Foo = 42; } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1630,19 +1593,18 @@ public void TestResolveVariable_Field() } [Test] - public void TestResolveVariable_FieldInParent() - { - string xml = "class B {" + - "public:" + - " int Foo;" + - "};" + - "class A : public B {" + - "public:" + - " A() { Foo = 42; }" + - "};"; + public void TestResolveVariable_FieldInParent() { + string xml = @"class B { + public: + int Foo; + }; + class A : public B { + public: + A() { Foo = 42; } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1656,15 +1618,14 @@ public void TestResolveVariable_FieldInParent() } [Test] - public void TestResolveVariable_Global() - { - string xml = "int Foo;" + - "int Bar() {" + - " Foo = 17;" + - "}"; + public void TestResolveVariable_Global() { + string xml = @"int Foo; + int Bar() { + Foo = 17; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1678,17 +1639,16 @@ public void TestResolveVariable_Global() } [Test] - public void TestResolveVariable_VarInNamespace() - { - string xml = "namespace A {" + - " int Foo;" + - " int Bar() {" + - " Foo = 17;" + - " }" + - "}"; + public void TestResolveVariable_VarInNamespace() { + string xml = @"namespace A { + int Foo; + int Bar() { + Foo = 17; + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1702,19 +1662,18 @@ public void TestResolveVariable_VarInNamespace() } [Test] - public void TestResolveVariable_Masking() - { - string xml = "int foo = 17;" + - "int main(int argc, char** argv)" + - "{" + - " std::cout<() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1737,23 +1696,34 @@ public void TestResolveVariable_Masking() } [Test] - public void TestVariableDeclaredInCallingObjectWithParentClass() - { - string a_xml = "class A { B b; };"; + public void TestVariableDeclaredInCallingObjectWithParentClass() { + string a_xml = @"class A { B b; };"; + + string b_xml = @"class B { void Foo() { } };"; + + string c_xml = @"class C : A { };"; + + string d_xml = @"class D { + C c; + void Bar() { c.b.Foo(); } + };"; - string b_xml = "class B { void Foo() { } };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(b_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string c_xml = "class C : A { };"; + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(c_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string d_xml = "class D {" + - " C c;" + - " void Bar() { c.b.Foo(); }" + - "};"; + LibSrcMLRunner runD = new LibSrcMLRunner(); + string srcMLtestd = runD.GenerateSrcMLFromString(d_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var aUnit = fileSetup.GetFileUnitForXmlSnippet(a_xml, "A.h"); - var bUnit = fileSetup.GetFileUnitForXmlSnippet(b_xml, "B.h"); - var cUnit = fileSetup.GetFileUnitForXmlSnippet(c_xml, "C.h"); - var dUnit = fileSetup.GetFileUnitForXmlSnippet(d_xml, "D.h"); + var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h"); + var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "B.h"); + var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "C.h"); + var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestd, "D.h"); var globalScope = codeParser.ParseFileUnit(aUnit); globalScope = globalScope.Merge(codeParser.ParseFileUnit(bUnit)); @@ -1787,16 +1757,15 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() } [Test] - public void TestResolveArrayVariable_Local() - { - string xml = "int Foo() {" + - " if(MethodCall()) {" + - " int* bar = malloc(SIZE);" + - " bar[0] = 42;" + - " }" + - "}"; + public void TestResolveArrayVariable_Local() { + string xml = @"int Foo() { + if(MethodCall()) { + int* bar = malloc(SIZE); + bar[0] = 42; + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CSharp, new Collection() { }, false); + string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLa, "a.cpp"); @@ -1812,18 +1781,17 @@ public void TestResolveArrayVariable_Local() } [Test] - public void TestResolveArrayVariable_Field() - { - string xml = "class A {" + - "public:" + - " char* Foo;" + - " A() { " + - " Foo = malloc(SIZE);" + - " Foo[17] = 'x';" + - " }" + - "}"; + public void TestResolveArrayVariable_Field() { + string xml = @"class A { + public: + char* Foo; + A() { + Foo = malloc(SIZE); + Foo[17] = 'x'; + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1837,25 +1805,24 @@ public void TestResolveArrayVariable_Field() } [Test] - public void TestResolveCallOnArrayVariable() - { + public void TestResolveCallOnArrayVariable() { //#include - string xml = "const int SIZE = 5;" + - "class Foo {" + - "public:" + - " int GetNum() { return 42; }" + - "};" + - "class Bar {" + - "public:" + - " Foo FooArray[SIZE];" + - "};" + - "int main(int argc, char** argv) {" + - " Bar myBar;" + - " std::cout<< myBar.FooArray[0].GetNum() << std::endl;" + - " return 0;" + - "}"; - LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string xml = @"const int SIZE = 5; + class Foo { + public: + int GetNum() { return 42; } + }; + class Bar { + public: + Foo FooArray[SIZE]; + }; + int main(int argc, char** argv) { + Bar myBar; + std::cout<< myBar.FooArray[0].GetNum() << std::endl; + return 0; + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1873,29 +1840,33 @@ public void TestResolveCallOnArrayVariable() } [Test] - public void TestTypeUseForOtherNamespace() - { - string c_xml = "namespace A {" + - " namespace B {" + - " class C {" + - " int Foo() { }" + - " };" + - " }" + - "}"; + public void TestTypeUseForOtherNamespace() { + string c_xml = @"namespace A { + namespace B { + class C { + int Foo() { } + }; + } + }"; + + string e_xml = @"using namespace A::B; + namespace D { + class E { + void main() { + C c = new C(); + c.Foo(); + } + }; + }"; - string e_xml = "using namespace A::B;" + - "namespace D {" + - " class E {" + - " void main() {" + - " C c = new C();" + - " c.Foo();" + - " }" + - " };" + - "}"; + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(c_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "C.cpp"); - var cUnit = fileSetup.GetFileUnitForXmlSnippet(c_xml, "C.cpp"); - var eUnit = fileSetup.GetFileUnitForXmlSnippet(e_xml, "E.cpp"); + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLteste = runE.GenerateSrcMLFromString(e_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var eUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLteste, "E.cpp"); NamespaceDefinition globalScope = codeParser.ParseFileUnit(cUnit); globalScope = globalScope.Merge(codeParser.ParseFileUnit(eUnit)); diff --git a/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs b/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs index 1718f88..bf7dfa8 100644 --- a/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs @@ -16,26 +16,22 @@ using ABB.SrcML; using System.Collections.ObjectModel; using System; -namespace ABB.SrcML.Data.Test -{ +namespace ABB.SrcML.Data.Test { [TestFixture] [Category("Build")] - public class CSharpCodeParserTests - { + public class CSharpCodeParserTests { private CSharpCodeParser codeParser; private SrcMLFileUnitSetup fileSetup; [TestFixtureSetUp] - public void ClassSetup() - { + public void ClassSetup() { codeParser = new CSharpCodeParser(); fileSetup = new SrcMLFileUnitSetup(Language.CSharp); } [Test] - public void TestNamespace() - { + public void TestNamespace() { //namespace A { // public class foo { } //} @@ -43,7 +39,7 @@ public void TestNamespace() public class foo { } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcML, "A.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -56,8 +52,7 @@ public class foo { } } [Test] - public void TestCallToGenericMethod() - { + public void TestCallToGenericMethod() { //namespace A { // public class B { // void Foo(T t) { } @@ -71,7 +66,7 @@ void Foo(T t) { } } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(code, "A.cs", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(code, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcML, "A.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -89,8 +84,7 @@ void Foo(T t) { } } [Test] - public void TestCallToGrandparent() - { + public void TestCallToGrandparent() { //namespace A { // public class B { public void Foo() { } } // public class C : B { } @@ -103,7 +97,7 @@ public class D : C { public void Bar() { Foo() } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var scope = codeParser.ParseFileUnit(unit); @@ -120,8 +114,7 @@ public class D : C { public void Bar() { Foo() } } } [Test] - public void TestMethodCallToParentOfCallingObject() - { + public void TestMethodCallToParentOfCallingObject() { //class A { void Foo() { } } string axml = @"class A { void Foo() { } }"; @@ -136,19 +129,19 @@ public void TestMethodCallToParentOfCallingObject() //} string cxml = @"class C { private B b; - void main() + void main() { b.Foo(); } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); NamespaceDefinition globalScope = codeParser.ParseFileUnit(aUnit); @@ -182,8 +175,8 @@ void main() [Test] [Category("Todo")] - public void TestCallWithTypeParameters() - { + public void TestCallWithTypeParameters() { + //TODO: get answer about how generics are suppsoed to be handled for the parser. Don't see how they're being parsed. //namespace A { // public interface IOdb { // int Query(); @@ -200,18 +193,18 @@ public void TestCallWithTypeParameters() var xml = @"namespace A { public interface IOdb { int Query(); - int QueryT(); + int Query(); } public class Test { public IOdb Open() { } void Test1() { IOdb odb = Open(); - var query = odb.QueryFoo(); + var query = odb.Query(); } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var scope = codeParser.ParseFileUnit(unit); @@ -231,8 +224,7 @@ void Test1() { } [Test] - public void TestCallConstructor() - { + public void TestCallConstructor() { //class Foo { // public Foo() { } //} @@ -240,10 +232,13 @@ public void TestCallConstructor() // Foo myFoo = new Foo(); //} string xml = @"class Foo { - public Foo() { } -}"; + public Foo() { } + } + class Bar { + Foo myFoo = new Foo(); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -257,18 +252,17 @@ public Foo() { } } [Test] - public void TestConstructorWithBaseKeyword() - { + public void TestConstructorWithBaseKeyword() { // B.cs namespace A { class B { public B() { } } } string bxml = @"namespace A { class B { public B() { } } }"; // C.cs namespace A { class C : B { public C() : base() { } } } string cxml = @"namespace A { class C : B { public C() : base() { } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -288,8 +282,7 @@ public void TestConstructorWithBaseKeyword() } [Test] - public void TestConstructorWithThisKeyword() - { + public void TestConstructorWithThisKeyword() { // B.cs //namespace A { // class B { @@ -306,7 +299,7 @@ public B(int i) { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var globalScope = codeParser.ParseFileUnit(bUnit); @@ -324,12 +317,11 @@ public B(int i) { } } [Test] - public void TestCreateAliasesForFiles_UsingNamespace() - { + public void TestCreateAliasesForFiles_UsingNamespace() { // using x.y.z; string xml = @"using x.y.z;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -341,12 +333,11 @@ public void TestCreateAliasesForFiles_UsingNamespace() } [Test] - public void TestCreateAliasesForFiles_UsingAlias() - { + public void TestCreateAliasesForFiles_UsingAlias() { // using x = Foo.Bar.Baz; string xml = @"using x = Foo.Bar.Baz;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -359,13 +350,12 @@ public void TestCreateAliasesForFiles_UsingAlias() } [Test] - public void TestGetImports() - { + public void TestGetImports() { //B.cs //namespace x.y.z {} string xmlB = @"namespace x.y.z {}"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); //A.cs //using x.y.z; @@ -373,7 +363,7 @@ public void TestGetImports() string xmlA = @"using x.y.z; foo = 17;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -395,13 +385,12 @@ public void TestGetImports() } [Test] - public void TestGetImports_NestedImportNamespace() - { + public void TestGetImports_NestedImportNamespace() { //A.cs //namespace bar.baz {} string xmlA = @"namespace bar.baz {}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //using x.y.z; @@ -415,7 +404,7 @@ public void TestGetImports_NestedImportNamespace() foo = 17; }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -437,15 +426,14 @@ public void TestGetImports_NestedImportNamespace() } [Test] - public void TestGetImports_SeparateFiles() - { + public void TestGetImports_SeparateFiles() { //A.cs //using x.y.z; //Foo = 17; string xmlA = @"using x.y.z; Foo = 17;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //using a.b.howdy; @@ -453,7 +441,7 @@ public void TestGetImports_SeparateFiles() string xmlB = @"using a.b.howdy; Bar();"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -475,8 +463,7 @@ public void TestGetImports_SeparateFiles() } [Test] - public void TestGetAliases_NestedUsingAlias() - { + public void TestGetAliases_NestedUsingAlias() { //A.cs //namespace bar { // class baz {} @@ -485,7 +472,7 @@ public void TestGetAliases_NestedUsingAlias() class baz {} }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //using x.y.z; @@ -499,7 +486,7 @@ class baz {} foo = 17; }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runA.GenerateSrcMLFromString(xmlB, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runA.GenerateSrcMLFromString(xmlB, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "A.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -523,8 +510,7 @@ class baz {} } [Test] - public void TestImport_NameResolution() - { + public void TestImport_NameResolution() { //A.cs //using Foo.Bar; // @@ -540,7 +526,7 @@ public class Robot { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //namespace Foo.Bar { @@ -554,7 +540,7 @@ public Baz() { } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -578,32 +564,16 @@ public Baz() { } } [Test] - public void TestAlias_NameResolution() - { - //A.cs - //namespace Foo.Bar { - // public class Baz { - // public static void DoTheThing() { }; - // } - //} + public void TestAlias_NameResolution() { string xmlA = @"namespace Foo.Bar { public class Baz { public static void DoTheThing() { }; } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); - //B.cs - //using Baz = Foo.Bar.Baz; - //namespace A { - // public class B { - // public B() { - // Baz.DoTheThing(); - // } - // } - //} string xmlB = @"using Baz = Foo.Bar.Baz; namespace A { public class B { @@ -613,7 +583,7 @@ public B() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -636,14 +606,13 @@ public B() { [Test] [Category("SrcMLUpdate")] - public void TestUsingBlock_SingleDecl() - { + public void TestUsingBlock_SingleDecl() { //using(var f = File.Open("out.txt")) { // ; //} string xml = "using(var f = File.Open(\"out.txt\")) {;}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -662,12 +631,11 @@ public void TestUsingBlock_SingleDecl() [Test] [Category("SrcMLUpdate")] - public void TestUsingBlock_MultipleDecl() - { + public void TestUsingBlock_MultipleDecl() { // using(Foo a = new Foo(1), b = new Foo(2)) { ; } string xml = @"using(Foo a = new Foo(1), b = new Foo(2)) { ; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -689,12 +657,11 @@ public void TestUsingBlock_MultipleDecl() [Test] [Category("SrcMLUpdate")] - public void TestUsingBlock_Expression() - { + public void TestUsingBlock_Expression() { //using(bar = new Foo()) { ; } string xml = @"using(bar = new Foo()) { ; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -722,8 +689,7 @@ public void TestUsingBlock_Expression() } [Test] - public void TestCreateTypeDefinition_Class() - { + public void TestCreateTypeDefinition_Class() { ////Foo.cs //public class Foo { // public int bar; @@ -732,7 +698,7 @@ public void TestCreateTypeDefinition_Class() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -751,8 +717,7 @@ public void TestCreateTypeDefinition_Class() } [Test] - public void TestCreateTypeDefinition_ClassWithParent() - { + public void TestCreateTypeDefinition_ClassWithParent() { ////Foo.cs //public class Foo : Baz { // public int bar; @@ -761,7 +726,7 @@ public void TestCreateTypeDefinition_ClassWithParent() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -776,8 +741,7 @@ public void TestCreateTypeDefinition_ClassWithParent() } [Test] - public void TestCreateTypeDefinition_ClassWithQualifiedParent() - { + public void TestCreateTypeDefinition_ClassWithQualifiedParent() { ////Foo.cs //public class Foo : Baz, System.IDisposable { // public int bar; @@ -786,7 +750,7 @@ public void TestCreateTypeDefinition_ClassWithQualifiedParent() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -803,8 +767,7 @@ public void TestCreateTypeDefinition_ClassWithQualifiedParent() } [Test] - public void TestCreateTypeDefinition_CompoundNamespace() - { + public void TestCreateTypeDefinition_CompoundNamespace() { ////Foo.cs //namespace Example.Level2.Level3 { // public class Foo { @@ -817,7 +780,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -841,8 +804,7 @@ public class Foo { } [Test] - public void TestCreateTypeDefinition_Interface() - { + public void TestCreateTypeDefinition_Interface() { ////Foo.cs //public interface Foo { // public int GetBar(); @@ -851,12 +813,12 @@ public void TestCreateTypeDefinition_Interface() public int GetBar(); }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); Assert.AreEqual(1, globalScope.ChildStatements.Count()); - var foo = globalScope.ChildStatements.First() as TypeDefinition; + var foo = globalScope.ChildStatements.First() as TypeDefinition; Assert.IsNotNull(foo); Assert.AreEqual("Foo", foo.Name); Assert.AreEqual(TypeKind.Interface, foo.Kind); @@ -864,8 +826,7 @@ public void TestCreateTypeDefinition_Interface() } [Test] - public void TestCreateTypeDefinition_Namespace() - { + public void TestCreateTypeDefinition_Namespace() { ////Foo.cs //namespace Example { // public class Foo { @@ -878,7 +839,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -894,8 +855,7 @@ public class Foo { } [Test] - public void TestCreateTypeDefinition_NestedCompoundNamespace() - { + public void TestCreateTypeDefinition_NestedCompoundNamespace() { ////Foo.cs //namespace Watermelon { // namespace Example.Level2.Level3 { @@ -912,7 +872,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -940,8 +900,7 @@ public class Foo { } [Test] - public void TestCreateTypeDefinition_Struct() - { + public void TestCreateTypeDefinition_Struct() { ////Foo.cs //public struct Foo { // public int bar; @@ -950,7 +909,7 @@ public void TestCreateTypeDefinition_Struct() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -963,8 +922,7 @@ public void TestCreateTypeDefinition_Struct() } [Test] - public void TestCreateTypeDefinitions_ClassWithInnerClass() - { + public void TestCreateTypeDefinitions_ClassWithInnerClass() { ////A.cs //class A { // class B {} @@ -973,7 +931,7 @@ public void TestCreateTypeDefinitions_ClassWithInnerClass() class B {} }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -990,8 +948,7 @@ class B {} } [Test] - public void TestCreateTypeDefinitions_InnerClassWithNamespace() - { + public void TestCreateTypeDefinitions_InnerClassWithNamespace() { ////A.cs //namespace Foo { // class A { @@ -1004,7 +961,7 @@ class B {} } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1028,18 +985,17 @@ class B {} } [Test] - public void TestDeclarationWithTypeVarFromConstructor() - { + public void TestDeclarationWithTypeVarFromConstructor() { // B.cs namespace A { class B { public B() { }; } } string bxml = @"namespace A { class B { public B() { }; } }"; // C.cs namespace A { class C { void main() { var b = new B(); } } } string cxml = @"namespace A { class C { void main() { var b = new B(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1058,18 +1014,17 @@ public void TestDeclarationWithTypeVarFromConstructor() } [Test] - public void TestDeclarationWithTypeVarFromImplicitConstructor() - { + public void TestDeclarationWithTypeVarFromImplicitConstructor() { // B.cs namespace A { class B { } } string bxml = @"namespace A { class B { } }"; // C.cs namespace A { class C { void main() { var b = new B(); } } } string cxml = @"namespace A { class C { void main() { var b = new B(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1088,8 +1043,7 @@ public void TestDeclarationWithTypeVarFromImplicitConstructor() } [Test] - public void TestDeclarationWithTypeVarFromMethod() - { + public void TestDeclarationWithTypeVarFromMethod() { //namespace A { // class B { // public static void main() { var b = getB(); } @@ -1103,7 +1057,7 @@ class B { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1120,8 +1074,7 @@ class B { } [Test] - public void TestDeclarationWithTypeVarInForeach() - { + public void TestDeclarationWithTypeVarInForeach() { //class Foo { // int[] GetInts() { // return new[] {1, 2, 3, 4}; @@ -1143,7 +1096,7 @@ int main() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1155,8 +1108,7 @@ int main() { } [Test] - public void TestFieldCreation() - { + public void TestFieldCreation() { //// A.cs //class A { // public int Foo; @@ -1165,7 +1117,7 @@ public void TestFieldCreation() public int Foo; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1181,8 +1133,7 @@ public void TestFieldCreation() } [Test] - public void TestFindParentType() - { + public void TestFindParentType() { // namespace A { class B : C { } } string bxml = @"namespace A { class B : C { } }"; @@ -1190,10 +1141,10 @@ public void TestFindParentType() string cxml = @"namespace A { class C { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLD = runD.GenerateSrcMLFromString(cxml, "D.cs", Language.CSharp, new Collection() { }, false); + string srcMLD = runD.GenerateSrcMLFromString(cxml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1211,8 +1162,7 @@ public void TestFindParentType() } [Test] - public void TestFindQualifiedParentType() - { + public void TestFindQualifiedParentType() { // namespace A { class B : C.D { } } string bxml = @"A { class B : C.D { } }"; @@ -1220,10 +1170,10 @@ public void TestFindQualifiedParentType() string dxml = @"namespace C { class D { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { }, false); + string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1241,13 +1191,12 @@ public void TestFindQualifiedParentType() } [Test] - public void TestGenericType() - { + public void TestGenericType() { //public class B { } var xml = @"public class B { }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scope = codeParser.ParseFileUnit(unit); @@ -1257,13 +1206,12 @@ public void TestGenericType() } [Test] - public void TestGenericVariableDeclaration() - { + public void TestGenericVariableDeclaration() { //Dictionary map; - string xml = @"Dictionary<string,int> map;"; + string xml = @"Dictionary map;"; LibSrcMLRunner runt = new LibSrcMLRunner(); - string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { }, false); + string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLt, "test.cs"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1279,13 +1227,11 @@ public void TestGenericVariableDeclaration() } [Test] - public void TestGenericVariableDeclarationWithPrefix() - { - //System.Collection.Dictionary map; - string xml = @"Dictionary map;"; + public void TestGenericVariableDeclarationWithPrefix() { + string xml = @"System.Collection.Dictionary map;"; LibSrcMLRunner runt = new LibSrcMLRunner(); - string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { }, false); + string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLt, "test.cs"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1305,31 +1251,24 @@ public void TestGenericVariableDeclarationWithPrefix() } [Test] - public void TestGetAccessModifierForMethod_InternalProtected() - { - //namespace Example { - // public class Foo { - // internal protected bool Bar() { return true; } - // } - //} + public void TestGetAccessModifierForMethod_InternalProtected() { string xml = @"namespace Example { public class Foo { internal protected bool Bar() { return true; } } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); var method = globalScope.GetDescendants().First(); - + //The specifier isn't in type anymore so it doesn't parse correctly. Assert.AreEqual(AccessModifier.ProtectedInternal, method.Accessibility); } [Test] - public void TestGetAccessModifierForMethod_None() - { + public void TestGetAccessModifierForMethod_None() { //namespace Example { // public class Foo { // bool Bar() { return true; } @@ -1341,7 +1280,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1351,8 +1290,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForMethod_Normal() - { + public void TestGetAccessModifierForMethod_Normal() { //namespace Example { // public class Foo { // public bool Bar() { return true; } @@ -1364,7 +1302,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1374,8 +1312,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForMethod_ProtectedInternal() - { + public void TestGetAccessModifierForMethod_ProtectedInternal() { //namespace Example { // public class Foo { // protected internal bool Bar() { return true; } @@ -1387,7 +1324,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1397,8 +1334,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForMethod_ProtectedInternalStatic() - { + public void TestGetAccessModifierForMethod_ProtectedInternalStatic() { //namespace Example { // public class Foo { // protected static internal bool Bar() { return true; } @@ -1410,7 +1346,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1420,8 +1356,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForType_InternalProtected() - { + public void TestGetAccessModifierForType_InternalProtected() { //namespace Example { // internal protected class Foo {} //} @@ -1429,7 +1364,7 @@ public void TestGetAccessModifierForType_InternalProtected() internal protected class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1439,8 +1374,7 @@ internal protected class Foo {} } [Test] - public void TestGetAccessModifierForType_None() - { + public void TestGetAccessModifierForType_None() { //namespace Example { // class Foo {} //} @@ -1448,7 +1382,7 @@ public void TestGetAccessModifierForType_None() class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1458,8 +1392,7 @@ class Foo {} } [Test] - public void TestGetAccessModifierForType_Normal() - { + public void TestGetAccessModifierForType_Normal() { //namespace Example { // public class Foo {} //} @@ -1467,7 +1400,7 @@ public void TestGetAccessModifierForType_Normal() public class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1477,8 +1410,7 @@ public class Foo {} } [Test] - public void TestGetAccessModifierForType_ProtectedInternal() - { + public void TestGetAccessModifierForType_ProtectedInternal() { //namespace Example { // protected internal class Foo {} //} @@ -1486,7 +1418,7 @@ public void TestGetAccessModifierForType_ProtectedInternal() protected internal class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1496,8 +1428,7 @@ protected internal class Foo {} } [Test] - public void TestGetAccessModifierForType_ProtectedInternalStatic() - { + public void TestGetAccessModifierForType_ProtectedInternalStatic() { //namespace Example { // protected static internal class Foo {} //} @@ -1505,7 +1436,7 @@ public void TestGetAccessModifierForType_ProtectedInternalStatic() protected static internal class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1515,18 +1446,17 @@ protected static internal class Foo {} } [Test] - public void TestMethodCallWithBaseKeyword() - { + public void TestMethodCallWithBaseKeyword() { // B.cs namespace A { class B { public virtual void Foo() { } } } string bxml = @"namespace A { class B { public virtual void Foo() { } } }"; // C.cs namespace A { class C : B { public override void Foo() { base.Foo(); } } } string cxml = @"namespace A { class C : B { public override void Foo() { base.Foo(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1547,13 +1477,12 @@ public void TestMethodCallWithBaseKeyword() } [Test] - public void TestMethodDefinitionWithReturnType() - { + public void TestMethodDefinitionWithReturnType() { //int Foo() { } string xml = @"int Foo() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcML, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1565,13 +1494,12 @@ public void TestMethodDefinitionWithReturnType() } [Test] - public void TestMethodDefinitionWithReturnTypeAndWithSpecifier() - { + public void TestMethodDefinitionWithReturnTypeAndWithSpecifier() { //static int Foo() { } string xml = @"static int Foo() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcML, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1583,13 +1511,12 @@ public void TestMethodDefinitionWithReturnTypeAndWithSpecifier() } [Test] - public void TestMethodDefinitionWithVoidReturn() - { + public void TestMethodDefinitionWithVoidReturn() { //void Foo() { } string xml = @"void Foo() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcML, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1602,13 +1529,12 @@ public void TestMethodDefinitionWithVoidReturn() [Test] - public void TestProperty() - { + public void TestProperty() { // namespace A { class B { int Foo { get; set; } } } string xml = @"namespace A { class B { int Foo { get; set; } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1627,29 +1553,13 @@ public void TestProperty() } [Test] - public void TestPropertyAsCallingObject() - { - // B.cs - //namespace A { - // class B { - // C Foo { get; set; } - // } - //} + public void TestPropertyAsCallingObject() { string bxml = @"namespace A { class B { C Foo { get; set; } } }"; - // C.cs - //namespace A { - // class C { - // static void main() { - // B b = new B(); - // b.Foo.Bar(); - // } - // void Bar() { } - // } - //} + string cxml = @"namespace A { class C { static void main() { @@ -1661,10 +1571,10 @@ void Bar() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1688,18 +1598,17 @@ void Bar() { } } [Test] - public void TestStaticMethodCall() - { + public void TestStaticMethodCall() { //namespace A { public class B { public static void Bar() { } } } var bxml = @"namespace A { public class B { public static void Bar() { } } }"; //namespace A { public class C { public void Foo() { B.Bar(); } } } var cxml = @"namespace A { public class C { public void Foo() { B.Bar(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1719,18 +1628,17 @@ public void TestStaticMethodCall() } [Test] - public void TestStaticMethodCallInDifferentNamespace() - { + public void TestStaticMethodCallInDifferentNamespace() { //namespace A { public class B { public static void Bar() { } } } var bxml = @"namespace A { public class B { public static void Bar() { } } }"; //namespace C { public class D { public void Foo() { A.B.Bar(); } } } var dxml = @"namespace C { public class D { public void Foo() { A.B.Bar(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(dxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(dxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1750,8 +1658,7 @@ public void TestStaticMethodCallInDifferentNamespace() } [Test] - public void TestVariablesWithSpecifiers() - { + public void TestVariablesWithSpecifiers() { //static int A; //public const int B; //public static readonly Foo C; @@ -1759,10 +1666,10 @@ public void TestVariablesWithSpecifiers() string testXml = @"static int A; public const int B; public static readonly Foo C; - volatile int D;"; + volatile int D;"; LibSrcMLRunner runt = new LibSrcMLRunner(); - string srcMLt = runt.GenerateSrcMLFromString(testXml, "test.cs", Language.CSharp, new Collection() { }, false); - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cs"); + string srcMLt = runt.GenerateSrcMLFromString(testXml, "test.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLt, "test.cs"); var globalScope = codeParser.ParseFileUnit(testUnit); Assert.AreEqual(4, globalScope.ChildStatements.Count); @@ -1793,8 +1700,7 @@ public void TestVariablesWithSpecifiers() } [Test] - public void TestStaticInstanceVariable() - { + public void TestStaticInstanceVariable() { //namespace A { // class B { // public static B Instance { get; set; } @@ -1812,7 +1718,7 @@ public void Bar() { } class C { public void Foo() { B.Instance.Bar(); } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1829,8 +1735,7 @@ class C { public void Foo() { B.Instance.Bar(); } } } [Test] - public void TestStaticInstanceVariableInDifferentNamespace() - { + public void TestStaticInstanceVariableInDifferentNamespace() { //namespace A { // class B { // public static B Instance { get; set; } @@ -1857,10 +1762,10 @@ class D { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var aScope = codeParser.ParseFileUnit(aUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1878,8 +1783,7 @@ class D { } [Test] - public void TestCallAsCallingObject() - { + public void TestCallAsCallingObject() { //namespace A { // public class B { // void main() { @@ -1907,7 +1811,7 @@ void Bar() { } } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcML, "B.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1929,8 +1833,7 @@ void Bar() { } } [Test] - public void TestResolveVariable_Field() - { + public void TestResolveVariable_Field() { //class A { // public int Foo; // public A() { @@ -1944,7 +1847,7 @@ public A() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1957,8 +1860,7 @@ public A() { } [Test] - public void TestResolveVariable_FieldInParent() - { + public void TestResolveVariable_FieldInParent() { //class B { // public int Foo; //} @@ -1976,7 +1878,7 @@ public A() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1989,8 +1891,7 @@ public A() { } [Test] - public void TestCallingVariableDeclaredInParentClass() - { + public void TestCallingVariableDeclaredInParentClass() { //class A { void Foo() { } } string axml = @"class A { void Foo() { } }"; @@ -2001,13 +1902,13 @@ public void TestCallingVariableDeclaredInParentClass() string cxml = @"class C : B { void Bar() { a.Foo(); } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var globalScope = codeParser.ParseFileUnit(aUnit); @@ -2036,8 +1937,7 @@ public void TestCallingVariableDeclaredInParentClass() } [Test] - public void TestVariableDeclaredInCallingObjectWithParentClass() - { + public void TestVariableDeclaredInCallingObjectWithParentClass() { //class A { B b; } string axml = @"class A { B b; }"; @@ -2057,16 +1957,16 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { }, false); + string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.cs"); var globalScope = codeParser.ParseFileUnit(aUnit); @@ -2101,8 +2001,7 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() } [Test] - public void TestResolveArrayVariable_Property() - { + public void TestResolveArrayVariable_Property() { //class Foo { // Collection Parameters { get; set; } // void DoWork() { @@ -2116,7 +2015,7 @@ void DoWork() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -2130,8 +2029,7 @@ void DoWork() { } [Test] - public void TestTypeUseForOtherNamespace() - { + public void TestTypeUseForOtherNamespace() { //namespace A.B { // class C { // int Foo() { } @@ -2163,10 +2061,10 @@ void main() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcMLC = run.GenerateSrcMLFromString(cxml, "C.cpp", Language.CSharp, new Collection() { }, false); + string srcMLC = run.GenerateSrcMLFromString(cxml, "C.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cpp"); LibSrcMLRunner runE = new LibSrcMLRunner(); - string srcMLE = runE.GenerateSrcMLFromString(exml, "E.cpp", Language.CSharp, new Collection() { }, false); + string srcMLE = runE.GenerateSrcMLFromString(exml, "E.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var eUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLE, "E.cpp"); NamespaceDefinition globalScope = codeParser.ParseFileUnit(cUnit); @@ -2199,8 +2097,7 @@ void main() { } [Test] - public void TestLockStatement() - { + public void TestLockStatement() { //lock(myVar) { // myVar.DoFoo(); //} @@ -2208,7 +2105,7 @@ public void TestLockStatement() myVar.DoFoo(); }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); diff --git a/ABB.SrcML.Data.Test/CodeParserTests.cs b/ABB.SrcML.Data.Test/CodeParserTests.cs index 8a9d511..c90235f 100644 --- a/ABB.SrcML.Data.Test/CodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CodeParserTests.cs @@ -20,18 +20,15 @@ using NUnit.Framework; using System.Collections.ObjectModel; -namespace ABB.SrcML.Data.Test -{ +namespace ABB.SrcML.Data.Test { [TestFixture] [Category("Build")] - public class CodeParserTests - { + public class CodeParserTests { private Dictionary codeParsers; private Dictionary fileSetup; [TestFixtureSetUp] - public void ClassSetup() - { + public void ClassSetup() { codeParsers = new Dictionary() { {Language.CPlusPlus, new CPlusPlusCodeParser()}, {Language.CSharp, new CSharpCodeParser()}, @@ -47,12 +44,11 @@ public void ClassSetup() [TestCase(Language.CPlusPlus)] [TestCase(Language.CSharp)] [TestCase(Language.Java)] - public void TestTwoVariableDeclarations(Language lang) - { + public void TestTwoVariableDeclarations(Language lang) { int a, b; string xml = @"int a,b;"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.cpp"); var globalScope = codeParsers[lang].ParseFileUnit(testUnit); @@ -70,15 +66,14 @@ public void TestTwoVariableDeclarations(Language lang) [TestCase(Language.CSharp)] [TestCase(Language.Java)] - public void TestField(Language lang) - { + public void TestField(Language lang) { string xml = @"class A { int Foo; Bar baz; }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -99,15 +94,14 @@ public void TestField(Language lang) } [TestCase(Language.CPlusPlus)] - public void TestField_Cpp(Language lang) - { + public void TestField_Cpp(Language lang) { string xml = @"class A { int Foo; Bar baz; }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -129,10 +123,7 @@ public void TestField_Cpp(Language lang) [TestCase(Language.CSharp)] [TestCase(Language.Java)] - public void TestMethodCallCreation(Language lang) - { - // A.cs - + public void TestMethodCallCreation(Language lang) { string xml = @"class A { public int Execute() { B b = new B(); @@ -146,7 +137,7 @@ public int Execute() { } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnit = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(fileUnit); @@ -201,11 +192,10 @@ public int Execute() { [TestCase(Language.CPlusPlus)] [TestCase(Language.CSharp)] [TestCase(Language.Java)] - public void TestSimpleExpression(Language lang) - { + public void TestSimpleExpression(Language lang) { string xml = @"foo = 2+3;"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -233,11 +223,10 @@ public void TestSimpleExpression(Language lang) [TestCase(Language.CPlusPlus)] [TestCase(Language.CSharp)] [TestCase(Language.Java)] - public void TestSubExpression(Language lang) - { + public void TestSubExpression(Language lang) { string xml = @"foo = (2+3)*5;"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -276,8 +265,7 @@ public void TestSubExpression(Language lang) [TestCase(Language.CPlusPlus)] [TestCase(Language.Java)] [TestCase(Language.CSharp)] - public void TestGetChildren_Statements(Language lang) - { + public void TestGetChildren_Statements(Language lang) { string xml = @"if(foo == 0) { return; try { @@ -289,7 +277,7 @@ public void TestGetChildren_Statements(Language lang) return; }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -300,11 +288,10 @@ public void TestGetChildren_Statements(Language lang) [TestCase(Language.CPlusPlus)] [TestCase(Language.Java)] [TestCase(Language.CSharp)] - public void TestGetChildren_Expressions(Language lang) - { + public void TestGetChildren_Expressions(Language lang) { string xml = @"Foo f = (bar + baz(qux(17))).Xyzzy();"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -315,8 +302,7 @@ public void TestGetChildren_Expressions(Language lang) [TestCase(Language.CPlusPlus)] [TestCase(Language.Java)] [TestCase(Language.CSharp)] - public void TestResolveLocalVariable(Language lang) - { + public void TestResolveLocalVariable(Language lang) { string xml = @"int Foo() { if(MethodCall()) { int bar = 17; @@ -324,7 +310,7 @@ public void TestResolveLocalVariable(Language lang) } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -341,15 +327,14 @@ public void TestResolveLocalVariable(Language lang) [TestCase(Language.CPlusPlus)] [TestCase(Language.Java)] [TestCase(Language.CSharp)] - public void TestResolveLocalVariable_ParentExpression(Language lang) - { + public void TestResolveLocalVariable_ParentExpression(Language lang) { string xml = @"int Foo() { for(int i = 0; i < bar; i++) { printf(i); } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); @@ -366,8 +351,7 @@ public void TestResolveLocalVariable_ParentExpression(Language lang) [TestCase(Language.CPlusPlus)] [TestCase(Language.Java)] [TestCase(Language.CSharp)] - public void TestResolveLocalVariable_Parameter(Language lang) - { + public void TestResolveLocalVariable_Parameter(Language lang) { string xml = @"int Foo(int num, bool option) { if(option) { printf(num); @@ -375,7 +359,7 @@ public void TestResolveLocalVariable_Parameter(Language lang) return 0; }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "A.cpp", lang, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "A.cpp", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "A.cpp"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); diff --git a/ABB.SrcML.Data.Test/DataFileNameMappingTests.cs b/ABB.SrcML.Data.Test/DataFileNameMappingTests.cs index fe6f75a..c56528f 100644 --- a/ABB.SrcML.Data.Test/DataFileNameMappingTests.cs +++ b/ABB.SrcML.Data.Test/DataFileNameMappingTests.cs @@ -12,6 +12,7 @@ using NUnit.Framework; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; @@ -39,18 +40,26 @@ public void FixtureTeardown() { TestCase(true), TestCase(false)] public void TestDataFileNameMap(bool compressionEnabled) { + //I'm not exactly sure what this test is testing for, but the way files are named by the library + //is not playing well with this test. Seems like it wants a specific file extension. Some decision + //will have to be made about how to handle this problem. Does the library need to generate names differently? + //Or maybe this test should be different? var generator = new DataGenerator(); var mapping = new DataFileNameMapping(TEST_DIRECTORY, compressionEnabled); var sourcePath = @"..\..\TestInputs\function_def.cpp"; var srcmlPath = @"..\..\TestInputs\function_def.xml"; var mappedPath = mapping.GetTargetPath(sourcePath); - + var actualExtension = Path.GetExtension(mappedPath); var expectedExtension = (compressionEnabled ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION); StringAssert.AreEqualIgnoringCase(expectedExtension, actualExtension); - generator.Generate(srcmlPath, mappedPath); + //generator.Generate(srcmlPath, mappedPath); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFile(srcmlPath, mappedPath, Language.CPlusPlus, new Collection { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary { }); + + Assert.That(File.Exists(mappedPath), String.Format("Could not generate {0}", mappedPath)); var data = XmlSerialization.Load(mappedPath, compressionEnabled); diff --git a/ABB.SrcML.Data.Test/FileRemovalTests_CSharp.cs b/ABB.SrcML.Data.Test/FileRemovalTests_CSharp.cs index 80351cd..e575594 100644 --- a/ABB.SrcML.Data.Test/FileRemovalTests_CSharp.cs +++ b/ABB.SrcML.Data.Test/FileRemovalTests_CSharp.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,33 +15,28 @@ public class FileRemovalTests_CSharp { [TestFixtureSetUp, Category("Build")] public void ClassSetup() { - FileUnitSetup = new SrcMLFileUnitSetup(Language.CPlusPlus); + FileUnitSetup = new SrcMLFileUnitSetup(Language.CSharp); CodeParser = new CSharpCodeParser(); } [Test] public void TestRemoveClass_Global() { - ////Foo.cs - //class Foo { - // private int bar; - // public Foo() { bar = 42; } - // public int GetBar() { return bar; } - //} - string fooXml = @"class Foo { - private int bar; - public Foo() { bar = 42; } - public int GetBar() { return bar; } -}"; - var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(fooXml, "Foo.cs"); + string fooXml = @"class Foo { + private int bar; + public Foo() { bar = 42; } + public int GetBar() { return bar; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs"); var beforeScope = CodeParser.ParseFileUnit(fooFileUnit); - ////Baz.cs - //class Baz { - // public static int DoWork() { return 0; } - //} - string bazXml = @"class Baz { - public static int DoWork() { return 0; } -}"; - var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(bazXml, "Baz.cs"); + + string bazXml = @"class Baz { + public static int DoWork() { return 0; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit)); Assert.AreEqual(0, afterScope.ChildStatements.OfType().Count()); @@ -53,23 +49,20 @@ public void TestRemoveClass_Global() { [Test] public void TestRemoveNamespace() { - ////A.cs - //namespace A { - // class Foo { int bar; } - //} - string aXml = @"namespace A { - class Foo { int bar; } -}"; - var aFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(aXml, "A.cs"); + string aXml = @"namespace A { + class Foo { int bar; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(aXml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var aFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A.cs"); var beforeScope = CodeParser.ParseFileUnit(aFileunit); - ////B.cs - //namespace B { - // class Baz { public ulong xyzzy; } - //} - string bXml = @"namespace B { - class Baz { public ulong xyzzy; } -}"; - var bFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(bXml, "B.cs"); + + string bXml = @"namespace B { + class Baz { public ulong xyzzy; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(bXml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var bFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "B.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bFileunit)); Assert.AreEqual(2, afterScope.ChildStatements.OfType().Count()); @@ -81,31 +74,24 @@ public void TestRemoveNamespace() { [Test] public void TestRemovePartialClass() { - ////A1.cs - //public partial class A { - // public int Execute() { - // return 0; - // } - //} - string a1Xml = @"public partial class A { - public int Execute() { - return 0; - } -}"; - var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a1Xml, "A1.cs"); + string a1Xml = @"public partial class A { + public int Execute() { + return 0; + } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A1.cs"); var beforeScope = CodeParser.ParseFileUnit(a1FileUnit); - ////A2.cs - //public partial class A { - // private bool Foo() { - // return true; - // } - //} - string a2Xml = @"public partial class A { - private bool Foo() { - return true; - } -}"; - var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a2Xml, "A2.cs"); + + string a2Xml = @"public partial class A { + private bool Foo() { + return true; + } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A2.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a2FileUnit)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); @@ -122,23 +108,20 @@ public void TestRemovePartialClass() { [Test] public void TestRemovePartialMethod_Declaration() { - ////A2.cs - //public partial class A { - // public partial int Foo() { return 42; } - //} - string a2Xml = @"public partial class A { - public partial int Foo() { return 42; } -}"; - var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a2Xml, "A2.cs"); + string a2Xml = @"public partial class A { + public partial int Foo() { return 42; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A2.cs"); var beforeScope = CodeParser.ParseFileUnit(a2FileUnit); - ////A1.cs - //public partial class A { - // public partial int Foo(); - //} - string a1Xml = @"public partial class A { - public partial int Foo(); -}"; - var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a1Xml, "A1.cs"); + + string a1Xml = @"public partial class A { + public partial int Foo(); + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A1.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a1FileUnit)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); @@ -158,23 +141,20 @@ public void TestRemovePartialMethod_Declaration() { [Test] public void TestRemovePartialMethod_Implementation() { - ////A1.cs - //public partial class A { - // public partial int Foo(); - //} - string a1Xml = @"public partial class A { - public partial int Foo(); -}"; - var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a1Xml, "A1.cs"); + string a1Xml = @"public partial class A { + public partial int Foo(); + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A1.cs"); var beforeScope = CodeParser.ParseFileUnit(a1FileUnit); - ////A2.cs - //public partial class A { - // public partial int Foo() { return 42; } - //} - string a2Xml = @"public partial class A { - public partial int Foo() { return 42; } -}"; - var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a2Xml, "A2.cs"); + + string a2Xml = @"public partial class A { + public partial int Foo() { return 42; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A2.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a2FileUnit)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); @@ -187,28 +167,26 @@ public void TestRemovePartialMethod_Implementation() { afterScope.RemoveFile("A2.cs"); - DataAssert.StatementsAreEqual(beforeScope, afterScope); + DataAssert.StatementsAreEqual(beforeScope, afterScope); } [Test] public void TestRemovePartOfNamespace() { - ////A1.cs - //namespace A { - // class Foo { int bar; } - //} - string a1Xml = @"namespace A { - class Foo { int bar; } -}"; - var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a1Xml, "A1.cs"); + string a1Xml = @"namespace A { + class Foo { int bar; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A1.cs"); var beforeScope = CodeParser.ParseFileUnit(a1FileUnit); - ////A2.cs - //namespace A { - // class Baz { public ulong xyzzy; } - //} - string a2Xml = @"namespace A { - class Baz { public ulong xyzzy; } -}"; - var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a2Xml, "A2.cs"); + + string a2Xml = @" + namespace A { + class Baz { public ulong xyzzy; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A2.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a2FileUnit)); Assert.AreEqual(1, afterScope.ChildStatements.OfType().Count()); @@ -221,14 +199,17 @@ public void TestRemovePartOfNamespace() { [Test] public void TestFileRemovalWithDifferentCase() { - // namespace A { class B { } } - string bXml = @"namespace A { class B { } }"; - // namespace C { class D { } } - string dXml = @"namespace C { class D { } }"; + string bXml = @"namespace A { class B { } }"; + + string dXml = @"namespace C { class D { } }"; - var bUnit = FileUnitSetup.GetFileUnitForXmlSnippet(bXml, "B.cs"); - var dUnit = FileUnitSetup.GetFileUnitForXmlSnippet(dXml, "D.cs"); + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(bXml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var bUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "B.cs"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(dXml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var dUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "D.cs"); var bScope = CodeParser.ParseFileUnit(bUnit); var dScope = CodeParser.ParseFileUnit(dUnit); diff --git a/ABB.SrcML.Data.Test/FileRemovalTests_Cpp.cs b/ABB.SrcML.Data.Test/FileRemovalTests_Cpp.cs index 4ad62ae..1acbfd8 100644 --- a/ABB.SrcML.Data.Test/FileRemovalTests_Cpp.cs +++ b/ABB.SrcML.Data.Test/FileRemovalTests_Cpp.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using NUnit.Framework; using ABB.SrcML.Test.Utilities; +using System.Collections.ObjectModel; namespace ABB.SrcML.Data.Test { [TestFixture, Category("Build")] @@ -20,27 +21,25 @@ public void ClassSetup() { [Test] public void TestRemoveClassDefinition() { - ////A.cpp - //int Foo::Add(int b) { - // return this->a + b; - //} - string cppXml = @"int Foo::Add(int b) { - return this->a + b; -}"; - var cppFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(cppXml, "A.cpp"); + + string cppXml = @"int Foo::Add(int b) { + return this->a + b; + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(cppXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var cppFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var beforeScope = CodeParser.ParseFileUnit(cppFileunit); - ////A.h - //class Foo { - // public: - // int a; - // int Add(int b); - //}; - string hXml = @"class Foo { - public: - int a; - int Add(int b); -};"; - var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(hXml, "A.h"); + + string hXml = @"class Foo { + public: + int a; + int Add(int b); + };"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(hXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "A.h"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(hFileunit)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); @@ -53,31 +52,27 @@ public void TestRemoveClassDefinition() { [Test] public void TestRemoveMethodFromClass() { - ////A.cpp - //int Foo::Add(int b) { - // return this->a + b; - //} - string cppXml = @"int Foo::Add(int b) { - return this->a + b; -}"; - var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(cppXml, "A.cpp"); - - ////A.h - //class Foo { - // public: - // int a; - // int Add(int b); - //}; - string hXml = @"class Foo { - public: - int a; - int Add(int b); -};"; - var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(hXml, "A.h"); + string cppXml = @"int Foo::Add(int b) { + return this->a + b; + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(cppXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); + + string hXml = @"class Foo { + public: + int a; + int Add(int b); + };"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(hXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "A.h"); var beforeScope = CodeParser.ParseFileUnit(hFileunit); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(cppFileUnit)); - + Assert.AreEqual(1, afterScope.ChildStatements.Count()); Assert.IsNotNull(afterScope.ChildStatements.First() as TypeDefinition); @@ -88,20 +83,22 @@ public void TestRemoveMethodFromClass() { [Test] public void TestRemoveMethodDeclaration_Global() { - ////Foo.cpp - //int Foo(char bar) { return 0; } - string defXml = "int Foo(char bar) { return 0; }"; - var fileUnitDef = FileUnitSetup.GetFileUnitForXmlSnippet(defXml, "Foo.cpp"); + string defXml = "int Foo(char bar) { return 0; }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(defXml, "Foo.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileUnitDef = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.cpp"); var beforeScope = CodeParser.ParseFileUnit(fileUnitDef); - ////Foo.h - //int Foo(char bar); - string declXml = "int Foo(char bar);"; - var fileunitDecl = FileUnitSetup.GetFileUnitForXmlSnippet(declXml, "Foo.h"); + string declXml = "int Foo(char bar);"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(declXml, "Foo.h", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileunitDecl = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "Foo.h"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(fileunitDecl)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); - Assert.AreEqual("Foo", ((MethodDefinition) afterScope.ChildStatements.First()).Name); + Assert.AreEqual("Foo", ((MethodDefinition)afterScope.ChildStatements.First()).Name); afterScope.RemoveFile("Foo.h"); @@ -110,28 +107,24 @@ public void TestRemoveMethodDeclaration_Global() { [Test] public void TestRemoveMethodDefinition_Class() { - ////A.h - //class Foo { - // public: - // int a; - // int Add(int b); - //}; - string hXml = @"class Foo { - public: - int a; - int Add(int b); -};"; - var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(hXml, "A.h"); + string hXml = @"class Foo { + public: + int a; + int Add(int b); + };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(hXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var beforeScope = CodeParser.ParseFileUnit(hFileunit); - ////A.cpp - //int Foo::Add(int b) { - // return this->a + b; - //} - string cppXml = @"int Foo::Add(int b) { - return this->a + b; -}"; - var cppFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(cppXml, "A.cpp"); + string cppXml = @"int Foo::Add(int b) { + return this->a + b; + }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runA.GenerateSrcMLFromString(cppXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var cppFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "A.cpp"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(cppFileunit)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); @@ -146,20 +139,24 @@ public void TestRemoveMethodDefinition_Class() { [Test] public void TestRemoveMethodDefinition_Global() { - ////Foo.h - //int Foo(char bar); - string declXml = "int Foo(char bar);"; - var fileunitDecl = FileUnitSetup.GetFileUnitForXmlSnippet(declXml, "Foo.h"); + string declXml = "int Foo(char bar);"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(declXml, "Foo.h", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileunitDecl = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.h"); var beforeScope = CodeParser.ParseFileUnit(fileunitDecl); - ////Foo.cpp //int Foo(char bar) { return 0; } - string defXml = "int Foo(char bar) { return 0; }"; - var fileUnitDef = FileUnitSetup.GetFileUnitForXmlSnippet(defXml, "Foo.cpp"); + string defXml = "int Foo(char bar) { return 0; }"; + + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(defXml, "Foo.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileUnitDef = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "Foo.cpp"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(fileUnitDef)); Assert.AreEqual(1, afterScope.ChildStatements.Count()); - Assert.AreEqual("Foo", ((MethodDefinition) afterScope.ChildStatements.First()).Name); + Assert.AreEqual("Foo", ((MethodDefinition)afterScope.ChildStatements.First()).Name); afterScope.RemoveFile("Foo.cpp"); @@ -168,16 +165,18 @@ public void TestRemoveMethodDefinition_Global() { [Test] public void TestRemoveMethodFromGlobal() { - ////Foo.cpp - //int Foo() { return 0; } - string fooXml = @"int Foo() { return 0; }"; - var fileunitFoo = FileUnitSetup.GetFileUnitForXmlSnippet(fooXml, "Foo.cpp"); + string fooXml = @"int Foo() { return 0; }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(fooXml, "Foo.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileunitFoo = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.cpp"); var beforeScope = CodeParser.ParseFileUnit(fileunitFoo); - ////Baz.cpp - //char* Baz() { return "Hello, World!"; } - string bazXml = "char* Baz() { return \"Hello, World!\"; }"; - var fileunitBaz = FileUnitSetup.GetFileUnitForXmlSnippet(bazXml, "Baz.cpp"); + string bazXml = "char* Baz() { return \"Hello, World!\"; }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(bazXml, "Baz.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileunitBaz = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "Baz.cpp"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(fileunitBaz)); Assert.AreEqual(2, afterScope.ChildStatements.OfType().Count()); @@ -188,24 +187,22 @@ public void TestRemoveMethodFromGlobal() { [Test] public void TestRemoveNamespace() { - ////A.cpp - //namespace A { - // int Foo(){ return 0;} - //} - string aXml = @"namespace A { - int Foo(){ return 0;} -}"; - var aFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(aXml, "A.cpp"); + string aXml = @"namespace A { + int Foo(){ return 0;} + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(aXml, "A.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var aFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var beforeScope = CodeParser.ParseFileUnit(aFileunit); - ////B.cpp - //namespace B { - // char* Bar(){return "Hello, World!";} - //} - string bXml = @"namespace B { - char* Bar(){return ""Hello, World!"";} -}"; - var bFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(bXml, "B.cpp"); + string bXml = @"namespace B { + char* Bar(){return 'Hello, World!';} + }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(bXml, "B.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var bFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bFileunit)); Assert.AreEqual(2, afterScope.ChildStatements.OfType().Count()); @@ -217,24 +214,23 @@ public void TestRemoveNamespace() { [Test] public void TestRemovePartOfNamespace() { - ////A1.cpp - //namespace A { - // int Foo(){ return 0;} - //} - string a1Xml = @"namespace A { - int Foo(){ return 0;} -}"; - var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(a1Xml, "A1.cpp"); + + string a1Xml = @"namespace A { + int Foo(){ return 0;} + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a1Xml, "A1.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A1.cpp"); var beforeScope = CodeParser.ParseFileUnit(a1FileUnit); - ////A2.cpp - //namespace A { - // char* Bar(){return "Hello, World!";} - //} - string a2Xml = @"namespace A { - char* Bar(){return ""Hello, World!"";} -}"; - var a2Fileunit = FileUnitSetup.GetFileUnitForXmlSnippet(a2Xml, "A2.cpp"); + string a2Xml = @"namespace A { + char* Bar(){return 'Hello, World!';} + }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runA.GenerateSrcMLFromString(a2Xml, "A2.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var a2Fileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "A2.cpp"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a2Fileunit)); Assert.AreEqual(1, afterScope.ChildStatements.OfType().Count()); @@ -247,26 +243,23 @@ public void TestRemovePartOfNamespace() { [Test] public void TestCppRemovalWithNamespaceAndClass() { - //Foo.h - //namespace A { - // class Foo { - // public: - // int Bar(int b); - // }; - //} - string hXml = @"namespace A { - class Foo { - public: - int Bar(int b); - }; -}"; - - //Foo.cpp - //int A::Foo::Bar(int b) { } - string cppXml = @"int A::Foo::Bar(int b) { }"; - - var hFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(hXml, "Foo.h"); - var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(cppXml, "Foo.cpp"); + string hXml = @"namespace A { + class Foo { + public: + int Bar(int b); + }; + }"; + + string cppXml = @"int A::Foo::Bar(int b) { }"; + + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(hXml, "Foo.h", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var hFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.h"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runA.GenerateSrcMLFromString(cppXml, "Foo.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "Foo.cpp"); var beforeScope = CodeParser.ParseFileUnit(hFileUnit); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(cppFileUnit)); @@ -278,26 +271,23 @@ public void TestCppRemovalWithNamespaceAndClass() { [Test] public void TestHeaderRemovalWithNamespaceAndClass() { - //Foo.h - //namespace A { - // class Foo { - // public: - // int Bar(int b); - // }; - //} - string hXml = @"namespace A { - class Foo { - public: - int Bar(int b); - }; -}"; - - //Foo.cpp - //int A::Foo::Bar(int b) { } - string cppXml = @"int A::Foo::Bar(int b) { }"; - - var hFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(hXml, "Foo.h"); - var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(cppXml, "Foo.cpp"); + string hXml = @"namespace A { + class Foo { + public: + int Bar(int b); + }; + }"; + + string cppXml = @"int A::Foo::Bar(int b) { }"; + + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(hXml, "Foo.h", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var hFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.h"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runA.GenerateSrcMLFromString(cppXml, "Foo.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "Foo.cpp"); var beforeScope = CodeParser.ParseFileUnit(cppFileUnit); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(hFileUnit)); @@ -309,18 +299,15 @@ public void TestHeaderRemovalWithNamespaceAndClass() { [Test] public void TestTestHelper() { - ////A.h - //class Foo { - // public: - // int a; - // int Add(int b); - //}; - string xml = @"class Foo { - public: - int a; - int Add(int b); -};"; - var fileunit = FileUnitSetup.GetFileUnitForXmlSnippet(xml, "A.h"); + string xml = @"class Foo { + public: + int a; + int Add(int b); + };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var scope1 = CodeParser.ParseFileUnit(fileunit); var scope2 = CodeParser.ParseFileUnit(fileunit); DataAssert.StatementsAreEqual(scope1, scope2); diff --git a/ABB.SrcML.Data.Test/FileRemovalTests_Java.cs b/ABB.SrcML.Data.Test/FileRemovalTests_Java.cs index d24d830..a93805e 100644 --- a/ABB.SrcML.Data.Test/FileRemovalTests_Java.cs +++ b/ABB.SrcML.Data.Test/FileRemovalTests_Java.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,33 +16,28 @@ public class FileRemovalTests_Java { [TestFixtureSetUp, Category("Build")] public void ClassSetup() { - FileUnitSetup = new SrcMLFileUnitSetup(Language.CPlusPlus); + FileUnitSetup = new SrcMLFileUnitSetup(Language.Java); CodeParser = new JavaCodeParser(); } [Test] public void TestRemoveClass_Global() { - ////Foo.java - //class Foo { - // private int bar; - // public Foo() { bar = 42; } - // public int GetBar() { return bar; } - //} - string fooXml = @"class Foo { - private int bar; - public Foo() { bar = 42; } - public int GetBar() { return bar; } -}"; - var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(fooXml, "Foo.java"); + string fooXml = @"class Foo { + private int bar; + public Foo() { bar = 42; } + public int GetBar() { return bar; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.java", Language.Java, new Collection() { }, false); + var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.java"); var beforeScope = CodeParser.ParseFileUnit(fooFileUnit); - ////Baz.java - //class Baz { - // public static int DoWork() { return 0; } - //} - string bazXml = @"class Baz { - public static int DoWork() { return 0; } -}"; - var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(bazXml, "Baz.java"); + + string bazXml = @"class Baz { + public static int DoWork() { return 0; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.java", Language.Java, new Collection() { }, false); + var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.java"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit)); Assert.AreEqual(0, afterScope.ChildStatements.OfType().Count()); @@ -54,31 +50,24 @@ public void TestRemoveClass_Global() { [Test] public void TestRemoveClass_Namespace() { - ////Foo.java - //package com.ABB.Example; - //class Foo { - // private int bar; - // public Foo() { bar = 42; } - // public int GetBar() { return bar; } - //} - string fooXml = @"package com.ABB.Example; -class Foo { - private int bar; - public Foo() { bar = 42; } - public int GetBar() { return bar; } -}"; - var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(fooXml, "Foo.java"); + string fooXml = @"package com.ABB.Example; + class Foo { + private int bar; + public Foo() { bar = 42; } + public int GetBar() { return bar; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.java", Language.Java, new Collection() { }, false); + var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.java"); var beforeScope = CodeParser.ParseFileUnit(fooFileUnit); - ////Baz.java - //package com.ABB.Example; - //class Baz { - // public static int DoWork() { return 0; } - //} - string bazXml = @"package com.ABB.Example; -class Baz { - public static int DoWork() { return 0; } -}"; - var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(bazXml, "Baz.java"); + + string bazXml = @"package com.ABB.Example; + class Baz { + public static int DoWork() { return 0; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.java", Language.Java, new Collection() { }, false); + var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.java"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit)); Assert.AreEqual(1, afterScope.ChildStatements.OfType().Count()); @@ -90,31 +79,24 @@ public void TestRemoveClass_Namespace() { [Test] public void TestRemoveNamespace() { - ////Foo.java - //package com.ABB.example; - //class Foo { - // private int bar; - // public Foo() { bar = 42; } - // public int GetBar() { return bar; } - //} - string fooXml = @"package com.ABB.example; -class Foo { - private int bar; - public Foo() { bar = 42; } - public int GetBar() { return bar; } -}"; - var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(fooXml, "Foo.java"); + string fooXml = @"package com.ABB.example; + class Foo { + private int bar; + public Foo() { bar = 42; } + public int GetBar() { return bar; } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.java", Language.Java, new Collection() { }, false); + var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.java"); var beforeScope = CodeParser.ParseFileUnit(fooFileUnit); - ////Baz.java - //package com.ABB.DifferentExample; - //class Baz { - // public static int DoWork() { return 0; } - //} - string bazXml = @"package com.ABB.DifferentExample; -class Baz { - public static int DoWork() { return 0; } -}"; - var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(bazXml, "Baz.java"); + + string bazXml = @"package com.ABB.DifferentExample; + class Baz { + public static int DoWork() { return 0; } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.java", Language.Java, new Collection() { }, false); + var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.java"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit)); var comDotAbb = afterScope.ChildStatements.OfType().First().ChildStatements.OfType().First(); diff --git a/ABB.SrcML.Data.Test/GetStatementTests.cs b/ABB.SrcML.Data.Test/GetStatementTests.cs index 6733038..bbd2644 100644 --- a/ABB.SrcML.Data.Test/GetStatementTests.cs +++ b/ABB.SrcML.Data.Test/GetStatementTests.cs @@ -1,6 +1,8 @@ using ABB.SrcML.Test.Utilities; using NUnit.Framework; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; namespace ABB.SrcML.Data.Test { @@ -27,118 +29,94 @@ public void ClassSetup() { [Test] public void TestGlobalStatement() { - ////Example.cpp - //char* bar = "Hello, world!"; - //int foo = 42; - var xml = @"char* bar = ""Hello, world!""; -int foo = 42;"; - var unit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xml, "Example.cpp"); + var xml = @"char* bar = 'Hello, world!'; + int foo = 42;"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Example.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var unit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Example.cpp"); var globalScope = parser[Language.CPlusPlus].ParseFileUnit(unit); var actual = globalScope.GetStatementForLocation(new SourceLocation("Example.cpp", 2, 5)); - Assert.AreSame(globalScope.ChildStatements[1], actual); + Assert.AreSame(globalScope.ChildStatements[0], actual); } [Test] public void TestLocationInClass_CSharp() { - ////Foo.cs - //namespace Example { - // class Foo { - // int bar = 42; - // } - //} - var xml = @"namespace Example { - class Foo { - int bar = 42; - } -}"; - var unit = fileSetup[Language.CSharp].GetFileUnitForXmlSnippet(xml, "Foo.cs"); + var xml = @"namespace Example { + class Foo { + int bar = 42; + } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var unit = fileSetup[Language.CSharp].GetFileUnitForXmlSnippet(srcML, "Foo.cs"); var globalScope = parser[Language.CSharp].ParseFileUnit(unit); var foo = globalScope.GetDescendants().First(t => t.Name == "Foo"); var stmt = foo.ChildStatements[0]; var stmtActual = globalScope.GetStatementForLocation(new SourceLocation("Foo.cs", 3, 14)); - Assert.AreSame(stmt, stmtActual); + Assert.AreSame(stmt, stmtActual.ChildStatements[0]); - var fooActual = globalScope.GetStatementForLocation(new SourceLocation("Foo.cs", 2, 6)); + var fooActual = globalScope.GetStatementForLocation(new SourceLocation("Foo.cs", 3, 14)); Assert.AreSame(foo, fooActual); } [Test] public void TestLocationInMain_Cpp() { - //#include - // - //char* MyFunction(int foo) { - // if(foo > 0) { - // return "Hello world!"; - // } else { - // return "Goodbye cruel world!"; - // } - //} - // - //int main(int argc, char* argv[]) { - // std::cout<#include <iostream> - -char* MyFunction(int foo) { - if(foo > 0) { - return ""Hello world!""; - } else { - return ""Goodbye cruel world!""; - } -} - -int main(int argc, char* argv[]) { - std::cout<<MyFunction(42); - return 0; -}"; - var fileUnit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xml, "function_def.cpp"); + var xml = @"#include + char* MyFunction(int foo) { + if(foo > 0) { + return 'Hello world!'; + } else { + return 'Goodbye cruel world!'; + } + } + + int main(int argc, char* argv[]) { + std::cout<() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "function_def.cpp"); var globalScope = parser[Language.CPlusPlus].ParseFileUnit(fileUnit); var main = globalScope.GetDescendants().First(md => md.Name == "main"); - Assert.AreSame(main.ChildStatements[0], globalScope.GetStatementForLocation(new SourceLocation("function_def.cpp", 12, 20))); + Assert.AreSame(main.ChildStatements[0], globalScope.GetStatementForLocation(new SourceLocation("function_def.cpp", 11, 17))); } [Test] public void TestLocationInMethodDefinition_Cpp() { - ////Foo.h - //class Foo { - //public: - // int bar(int); - //} - var hXml = @"class Foo { -public: - int bar(int); -}"; - var hUnit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(hXml, "Foo.h"); + var hXml = @"class Foo { + public: + int bar(int); + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(hXml, "Foo.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var hUnit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.h"); var globalScope = parser[Language.CPlusPlus].ParseFileUnit(hUnit); - ////Foo.cpp - //#include "Foo.h" - //int Foo::bar(int baz) { - // return baz + 1; - //} - var cppXml = @"#include ""Foo.h"" -int Foo::bar(int baz) { - return baz + 1; -}"; - var cppUnit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(cppXml, "Foo.cpp"); + + var cppXml = @"#include 'Foo.h' + int Foo::bar(int baz) { + return baz + 1; + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(cppXml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var cppUnit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "Foo.cpp"); globalScope = globalScope.Merge(parser[Language.CPlusPlus].ParseFileUnit(cppUnit)); var bar = globalScope.GetDescendants().First(md => md.Name == "bar"); Assert.AreEqual(1, bar.ChildStatements.Count); - Assert.AreEqual(bar.ChildStatements[0], globalScope.GetStatementForLocation(new SourceLocation("Foo.cpp", 3, 8))); + Assert.AreEqual(bar.ChildStatements[0], globalScope.GetStatementForLocation(new SourceLocation("Foo.cpp", 3, 17))); } [Test] public void TestLocationInForLoop() { - //for(int i = 0; i < foo.Count; i++) { - // Bar(i); - //} - var xml = @"for(int i = 0; i < foo.Count; i++) { - Bar(i); -}"; - var xmlElement = fileSetup[Language.CSharp].GetFileUnitForXmlSnippet(xml, "Foo.cs"); + var xml = @"for(int i = 0; i < foo.Count; i++) { + Bar(i); + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = fileSetup[Language.CSharp].GetFileUnitForXmlSnippet(srcML, "Foo.cs"); var globalScope = parser[Language.CSharp].ParseFileUnit(xmlElement); var forLoop = globalScope.GetDescendants().First(); diff --git a/ABB.SrcML.Data.Test/JavaCodeParserTests.cs b/ABB.SrcML.Data.Test/JavaCodeParserTests.cs index aa93b8b..fc6c441 100644 --- a/ABB.SrcML.Data.Test/JavaCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/JavaCodeParserTests.cs @@ -17,29 +17,25 @@ using System.Linq; using System.Xml.Linq; -namespace ABB.SrcML.Data.Test -{ +namespace ABB.SrcML.Data.Test { [TestFixture] [Category("Build")] - internal class JavaCodeParserTests - { + internal class JavaCodeParserTests { private AbstractCodeParser codeParser; private SrcMLFileUnitSetup fileSetup; [TestFixtureSetUp] - public void ClassSetup() - { + public void ClassSetup() { codeParser = new JavaCodeParser(); fileSetup = new SrcMLFileUnitSetup(Language.Java); } [Test] - public void TestCreateAliasesForFiles_ImportClass() - { + public void TestCreateAliasesForFiles_ImportClass() { string xml = @"import x.y.z;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -52,11 +48,11 @@ public void TestCreateAliasesForFiles_ImportClass() } [Test] - public void TestCreateAliasesForFiles_ImportNamespace() - { + public void TestCreateAliasesForFiles_ImportNamespace() { string xml = @"import x . /*test */ y /*test */ . z .* /*test*/;"; + //import x . /*test */ y /*test */ . z .* /*test*/;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -68,12 +64,11 @@ public void TestCreateAliasesForFiles_ImportNamespace() } [Test] - public void TestCreateTypeDefinition_ClassInPackage() - { + public void TestCreateTypeDefinition_ClassInPackage() { string xml = @"package A.B.C; public class D { }"; LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLA = runD.GenerateSrcMLFromString(xml, "D.java", Language.Java, new Collection() { }, false); + string srcMLA = runD.GenerateSrcMLFromString(xml, "D.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "D.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -104,12 +99,11 @@ public class D { }"; } [Test] - public void TestCreateTypeDefinitions_Class() - { + public void TestCreateTypeDefinitions_Class() { string xml = @"class A { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -122,13 +116,12 @@ public void TestCreateTypeDefinitions_Class() } [Test] - public void TestCreateTypeDefinitions_ClassInFunction() - { + public void TestCreateTypeDefinitions_ClassInFunction() { string xml = @"class A { int foo() { class B { } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -145,16 +138,13 @@ public void TestCreateTypeDefinitions_ClassInFunction() } [Test] - public void TestCreateTypeDefinitions_ClassWithExtendsAndImplements() - { - - string xml = @"Foo.java - public class Foo extends xyzzy implements A, B, C { + public void TestCreateTypeDefinitions_ClassWithExtendsAndImplements() { + string xml = @"public class Foo extends xyzzy implements A, B, C { public int bar; }"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -169,19 +159,17 @@ public class Foo extends xyzzy implements A, B, C { select parent.Name; var tests = Enumerable.Zip(new[] { "xyzzy", "A", "B", "C" }, parentNames, (e, a) => e == a); - foreach (var test in tests) - { + foreach (var test in tests) { Assert.That(test); } } [Test] - public void TestCreateTypeDefinitions_ClassWithInnerClass() - { + public void TestCreateTypeDefinitions_ClassWithInnerClass() { string xml = @"class A { class B { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -195,12 +183,11 @@ public void TestCreateTypeDefinitions_ClassWithInnerClass() } [Test] - public void TestCreateTypeDefinitions_ClassWithParents() - { + public void TestCreateTypeDefinitions_ClassWithParents() { string xml = @"class A implements B,C,D { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -213,19 +200,17 @@ public void TestCreateTypeDefinitions_ClassWithParents() select parent.Name; var tests = Enumerable.Zip(new[] { "B", "C", "D" }, parentNames, (e, a) => e == a); - foreach (var test in tests) - { + foreach (var test in tests) { Assert.That(test); } } [Test] - public void TestCreateTypeDefinitions_ClassWithQualifiedParent() - { + public void TestCreateTypeDefinitions_ClassWithQualifiedParent() { string xml = @"class D implements A.B.C { }"; LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLA = runD.GenerateSrcMLFromString(xml, "D.java", Language.Java, new Collection() { }, false); + string srcMLA = runD.GenerateSrcMLFromString(xml, "D.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "D.java"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -246,15 +231,13 @@ public void TestCreateTypeDefinitions_ClassWithQualifiedParent() } [Test] - public void TestCreateTypeDefinitions_ClassWithSuperClass() - { + public void TestCreateTypeDefinitions_ClassWithSuperClass() { - string xml = @"Foo.java - public class Foo extends xyzzy { + string xml = @"public class Foo extends xyzzy { public int bar; }"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -268,13 +251,12 @@ public class Foo extends xyzzy { } [Test] - public void TestCreateTypeDefinitions_InnerClassWithNamespace() - { + public void TestCreateTypeDefinitions_InnerClassWithNamespace() { string xml = @"package A; class B { class C { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLA = runB.GenerateSrcMLFromString(xml, "B.java", Language.Java, new Collection() { }, false); + string srcMLA = runB.GenerateSrcMLFromString(xml, "B.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "B.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -294,30 +276,28 @@ public void TestCreateTypeDefinitions_InnerClassWithNamespace() } [Test] - public void TestCreateTypeDefinitions_Interface() - { - + public void TestCreateTypeDefinitions_Interface() { string xml = @"interface A { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); - var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; - var globalNamespace = actual.ParentStatement as NamespaceDefinition; + var actual = codeParser.ParseFileUnit(xmlElement); + var actual2 = actual.ChildStatements.First() as TypeDefinition; + var globalNamespace = actual as NamespaceDefinition; - Assert.AreEqual("A", actual.Name); - Assert.AreEqual(TypeKind.Interface, actual.Kind); + Assert.AreEqual("A", actual2.Name); + Assert.AreEqual(TypeKind.Interface, actual2.Kind); Assert.That(globalNamespace.IsGlobal); } [Test] - public void TestFieldCreation() - { + public void TestFieldCreation() { string xml = @"class A { int B; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -333,14 +313,13 @@ public void TestFieldCreation() } [Test] - public void TestGetAccessModifierForMethod_None() - { + public void TestGetAccessModifierForMethod_None() { string xml = @"public class Foo { bool Bar() { return true; } }"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var globalScope = codeParser.ParseFileUnit(unit); @@ -350,14 +329,13 @@ public void TestGetAccessModifierForMethod_None() } [Test] - public void TestGetAccessModifierForMethod_Normal() - { + public void TestGetAccessModifierForMethod_Normal() { string xml = @"public class Foo { public bool Bar() { return true; } }"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var globalScope = codeParser.ParseFileUnit(unit); @@ -367,14 +345,13 @@ public void TestGetAccessModifierForMethod_Normal() } [Test] - public void TestGetAccessModifierForMethod_Static() - { + public void TestGetAccessModifierForMethod_Static() { string xml = @"public class Foo { static public bool Bar() { return true; } }"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var globalScope = codeParser.ParseFileUnit(unit); @@ -384,11 +361,10 @@ public void TestGetAccessModifierForMethod_Static() } [Test] - public void TestGetAccessModifierForType_None() - { + public void TestGetAccessModifierForType_None() { string xml = @"class Foo {}"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var globalScope = codeParser.ParseFileUnit(unit); @@ -398,12 +374,11 @@ public void TestGetAccessModifierForType_None() } [Test] - public void TestGetAccessModifierForType_Normal() - { + public void TestGetAccessModifierForType_Normal() { string xml = @"public class Foo {}"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var globalScope = codeParser.ParseFileUnit(unit); @@ -413,11 +388,10 @@ public void TestGetAccessModifierForType_Normal() } [Test] - public void TestGetAccessModifierForType_Static() - { + public void TestGetAccessModifierForType_Static() { string xml = @"static public class Foo {}"; LibSrcMLRunner runFoo = new LibSrcMLRunner(); - string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { }, false); + string srcMLA = runFoo.GenerateSrcMLFromString(xml, "Foo.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "Foo.java"); var globalScope = codeParser.ParseFileUnit(unit); @@ -429,8 +403,7 @@ public void TestGetAccessModifierForType_Static() [Test] - public void TestMethodCallCreation_WithConflictingMethodNames() - { + public void TestMethodCallCreation_WithConflictingMethodNames() { string a_xml = @"class A { B b; boolean Contains() { b.Contains(); } @@ -442,10 +415,10 @@ public void TestMethodCallCreation_WithConflictingMethodNames() }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(a_xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(a_xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnitA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(b_xml, "B.java", Language.Java, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(b_xml, "B.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnitB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.java"); var scopeForA = codeParser.ParseFileUnit(fileUnitA); @@ -469,8 +442,7 @@ public void TestMethodCallCreation_WithConflictingMethodNames() } [Test] - public void TestMethodCallCreation_WithThisKeyword() - { + public void TestMethodCallCreation_WithThisKeyword() { string a_xml = @"class A { void Bar() { } class B { @@ -481,7 +453,7 @@ class B { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(a_xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(a_xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(fileUnit); @@ -505,8 +477,7 @@ class B { } [Test] - public void TestMethodCallCreation_WithSuperKeyword() - { + public void TestMethodCallCreation_WithSuperKeyword() { string xml = @"class B { public void Foo() { } } @@ -517,7 +488,7 @@ public void Bar() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -539,8 +510,7 @@ public void Bar() { } [Test] - public void TestMethodCallCreation_SuperConstructor() - { + public void TestMethodCallCreation_SuperConstructor() { string xml = @"class B { public B(int num) { } } @@ -550,7 +520,7 @@ public C() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -569,15 +539,12 @@ public C() { } [Test] - public void TestMethodCallCreation_ConstructorFromOtherNamespace() - { - + public void TestMethodCallCreation_ConstructorFromOtherNamespace() { string c_xml = @"package A.B; class C { public C() { } }"; - string e_xml = @"package A.D; import A.B.*; class E { @@ -587,10 +554,10 @@ public void main() { }"; LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLA = runC.GenerateSrcMLFromString(c_xml, "C.java", Language.Java, new Collection() { }, false); + string srcMLA = runC.GenerateSrcMLFromString(c_xml, "C.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "C.java"); LibSrcMLRunner runE = new LibSrcMLRunner(); - string srcMLE = runE.GenerateSrcMLFromString(e_xml, "E.java", Language.Java, new Collection() { }, false); + string srcMLE = runE.GenerateSrcMLFromString(e_xml, "E.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var eUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLE, "E.java"); var cScope = codeParser.ParseFileUnit(cUnit); @@ -632,14 +599,13 @@ from call in expr.GetDescendantsAndSelf() } [Test] - public void TestVariablesWithSpecifiers() - { + public void TestVariablesWithSpecifiers() { string testXml = @"public static int A; public final int B; private static final Foo C;"; LibSrcMLRunner runtest = new LibSrcMLRunner(); - string srcMLA = runtest.GenerateSrcMLFromString(testXml, "test.java", Language.Java, new Collection() { }, false); + string srcMLA = runtest.GenerateSrcMLFromString(testXml, "test.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "test.java"); var globalScope = codeParser.ParseFileUnit(testUnit); @@ -665,15 +631,14 @@ public void TestVariablesWithSpecifiers() } [Test] - public void TestImport_NameResolution() - { + public void TestImport_NameResolution() { string xmlA = @"import Foo.Bar.*; package A; public class Robot { public Baz GetThingy() { return new Baz(); } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); string xmlB = @"package Foo.Bar; @@ -681,7 +646,7 @@ public class Baz { public Baz() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.java", Language.Java, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.java"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -705,14 +670,13 @@ public Baz() { } } [Test] - public void TestAlias_NameResolution() - { + public void TestAlias_NameResolution() { string xmlA = @"package Foo.Bar; public class Baz { public static void DoTheThing() { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); string xmlB = @"import Foo.Bar.Baz; package A; @@ -722,7 +686,7 @@ public B() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.java", Language.Java, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.java"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -743,20 +707,19 @@ public B() { } [Test] - public void BasicParentTest_Java() - { + public void BasicParentTest_Java() { string a_xml = @"class A implements B { }"; string b_xml = @"class B { }"; string c_xml = @"class C { A a; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(a_xml, "A.java", Language.Java, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(a_xml, "A.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnitA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(b_xml, "B.java", Language.Java, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(b_xml, "B.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnitB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.java"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(c_xml, "C.java", Language.Java, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(c_xml, "C.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnitC = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.java"); var globalScope = codeParser.ParseFileUnit(fileUnitA); @@ -782,15 +745,12 @@ from decl in stmt.GetExpressions().OfType() } [Test] - public void TestTypeUseForOtherNamespace() - { - + public void TestTypeUseForOtherNamespace() { string c_xml = @"package A.B; class C { int Foo(); }"; - string e_xml = @"package D; import A.B.*; class E { @@ -801,10 +761,10 @@ public static void main() { }"; LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLA = runC.GenerateSrcMLFromString(c_xml, "C.java", Language.Java, new Collection() { }, false); + string srcMLA = runC.GenerateSrcMLFromString(c_xml, "C.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "C.java"); LibSrcMLRunner runE = new LibSrcMLRunner(); - string srcMLE = runE.GenerateSrcMLFromString(e_xml, "E.java", Language.Java, new Collection() { }, false); + string srcMLE = runE.GenerateSrcMLFromString(e_xml, "E.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var eUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLE, "E.java"); var globalScope = codeParser.ParseFileUnit(cUnit); diff --git a/ABB.SrcML.Data.Test/MergeTests.cs b/ABB.SrcML.Data.Test/MergeTests.cs index 78e800d..11fb461 100644 --- a/ABB.SrcML.Data.Test/MergeTests.cs +++ b/ABB.SrcML.Data.Test/MergeTests.cs @@ -17,6 +17,7 @@ using System.Threading.Tasks; using NUnit.Framework; using ABB.SrcML.Test.Utilities; +using System.Collections.ObjectModel; namespace ABB.SrcML.Data.Test { [TestFixture] @@ -41,14 +42,16 @@ public void ClassSetup() { [Test] public void TestConstructorMerge_Cpp() { - //A.h class A { A(); }; - string header_xml = @"class A { A(); };"; + string header_xml = @"class A { A(); };"; - //A.cpp A::A() { } - string impl_xml = @"A::A() { }"; + string impl_xml = @"A::A() { }"; - var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(header_xml, "A.h"); - var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(impl_xml, "A.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(header_xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.h"); + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLE = runE.GenerateSrcMLFromString(impl_xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLE, "A.cpp"); var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(header); var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(implementation); @@ -72,43 +75,29 @@ public void TestConstructorMerge_Cpp() { [Test] public void TestNestedConstructorMerge_Cpp() { - //Foo.h - //class Foo - //{ - //public: - // Foo(int, int, char); - // virtual ~Foo(); - // struct Bar - // { - // Bar(float, float); - // virtual ~Bar(); - // } - //}; - string headerXml = @"class Foo -{ -public: - Foo(int, int, char); - virtual ~Foo(); - struct Bar - { - Bar(float, float); - virtual ~Bar(); - } -};"; - //Foo.cpp - //Foo::Bar::Bar(float a, float b) { } - //Foo::Bar::~Bar() { } - // - //Foo::Foo(int a, int b, char c) { } - //Foo::~Foo() { } - string implXml = @"Foo::Bar::Bar(float a, float b) { } -Foo::Bar::~Bar() { } - -Foo::Foo(int a, int b, char c) { } -Foo::~Foo() { } -"; - var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(headerXml, "Foo.h"); - var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(implXml, "Foo.cpp"); + string headerXml = @"class Foo + { + public: + Foo(int, int, char); + virtual ~Foo(); + struct Bar + { + Bar(float, float); + virtual ~Bar(); + } + };"; + + string implXml = @"Foo::Bar::Bar(float a, float b) { } + Foo::Bar::~Bar() { } + + Foo::Foo(int a, int b, char c) { } + Foo::~Foo() { }"; + LibSrcMLRunner runF = new LibSrcMLRunner(); + string srcMLF = runF.GenerateSrcMLFromString(headerXml, "Foo.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLF, "Foo.h"); + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLE = runE.GenerateSrcMLFromString(implXml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLE, "Foo.cpp"); var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(header); var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(implementation); @@ -134,15 +123,16 @@ public void TestNestedConstructorMerge_Cpp() { [Test] public void TestDestructorMerge_Cpp() { - //A.h class A { ~A(); }; - string header_xml = @"class A { ~A(); }; -"; + string header_xml = @"class A { ~A(); };"; - //A.cpp A::~A() { } - string impl_xml = @"A::~A() { }"; + string impl_xml = @"A::~A() { }"; - var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(header_xml, "A.h"); - var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(impl_xml, "A.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(header_xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.h"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(impl_xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "A.cpp"); var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(header); var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(implementation); @@ -165,16 +155,16 @@ public void TestDestructorMerge_Cpp() { } [Test] public void TestMethodDefinitionMerge_Cpp() { - // # A.h class A { int Foo(); }; - string header_xml = @"class A { - int Foo(); -};"; + string header_xml = @"class A { int Foo(); };"; - // # A.cpp int A::Foo() { int bar = 1; return bar; } - string impl_xml = @"int A::Foo() { int bar = 1; return bar; }"; + string impl_xml = @"int A::Foo() { int bar = 1; return bar; }"; - var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(header_xml, "A.h"); - var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(impl_xml, "A.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(header_xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.h"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(impl_xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "A.cpp"); var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(header); var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(implementation); @@ -191,23 +181,23 @@ public void TestMethodDefinitionMerge_Cpp() { var methodFoo = typeA.ChildStatements.First() as MethodDefinition; Assert.AreEqual("Foo", methodFoo.Name); Assert.AreEqual(2, methodFoo.ChildStatements.Count()); - // TODO Assert.AreEqual(1, methodFoo.DeclaredVariables.Count()); + //TODO Assert.AreEqual(1, methodFoo.DeclaredVariables.Count()); Assert.AreEqual("A.cpp", methodFoo.PrimaryLocation.SourceFileName); Assert.AreEqual(AccessModifier.Private, methodFoo.Accessibility); } [Test] public void TestMethodDefinitionMerge_NoParameterName() { - ////Foo.h - //int Foo(char); - string declXml = "int Foo(char);"; - var fileunitDecl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(declXml, "Foo.h"); + string declXml = "int Foo(char);"; + LibSrcMLRunner runF = new LibSrcMLRunner(); + string srcMLF = runF.GenerateSrcMLFromString(declXml, "Foo.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileunitDecl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLF, "Foo.h"); var declarationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(fileunitDecl); - ////Foo.cpp - //int Foo(char bar) { return 0; } - string defXml = "int Foo(char bar) { return 0; }"; - var fileUnitDef = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(defXml, "Foo.cpp"); + string defXml = "int Foo(char bar) { return 0; }"; + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLE = runE.GenerateSrcMLFromString(defXml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitDef = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLE, "Foo.cpp"); var globalScope = new NamespaceDefinition(); var definitionScope = CodeParser[Language.CPlusPlus].ParseFileUnit(fileUnitDef); @@ -229,18 +219,16 @@ public void TestMethodDefinitionMerge_NoParameterName() { [Test] public void TestCreateMethodDefinition_TwoUnresolvedParents() { - // # B.h namespace A { class B { }; } - string xmlh = @"namespace A { - class B { - }; -}"; + string xmlh = @"namespace A { class B { }; }"; - // # B.cpp int A::B::Foo() { return 0; } - string xmlcpp = @"int A::B::Foo() { -}"; + string xmlcpp = @"int A::B::Foo() { }"; - var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlh, "B.h"); - var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlcpp, "B.cpp"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(xmlh, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "B.h"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(xmlcpp, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "B.cpp"); var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlHeader); var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlImpl); @@ -270,16 +258,16 @@ public void TestCreateMethodDefinition_TwoUnresolvedParents() { [Test] public void TestCreateMethodDefinition_TwoUnresolvedParentsWithPrototype() { - // # B.h namespace A { class B { int Foo(); }; } - string xmlh = @"namespace A { class B { int Foo(); }; } -"; + string xmlh = @"namespace A { class B { int Foo(); }; }"; - // # B.cpp int A::B::Foo() { return 0; } - string xmlcpp = @"int A::B::Foo() { -}"; + string xmlcpp = @"int A::B::Foo() { }"; - var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlh, "B.h"); - var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlcpp, "B.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(xmlh, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "B.h"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(xmlcpp, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlHeader); var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlImpl); @@ -308,53 +296,42 @@ public void TestCreateMethodDefinition_TwoUnresolvedParentsWithPrototype() { } [Test] public void TestMethodDefinitionMerge_NoParameters() { - ////Foo.h - //int Foo(); - string declXml = "int Foo();"; - var fileunitDecl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(declXml, "Foo.h"); + string declXml = "int Foo();"; + LibSrcMLRunner runF = new LibSrcMLRunner(); + string srcMLF = runF.GenerateSrcMLFromString(declXml, "Foo.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileunitDecl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLF, "Foo.h"); var declarationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(fileunitDecl); - ////Foo.cpp - //int Foo() { return 0; } - string defXml = @"int Foo() { return 0; }"; - var fileUnitDef = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(defXml, "Foo.cpp"); + string defXml = @"int Foo() { return 0; }"; + LibSrcMLRunner runG = new LibSrcMLRunner(); + string srcMLG = runG.GenerateSrcMLFromString(defXml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitDef = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLG, "Foo.cpp"); var definitionScope = CodeParser[Language.CPlusPlus].ParseFileUnit(fileUnitDef); var globalScope = declarationScope.Merge(definitionScope); Assert.AreEqual(1, globalScope.ChildStatements.Count()); - Assert.AreEqual("Foo", ((MethodDefinition) globalScope.ChildStatements.First()).Name); + Assert.AreEqual("Foo", ((MethodDefinition)globalScope.ChildStatements.First()).Name); } [Test] public void TestNamespaceMerge_Cpp() { - // # D.h namespace A { namespace B { namespace C { class D { }; } } } - string d_xml = @"namespace A { - namespace B { - namespace C { - class D { }; - } - } -}"; - - // # E.h namespace A { namespace B { namespace C { class E { }; } } } - string e_xml = @"namespace A { - namespace B { - namespace C { - class E { }; - } - } -}"; - - // # F.h namespace D { class F { }; } - string f_xml = @"namespace D { - class F { }; -}"; - - var fileUnitD = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(d_xml, "D.h"); - var fileUnitE = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(e_xml, "E.h"); - var fileUnitF = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(f_xml, "F.h"); + string d_xml = @"namespace A { namespace B { namespace C { class D { }; } } }"; + + string e_xml = @"namespace A { namespace B { namespace C { class E { }; } } }"; + + string f_xml = @"namespace D { class F { }; }"; + + LibSrcMLRunner runD = new LibSrcMLRunner(); + string srcMLD = runD.GenerateSrcMLFromString(d_xml, "D.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitD = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLD, "D.h"); + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLE = runE.GenerateSrcMLFromString(e_xml, "E.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitE = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLE, "E.h"); + LibSrcMLRunner runF = new LibSrcMLRunner(); + string srcMLF = runF.GenerateSrcMLFromString(f_xml, "F.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitF = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLF, "F.h"); var globalScope = new NamespaceDefinition(); var scopeD = CodeParser[Language.CPlusPlus].ParseFileUnit(fileUnitD); @@ -397,18 +374,21 @@ public void TestNamespaceMerge_Cpp() { [Test] public void TestNamespaceMerge_Java() { - // # D.java package A.B.C; class D { public void Foo() { } } - string d_xml = @"package A.B.C; class D { public void Foo() { } }"; + string d_xml = @"package A.B.C; class D { public void Foo() { } }"; - // # E.java package A.B.C; class E { public void Bar() { } } - string e_xml = @"package A.B.C; class E { public void Bar() { } }"; + string e_xml = @"package A.B.C; class E { public void Bar() { } }"; - // # F.java package D; class F { public void Oof() { } } - string f_xml = @"package D; class F { public void Oof() { } }"; + string f_xml = @"package D; class F { public void Oof() { } }"; - var fileUnitD = FileUnitSetup[Language.Java].GetFileUnitForXmlSnippet(d_xml, "D.java"); - var fileUnitE = FileUnitSetup[Language.Java].GetFileUnitForXmlSnippet(e_xml, "E.java"); - var fileUnitF = FileUnitSetup[Language.Java].GetFileUnitForXmlSnippet(f_xml, "F.java"); + LibSrcMLRunner runD = new LibSrcMLRunner(); + string srcMLD = runD.GenerateSrcMLFromString(d_xml, "D.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitD = FileUnitSetup[Language.Java].GetFileUnitForXmlSnippet(srcMLD, "D.java"); + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLE = runE.GenerateSrcMLFromString(e_xml, "E.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitE = FileUnitSetup[Language.Java].GetFileUnitForXmlSnippet(srcMLE, "E.java"); + LibSrcMLRunner runF = new LibSrcMLRunner(); + string srcMLF = runF.GenerateSrcMLFromString(f_xml, "F.java", Language.Java, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitF = FileUnitSetup[Language.Java].GetFileUnitForXmlSnippet(srcMLF, "F.java"); var globalScopeD = CodeParser[Language.Java].ParseFileUnit(fileUnitD); var globalScopeE = CodeParser[Language.Java].ParseFileUnit(fileUnitE); @@ -446,16 +426,16 @@ public void TestNamespaceMerge_Java() { [Test] public void TestMethodDefinitionMerge_DifferentPrefixes() { - ////A.cpp - // int A::Foo() { return 0; } - string aCpp = @"int A::Foo() { return 0; }"; - var fileUnitA = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(aCpp, "A.cpp"); + string aCpp = @"int A::Foo() { return 0; }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(aCpp, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitA = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var aScope = CodeParser[Language.CPlusPlus].ParseFileUnit(fileUnitA); - ////B.cpp - // int B::Foo() { return 1; } - string bCpp = @"int B::Foo() { return 1; }"; - var fileUnitB = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(bCpp, "B.cpp"); + string bCpp = @"int B::Foo() { return 1; }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(bCpp, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var fileUnitB = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); var bScope = CodeParser[Language.CPlusPlus].ParseFileUnit(fileUnitB); var globalScope = aScope.Merge(bScope); @@ -464,31 +444,24 @@ public void TestMethodDefinitionMerge_DifferentPrefixes() { } [Test] public void TestPartialClassMerge_CSharp() { - ////A1.cs - //public partial class A { - // public int Execute() { - // return 0; - // } - //} - string a1Xml = @"public partial class A { - public int Execute() { - return 0; - } -}"; - var a1FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a1Xml, "A1.cs"); + string a1Xml = @"public partial class A { + public int Execute() { + return 0; + } + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a1FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(srcMLA, "A1.cs"); var globalScope = CodeParser[Language.CSharp].ParseFileUnit(a1FileUnit); - ////A2.cs - //public partial class A { - // private bool Foo() { - // return true; - // } - //} - string a2Xml = @"public partial class A { - private bool Foo() { - return true; - } -}"; - var a2FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a2Xml, "A2.cs"); + + string a2Xml = @"public partial class A { + private bool Foo() { + return true; + } + }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a2FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(srcMLB, "A2.cs"); globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(a2FileUnit)); Assert.AreEqual(1, globalScope.ChildStatements.Count()); @@ -501,23 +474,20 @@ public void TestPartialClassMerge_CSharp() { [Test] public void TestPartialMethodMerge_CSharp() { - ////A1.cs - //public partial class A { - // public partial int Foo(); - //} - string a1Xml = @"public partial class A { - public partial int Foo(); -}"; - var a1FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a1Xml, "A1.cs"); + string a1Xml = @"public partial class A { + public partial int Foo(); + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a1FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(srcMLA, "A1.cs"); var globalScope = CodeParser[Language.CSharp].ParseFileUnit(a1FileUnit); - ////A2.cs - //public partial class A { - // public partial int Foo() { return 42; } - //} - string a2Xml = @"public partial class A { - public partial int Foo() { return 42; } -}"; - var a2FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a2Xml, "A2.cs"); + + string a2Xml = @"public partial class A { + public partial int Foo() { return 42; } + }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var a2FileUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(srcMLB, "A2.cs"); globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(a2FileUnit)); Assert.AreEqual(1, globalScope.ChildStatements.Count()); @@ -531,23 +501,18 @@ public void TestPartialMethodMerge_CSharp() { [Test] public void TestUnresolvedParentMerge_ClassEncounteredFirst_Cpp() { - // # A.cpp int A::Foo() { return 0; } - // - // int A::Bar() { return 0; } - string xmlcpp = @"int A::Foo() { - return 0; -} + string xmlcpp = @"int A::Foo() { return 0; } + int A::Bar() { return 0; }"; -int A::Bar() { - return 0; -}"; - // # A.h class A { }; - string xmlh = @"class A { -};"; + string xmlh = @"class A { };"; - var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlcpp, "A.cpp"); - var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlh, "A.h"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(xmlcpp, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(xmlh, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "A.h"); var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlHeader); Assert.AreEqual(1, globalScope.ChildStatements.Count()); @@ -577,23 +542,17 @@ public void TestUnresolvedParentMerge_ClassEncounteredFirst_Cpp() { [Test] public void TestUnresolvedParentMerge_MethodsEncounteredFirst_Cpp() { - // # A.cpp int A::Foo() { return 0; } - // - // int A::Bar() { return 0; } - string xmlcpp = @"int A::Foo() { - return 0; -} - -int A::Bar() { - return 0; -}"; - - // # A.h class A { }; - string xmlh = @"class A { -};"; - - var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlcpp, "A.cpp"); - var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xmlh, "A.h"); + string xmlcpp = @"int A::Foo() { return 0; } + int A::Bar() { return 0; }"; + + string xmlh = @"class A { };"; + + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(xmlcpp, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlImpl = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLB = runB.GenerateSrcMLFromString(xmlh, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlHeader = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLB, "A.h"); var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlImpl); Assert.AreEqual(2, globalScope.ChildStatements.Count()); diff --git a/ABB.SrcML.Data.Test/ProgamElementTests.cs b/ABB.SrcML.Data.Test/ProgamElementTests.cs index b597839..d80f86c 100644 --- a/ABB.SrcML.Data.Test/ProgamElementTests.cs +++ b/ABB.SrcML.Data.Test/ProgamElementTests.cs @@ -17,6 +17,7 @@ using System.Threading.Tasks; using ABB.SrcML.Test.Utilities; using NUnit.Framework; +using System.Collections.ObjectModel; namespace ABB.SrcML.Data.Test { [TestFixture] @@ -41,13 +42,13 @@ public void ClassSetup() { [Test] public void TestSiblingsBeforeSelf() { - var a = new VariableUse() {Name = "a"}; - var plus = new OperatorUse() {Text = "+"}; - var foo = new VariableUse() {Name = "foo"}; - var times = new OperatorUse() {Text = "*"}; - var b = new VariableUse() {Name = "b"}; + var a = new VariableUse() { Name = "a" }; + var plus = new OperatorUse() { Text = "+" }; + var foo = new VariableUse() { Name = "foo" }; + var times = new OperatorUse() { Text = "*" }; + var b = new VariableUse() { Name = "b" }; var exp = new Expression(); - exp.AddComponents(new Expression[] {a, plus, foo, times, b}); + exp.AddComponents(new Expression[] { a, plus, foo, times, b }); var fooSiblings = foo.GetSiblingsBeforeSelf().ToList(); Assert.AreEqual(2, fooSiblings.Count()); @@ -60,13 +61,13 @@ public void TestSiblingsBeforeSelf() { [Test] public void TestSiblingsBeforeSelf_MissingChild() { - var a = new VariableUse() {Name = "a"}; - var plus = new OperatorUse() {Text = "+"}; - var foo = new VariableUse() {Name = "foo"}; - var times = new OperatorUse() {Text = "*"}; - var b = new VariableUse() {Name = "b"}; + var a = new VariableUse() { Name = "a" }; + var plus = new OperatorUse() { Text = "+" }; + var foo = new VariableUse() { Name = "foo" }; + var times = new OperatorUse() { Text = "*" }; + var b = new VariableUse() { Name = "b" }; var exp = new Expression(); - exp.AddComponents(new Expression[] {a, plus, foo, times, b}); + exp.AddComponents(new Expression[] { a, plus, foo, times, b }); var dot = new OperatorUse { Text = ".", @@ -78,13 +79,13 @@ public void TestSiblingsBeforeSelf_MissingChild() { [Test] public void TestSiblingsAfterSelf() { - var a = new VariableUse() {Name = "a"}; - var plus = new OperatorUse() {Text = "+"}; - var foo = new VariableUse() {Name = "foo"}; - var times = new OperatorUse() {Text = "*"}; - var b = new VariableUse() {Name = "b"}; + var a = new VariableUse() { Name = "a" }; + var plus = new OperatorUse() { Text = "+" }; + var foo = new VariableUse() { Name = "foo" }; + var times = new OperatorUse() { Text = "*" }; + var b = new VariableUse() { Name = "b" }; var exp = new Expression(); - exp.AddComponents(new Expression[] {a, plus, foo, times, b}); + exp.AddComponents(new Expression[] { a, plus, foo, times, b }); var plusSiblings = plus.GetSiblingsAfterSelf().ToList(); Assert.AreEqual(3, plusSiblings.Count()); @@ -98,13 +99,13 @@ public void TestSiblingsAfterSelf() { [Test] public void TestSiblingsAfterSelf_MissingChild() { - var a = new VariableUse() {Name = "a"}; - var plus = new OperatorUse() {Text = "+"}; - var foo = new VariableUse() {Name = "foo"}; - var times = new OperatorUse() {Text = "*"}; - var b = new VariableUse() {Name = "b"}; + var a = new VariableUse() { Name = "a" }; + var plus = new OperatorUse() { Text = "+" }; + var foo = new VariableUse() { Name = "foo" }; + var times = new OperatorUse() { Text = "*" }; + var b = new VariableUse() { Name = "b" }; var exp = new Expression(); - exp.AddComponents(new Expression[] {a, plus, foo, times, b}); + exp.AddComponents(new Expression[] { a, plus, foo, times, b }); var dot = new OperatorUse { Text = ".", @@ -118,17 +119,15 @@ public void TestSiblingsAfterSelf_MissingChild() { [TestCase(Language.CSharp)] [TestCase(Language.Java)] public void TestGetNamedChildren_Statement(Language lang) { - //int foo = 17; - //while(bar) { - // MethodCall(foo); - // int foo = 42; - //} - string xml = @"int foo = 17; -while(bar) { - MethodCall(foo); - int foo = 42; -}"; - var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(xml, "test.code"); + + string xml = @"int foo = 17; + while(bar) { + MethodCall(foo); + int foo = 42; + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); Assert.AreEqual(2, globalScope.ChildStatements.Count); @@ -149,23 +148,17 @@ public void TestGetNamedChildren_Statement(Language lang) { [TestCase(Language.CSharp)] [TestCase(Language.Java)] public void TestGetNamedChildren_IfStatement(Language lang) { - //int foo = 17; - //if(bar) { - // int foo = 42; - // MethodCall(foo); - //} else { - // MethodCall2(foo); - // int foo = 101; - //} - string xml = @"int foo = 17; -if(bar) { - int foo = 42; - MethodCall(foo); -} else { - MethodCall2(foo); - int foo = 101; -}"; - var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(xml, "test.code"); + string xml = @"int foo = 17; + if(bar) { + int foo = 42; + MethodCall(foo); + } else { + MethodCall2(foo); + int foo = 101; + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); Assert.AreEqual(2, globalScope.ChildStatements.Count); @@ -191,27 +184,20 @@ public void TestGetNamedChildren_IfStatement(Language lang) { Assert.IsEmpty(ifStatement.GetNamedChildren(elseFooUse).ToList()); } - [TestCase(Language.CPlusPlus)] [TestCase(Language.CSharp)] [TestCase(Language.Java)] public void TestGetNamedChildren_TryStatement(Language lang) { - //int foo = 17; - //try { - // int foo = 42; - // MethodCall(foo); - //} finally { - // MethodCall2(foo); - // int foo = 101; - //} - string xml = @"int foo = 17; -try { - int foo = 42; - MethodCall(foo); -} finally { - MethodCall2(foo); - int foo = 101; -}"; - var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(xml, "test.code"); + string xml = @"int foo = 17; + try { + int foo = 42; + MethodCall(foo); + } finally { + MethodCall2(foo); + int foo = 101; + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code"); var globalScope = codeParsers[lang].ParseFileUnit(xmlElement); Assert.AreEqual(2, globalScope.ChildStatements.Count); diff --git a/ABB.SrcML.Data.Test/SerializationTests.cs b/ABB.SrcML.Data.Test/SerializationTests.cs index 923547d..714f4c4 100644 --- a/ABB.SrcML.Data.Test/SerializationTests.cs +++ b/ABB.SrcML.Data.Test/SerializationTests.cs @@ -13,6 +13,7 @@ using NUnit.Framework; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; @@ -22,7 +23,7 @@ namespace ABB.SrcML.Data.Test { [TestFixture(Category="Build")] public class SerializationTests { private const string TestInputPath = @"..\..\TestInputs"; - private const string DefaultInputName = "serializationtest_input.xml"; + private const string DefaultInputName = "serializationtest_input"; private const string DefaultOutputName = "serializationtest_output"; [SetUp] public void TestSetup() { @@ -39,13 +40,16 @@ public void TestSetup() { [TestCase("A.h", false)] public void TestRoundTrip(string sourceFileName, bool compressOutput) { var sourceFilePath = Path.Combine(TestInputPath, sourceFileName); + var destFilePath = Path.Combine(TestInputPath, DefaultInputName); - var srcMLGenerator = new SrcMLGenerator("SrcML"); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFile(sourceFilePath, destFilePath + ".cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary() { }); + Assert.That(File.Exists(destFilePath + ".cpp0.xml")); + + var fileUnit = SrcMLElement.Load(destFilePath + ".cpp0.xml"); var dataGenerator = new DataGenerator(); + var nsd = dataGenerator.Parse(fileUnit.Element(SRC.Unit)) as NamespaceDefinition; - Assert.That(srcMLGenerator.Generate(sourceFilePath, DefaultInputName)); - var fileUnit = SrcMLElement.Load(DefaultInputName); - var nsd = dataGenerator.Parse(fileUnit) as NamespaceDefinition; XmlSerialization.WriteElement(nsd, DefaultOutputName, compressOutput); var nsdFromFile = XmlSerialization.Load(DefaultOutputName, compressOutput) as NamespaceDefinition; DataAssert.StatementsAreEqual(nsd, nsdFromFile); @@ -58,14 +62,16 @@ public void TestRoundTrip(string sourceFileName, bool compressOutput) { [TestCase("A.h", false)] public void TestRoundTripWithDefaultExtension(string sourceFileName, bool useCompression) { var sourceFilePath = Path.Combine(TestInputPath, sourceFileName); + var destFilePath = Path.Combine(TestInputPath, DefaultInputName); - var srcMLGenerator = new SrcMLGenerator("SrcML"); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFile(sourceFilePath, destFilePath+".cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary() { }); + Assert.That(File.Exists(destFilePath + ".cpp0.xml")); + + var fileUnit = SrcMLElement.Load(destFilePath + ".cpp0.xml"); var dataGenerator = new DataGenerator(); + var nsd = dataGenerator.Parse(fileUnit.Element(SRC.Unit)) as NamespaceDefinition; - Assert.That(srcMLGenerator.Generate(sourceFilePath, DefaultInputName)); - var fileUnit = SrcMLElement.Load(DefaultInputName); - var nsd = dataGenerator.Parse(fileUnit) as NamespaceDefinition; - string outputFileName = Path.ChangeExtension(DefaultOutputName, useCompression ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION); XmlSerialization.WriteElement(nsd, outputFileName); var nsdFromFile = XmlSerialization.Load(outputFileName) as NamespaceDefinition; diff --git a/ABB.SrcML.Data.Test/SrcMLLocationTests.cs b/ABB.SrcML.Data.Test/SrcMLLocationTests.cs index 512354a..5069508 100644 --- a/ABB.SrcML.Data.Test/SrcMLLocationTests.cs +++ b/ABB.SrcML.Data.Test/SrcMLLocationTests.cs @@ -1,5 +1,7 @@ using ABB.SrcML.Test.Utilities; using NUnit.Framework; +using System; +using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -17,14 +19,12 @@ public void SetUpFixture() { [Test] public void TestContains_NoSibling() { - ////Foo.cs - //class Foo { - // int Bar(){return 0;} - //} - var xml = @"class Foo { - int Bar(){return 0;} -}"; - var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Class).First(); + var xml = @"class Foo { + int Bar(){return 0;} + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Class).First(); var methodElement = classElement.Descendants(SRC.Function).First(); var classLoc = new SrcMLLocation(classElement, "Foo.cs"); var methodLoc = new SrcMLLocation(methodElement, "Foo.cs"); @@ -33,36 +33,28 @@ public void TestContains_NoSibling() { [Test] public void TestContains_Reflexive() { - ////Foo.cs - //class Foo { - // int Bar(){return 0;} - //} - var xml = @"class Foo { - int Bar(){return 0;} -}"; - var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Class).First(); + var xml = @"class Foo { + int Bar(){return 0;} + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Class).First(); var classLoc = new SrcMLLocation(classElement, "Foo.cs"); Assert.IsTrue(classLoc.Contains(classLoc)); } [Test] public void TestContains_Sibling() { - ////Foo.cs - //class Foo { - // string Bar(){ - // string a = "Hello, world!"; - // return a; - // } - // int Baz(){ return 0; } - //} - var xml = @"class Foo { - string Bar(){ - string a = ""Hello, world!""; - return a; - } - int Baz(){ return 0; } -}"; - var methodElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Foo.cs").Descendants(SRC.Function).First(); + 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() { }, 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"); @@ -71,18 +63,14 @@ public void TestContains_Sibling() { [Test] public void TestContains_TwoLevel() { - ////Example.cs - //namespace Example { - // class Foo { - // int Bar(){return 0;} - // } - //} - var xml = @"namespace Example { - class Foo { - int Bar(){return 0;} - } -}"; - var namespaceElement = fileUnitSetup.GetFileUnitForXmlSnippet(xml, "Example.cs").Element(SRC.Namespace); + 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() { }, 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"); @@ -99,7 +87,7 @@ public void TestGetXElement() { Assert.IsNotNull(unit); var classElement = unit.Descendants(SRC.Class).FirstOrDefault(); Assert.IsNotNull(classElement); - + var parser = new CPlusPlusCodeParser(); var globalScope = parser.ParseFileUnit(unit); var typeDefinition = globalScope.ChildStatements.OfType().FirstOrDefault(); diff --git a/ABB.SrcML.Data.Test/StatementExtensionTests.cs b/ABB.SrcML.Data.Test/StatementExtensionTests.cs index 65ec26b..1668c63 100644 --- a/ABB.SrcML.Data.Test/StatementExtensionTests.cs +++ b/ABB.SrcML.Data.Test/StatementExtensionTests.cs @@ -3,7 +3,7 @@ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http:www.eclipse.org/legal/epl-v10.html * * Contributors: * Vinay Augustine (ABB Group) - initial API, implementation, & documentation @@ -11,7 +11,9 @@ using ABB.SrcML.Test.Utilities; using NUnit.Framework; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; namespace ABB.SrcML.Data.Test { @@ -38,23 +40,18 @@ public void ClassSetup() { [Test] public void TestGetCallsTo_Simple() { - //void foo() { - // printf("Hello"); - //} - // - //int main() { - // foo(); - // return 0; - //} - string xml = @"void foo() { - printf(""Hello""); -} - -int main() { - foo(); - return 0; -}"; - var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xml, "foo.cpp"); + + string xml = @"void foo() { + printf('Hello'); + } + + int main() { + foo(); + return 0; + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp"); var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlElement); var fooMethod = globalScope.GetNamedChildren("foo").First(); @@ -73,24 +70,19 @@ public void TestGetCallsTo_Simple() { [Test] public void TestGetCallsTo_Multiple() { - //void star() { } - // - //void bar() { star(); } - // - //void foo() { - // bar(); - // if(0) bar(); - //} - string xml = @"void star() { } - -void bar() { star(); } -void foo() { - bar(); - if(0) bar(); -}"; + string xml = @"void star() { } + + void bar() { star(); } + + void foo() { + bar(); + if(0) bar(); + }"; - var unit = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xml, "test.cpp"); + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var unit = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp"); var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(unit); @@ -112,21 +104,16 @@ public void TestGetCallsTo_Multiple() { [Test] public void TestGetCallsTo_Masking() { - //void foo() { printf("Global foo"); } - // - //class Bar { - //public: - // void foo() { printf("Bar::foo"); } - // void baz() { foo(); } - //}; - var xml = @"void foo() { printf(""Global foo""); } - -class Bar { -public: - void foo() { printf(""Bar::foo""); } - void baz() { foo(); } -};"; - var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xml, "Bar.cpp"); + + var xml = @"void foo() { printf('Global foo'); } + class Bar { + public: + void foo() { printf('Bar::foo'); } + void baz() { foo(); } + };"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp"); var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlElement); var globalFooMethod = globalScope.GetNamedChildren("foo").First(); @@ -147,23 +134,18 @@ public void TestGetCallsTo_Masking() { [Test] public void TestGetCallsTo_NonRecursive() { - //int Qux() { return 42; } - //int Xyzzy() { return 17; } - // - //void foo() { - // if(Qux()) { - // print(Xyzzy()); - // } - //} - string xml = @"int Qux() { return 42; } -int Xyzzy() { return 17; } - -void foo() { - if(Qux()) { - print(Xyzzy()); - } -}"; - var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(xml, "foo.cpp"); + + string xml = @"int Qux() { return 42; } + int Xyzzy() { return 17; } + + void foo() { + if(Qux()) { + print(Xyzzy()); + } + }"; + LibSrcMLRunner run = new LibSrcMLRunner(); + string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp"); var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlElement); var quxMethod = globalScope.GetNamedChildren("Qux").First(); diff --git a/ABB.SrcML.Data/AbstractCodeParser.cs b/ABB.SrcML.Data/AbstractCodeParser.cs index f9c2cf5..7a3b348 100644 --- a/ABB.SrcML.Data/AbstractCodeParser.cs +++ b/ABB.SrcML.Data/AbstractCodeParser.cs @@ -195,9 +195,11 @@ protected virtual Statement ParseStatement(XElement element, ParserContext conte stmt = ParseTryElement(element, context); } else if(element.Name == SRC.ExpressionStatement) { stmt = ParseExpressionStatementElement(element, context); - } else if(element.Name == SRC.DeclarationStatement) { + } else if(element.Name == SRC.Property) { + stmt = ParseDeclarationStatementElement(element, context); + } else if (element.Name == SRC.DeclarationStatement) { stmt = ParseDeclarationStatementElement(element, context); - } else if(element.Name == SRC.Block) { + } else if (element.Name == SRC.Block) { stmt = ParseBlockElement(element, context); } else if(element.Name == SRC.Extern) { stmt = ParseExternElement(element, context); @@ -205,13 +207,23 @@ protected virtual Statement ParseStatement(XElement element, ParserContext conte stmt = ParseEmptyStatementElement(element, context); } else if(element.Name == SRC.Lock) { stmt = ParseLockElement(element, context); - } else if(element.Name == SRC.Comment) { + } else if(element.Name == POS.Position) { + // do nothing. we are ignoring position (for now; current method of getting line num seems to still work) + } else if (element.Name == SRC.Using) { + // do nothing for now. + } else if (element.Name == SRC.Using_Stmt) { + stmt = ParseUsingBlockElement(element, context); + } else if (element.Name == SRC.Interface) { + stmt = ParseTypeElement(element, context); + } + else if (element.Name == SRC.Comment) { // do nothing. we are ignoring comments - } else if(element.Name == SRC.Package) { + } else if (element.Name == SRC.Package) { //do nothing. This is already handled in JavaCodeParser.ParseUnitElement() } else if(element.Name.Namespace == CPP.NS) { //do nothing. skip any cpp preprocessor macros } else if(NotImplementedStatements.Contains(element.Name)) { + ; //do nothing. These are known and we're skipping them for now. } else { LogUnknown(element, context, "ParseStatement"); @@ -364,7 +376,7 @@ protected virtual IfStatement ParseIfElement(XElement ifElement, ParserContext c ifStmt.AddChildStatement(ParseStatement(thenChild, context)); } } - } else if(ifChild.Name == SRC.Else) { + } else if(ifChild.Name == SRC.ElseIf || ifChild.Name == SRC.Else) { //add the else statements foreach(var elseChild in ifChild.Elements()) { if(elseChild.Name == SRC.Block) { @@ -438,7 +450,10 @@ protected virtual ConditionBlockStatement ParseForElement(XElement forElement, P var forStmt = new ForStatement() {ProgrammingLanguage = ParserLanguage}; forStmt.AddLocation(context.CreateLocation(forElement)); - foreach(var forChild in forElement.Elements()) { + //TODO: throw the correct exception (since Christian doesn't know which one to throw) + var controlElement = forElement.Element(SRC.Control); + if (controlElement == null) { throw new Exception("Malformed foreach"); } + foreach(var forChild in controlElement.Elements()) { if(forChild.Name == SRC.Init) { //fill in initializer var expElement = GetFirstChildExpression(forChild); @@ -457,16 +472,18 @@ protected virtual ConditionBlockStatement ParseForElement(XElement forElement, P if(expElement != null) { forStmt.Incrementer = ParseExpression(expElement, context); } - } else if(forChild.Name == SRC.Block) { - //add children from block - var blockStatements = forChild.Elements().Select(e => ParseStatement(e, context)); - forStmt.AddChildStatements(blockStatements); } else { //add child forStmt.AddChildStatement(ParseStatement(forChild, context)); } } + var blockElement = forElement.Element(SRC.Block); + if (blockElement != null) { + //add children from block + var blockStatements = blockElement.Elements().Select(e => ParseStatement(e, context)); + forStmt.AddChildStatements(blockStatements); + } return forStmt; } @@ -487,7 +504,10 @@ protected virtual ForeachStatement ParseForeachElement(XElement foreachElement, var foreachStmt = new ForeachStatement() {ProgrammingLanguage = ParserLanguage}; foreachStmt.AddLocation(context.CreateLocation(foreachElement)); - foreach(var child in foreachElement.Elements()) { + //TODO: throw the correct exception (since Christian doesn't know which one to throw) + var controlElement = foreachElement.Element(SRC.Control); + if (controlElement == null) { throw new Exception("Malformed foreach"); } + foreach(var child in controlElement.Elements()) { if(child.Name == SRC.Init) { //fill in condition/initializer var expElement = GetFirstChildExpression(child); @@ -619,6 +639,14 @@ protected virtual CaseStatement ParseCaseElement(XElement caseElement, ParserCon return caseStmt; } + /// + /// + /// + /// + /// + /// + protected abstract UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context); + /// /// Creates a object for . /// @@ -879,22 +907,7 @@ protected virtual Statement ParseExpressionStatementElement(XElement stmtElement /// The context to use. /// A corresponding to . /// The return type is so that subclasses can return another type, as necessary. - protected virtual Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { - if(stmtElement == null) - throw new ArgumentNullException("stmtElement"); - if(stmtElement.Name != SRC.DeclarationStatement) - throw new ArgumentException("Must be a SRC.DeclarationStatement element", "stmtElement"); - if(context == null) - throw new ArgumentNullException("context"); - - var stmt = new DeclarationStatement() { - ProgrammingLanguage = ParserLanguage, - Content = ParseExpression(GetChildExpressions(stmtElement), context) - }; - stmt.AddLocation(context.CreateLocation(stmtElement)); - - return stmt; - } + protected abstract Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context); /// @@ -925,12 +938,13 @@ protected virtual TypeDefinition ParseTypeElement(XElement typeElement, ParserCo if(context == null) throw new ArgumentNullException("context"); - var typeDefinition = new TypeDefinition() { - Accessibility = GetAccessModifierForType(typeElement), - Kind = XNameMaps.GetKindForXElement(typeElement), - Name = GetNameForType(typeElement), - ProgrammingLanguage = ParserLanguage - }; + var typeDefinition = new TypeDefinition(); + + typeDefinition.Accessibility = GetAccessModifierForType(typeElement); + typeDefinition.Kind = XNameMaps.GetKindForXElement(typeElement); + typeDefinition.Name = GetNameForType(typeElement); + typeDefinition.ProgrammingLanguage = ParserLanguage; + typeDefinition.AddLocation(context.CreateLocation(typeElement, ContainerIsReference(typeElement))); foreach(var parentTypeElement in GetParentTypeUseElements(typeElement)) { @@ -1022,7 +1036,7 @@ protected virtual ExternStatement ParseExternElement(XElement externElement, Par es.AddLocation(context.CreateLocation(externElement)); foreach(var exChild in externElement.Elements()) { - if(exChild.Name == LIT.Literal) { + if(exChild.Name == SRC.Literal) { es.LinkageType = exChild.Value; } else if(exChild.Name == SRC.Block) { //add children from block @@ -1072,17 +1086,23 @@ protected virtual LockStatement ParseLockElement(XElement lockElement, ParserCon var lockStmt = new LockStatement() {ProgrammingLanguage = ParserLanguage}; lockStmt.AddLocation(context.CreateLocation(lockElement)); - foreach(var child in lockElement.Elements()) { + //TODO: throw the correct exception (since Christian doesn't know which one to throw) + var initElement = lockElement.Element(SRC.Init); + if (initElement == null) { throw new Exception("Invalid lock element format"); } + foreach(var child in initElement.Elements()) { if(child.Name == SRC.Expression) { lockStmt.LockExpression = ParseExpression(child, context); - } else if(child.Name == SRC.Block) { + } + } + + foreach (var child in lockElement.Elements()) { + if(child.Name == SRC.Block) { var blockStatements = child.Elements().Select(e => ParseStatement(e, context)); lockStmt.AddChildStatements(blockStatements); } else { lockStmt.AddChildStatement(ParseStatement(child, context)); } } - return lockStmt; } @@ -1122,15 +1142,17 @@ protected virtual Expression ParseExpression(XElement element, ParserContext con exp = ParseNameUseElement(element, context); } else if(element.Name == SRC.Type) { exp = ParseTypeUseElement(element, context); - } else if(element.Name == OP.Operator) { + } else if(element.Name == SRC.Operator) { exp = ParseOperatorElement(element, context); } else if(element.Name == SRC.Call) { exp = ParseCallElement(element, context); - } else if(element.Name == LIT.Literal) { + } else if(element.Name == SRC.Literal) { exp = ParseLiteralElement(element, context); } else if(element.Name == SRC.Comment) { //skip - } else if(element.Name == SRC.Class && ParserLanguage == Language.Java) { + } else if (element.Name == POS.Position) { + //skip + } else if (element.Name == SRC.Class && ParserLanguage == Language.Java) { //anonymous class, skip //TODO: add parsing for anonymous classes in Java } else if(element.Name.Namespace == CPP.NS) { @@ -1256,16 +1278,16 @@ protected virtual Expression ParseExpressionElement(XElement expElement, ParserC /// /// Creates a variable declaration object from the given declaration element /// - /// The SRC.Declaration element to parse. + /// The SRC.Declaration element to parse. /// The parser context. /// A VariableDeclaration object corresponding to the given element. protected virtual VariableDeclaration ParseDeclarationElement(XElement declElement, ParserContext context) { //TODO: can/should this handle function_decls as well as decls? ParseParameterElement may pass in a function_decl - + //NOTE: When the declaration is using f = bla this won't work because there is no decl on the inside. Fix. if(declElement == null) - throw new ArgumentNullException("declElement"); + throw new ArgumentNullException("propertyElement"); if(!(declElement.Name == SRC.Declaration || declElement.Name == SRC.FunctionDeclaration)) - throw new ArgumentException("Must be a SRC.Declaration or SRC.FunctionDeclaration element", "declElement"); + throw new ArgumentException("Must be a SRC.Declaration or SRC.FunctionDeclaration element", "propertyElement"); if(context == null) throw new ArgumentNullException("context"); @@ -1282,9 +1304,8 @@ protected virtual VariableDeclaration ParseDeclarationElement(XElement declEleme var typeElement = declElement.Element(SRC.Type); if(typeElement != null && typeElement.Attribute("ref") == null) { varDecl.VariableType = ParseTypeUseElement(typeElement, context); - varDecl.Accessibility = GetAccessModifierFromTypeUseElement(typeElement); + varDecl.Accessibility = GetAccessModifier(declElement); } - var initElement = declElement.Element(SRC.Init); if(initElement != null) { var expElement = GetFirstChildExpression(initElement); @@ -1336,8 +1357,9 @@ protected virtual Expression ParseNameUseElement(XElement nameElement, ParserCon return ParseVariableUse(nameElement, context); } - if(nameElement.HasElements) { - return ParseExpression(nameElement.Elements(), context); + var eleList = nameElement.Elements();//need to always generate this now? Is there a better way? + if (eleList.Count() > 1) { //position is always in name, so check to see if there's something more here. + return ParseExpression(eleList, context); } //no children @@ -1353,14 +1375,14 @@ protected virtual Expression ParseNameUseElement(XElement nameElement, ParserCon /// /// Creates an OperatorUse object from the given operator element. /// - /// The OP.Operator element to parse. + /// The SRC.Operator element to parse. /// The parser context to use. /// An OperatorUse corresponding to . protected virtual OperatorUse ParseOperatorElement(XElement operatorElement, ParserContext context) { if(operatorElement == null) throw new ArgumentNullException("operatorElement"); - if(operatorElement.Name != OP.Operator) - throw new ArgumentException("should be an OP.Operator", "operatorElement"); + if(operatorElement.Name != SRC.Operator) + throw new ArgumentException("should be an SRC.Operator", "operatorElement"); if(context == null) throw new ArgumentNullException("context"); @@ -1421,8 +1443,8 @@ protected virtual TypeUse ParseTypeUseElement(XElement typeUseElement, ParserCon if(argumentListElement != null) { typeArguments = from argument in argumentListElement.Elements(SRC.Argument) - where argument.Elements(SRC.Name).Any() - select ParseTypeUseElement(argument.Element(SRC.Name), context); + where argument.Descendants(SRC.Name).Any() + select ParseTypeUseElement(argument.Descendants(SRC.Name).First(), context); // if this is a generic type use and there is a prefix (A::B::C) then the last name // element will actually be the first child of lastNameElement if(prefix != null) { @@ -1496,8 +1518,9 @@ protected virtual Expression ParseCallElement(XElement callElement, ParserContex //parse the name element for the call var nameElement = callElement.Element(SRC.Name); + var position = nameElement.Element(POS.Position); if(nameElement != null) { - if(!nameElement.HasElements) { + if(position != null) { methodNameElement = nameElement; } else { methodNameElement = nameElement.Elements(SRC.Name).Last(); @@ -1521,7 +1544,7 @@ protected virtual Expression ParseCallElement(XElement callElement, ParserContex } //check if this is a call to a constructor - if(callElement.ElementsBeforeSelf().Any(e => e.Name == OP.Operator && e.Value == "new")) { + if(callElement.ElementsBeforeSelf().Any(e => e.Name == SRC.Operator && e.Value == "new")) { mc.IsConstructor = true; } var parentElement = callElement.Parent; @@ -1566,7 +1589,7 @@ protected virtual Expression ParseCallElement(XElement callElement, ParserContex protected virtual LiteralUse ParseLiteralElement(XElement literalElement, ParserContext context) { if(literalElement == null) throw new ArgumentNullException("literalElement"); - if(literalElement.Name != LIT.Literal) + if(literalElement.Name != SRC.Literal) throw new ArgumentException("Must be a LIT.Literal element", "literalElement"); if(context == null) throw new ArgumentNullException("context"); @@ -1645,12 +1668,7 @@ protected virtual AccessModifier GetAccessModifierForMethod(XElement methodEleme throw new ArgumentNullException("methodElement"); if(!MethodElementNames.Contains(methodElement.Name)) throw new ArgumentException(string.Format("Not a valid methodElement: {0}", methodElement.Name), "methodElement"); - - var specifierContainer = methodElement.Element(SRC.Type); - if(null == specifierContainer) { - specifierContainer = methodElement; - } - return GetAccessModifier(specifierContainer); + return GetAccessModifier(methodElement); } /// @@ -1809,6 +1827,11 @@ protected virtual string GetNameForMethod(XElement methodElement) { if(null == nameElement) return string.Empty; + /* + var templateArgs = nameElement.Element(SRC.ArgumentList); + if (templateArgs != null) { + return nameElement.Value; + }*/ return NameHelper.GetLastName(nameElement); } @@ -1849,7 +1872,7 @@ protected virtual IEnumerable GetChildExpressions(XElement element) { if(element == null) throw new ArgumentNullException("element"); - return element.Elements().Where(e => e.Name == SRC.Expression || e.Name == SRC.Declaration || e.Name == SRC.FunctionDeclaration); + return element.Elements().Where(e => e.Name == SRC.Expression || e.Name == SRC.Declaration || e.Name == SRC.FunctionDeclaration || e.Name == SRC.Type); } /// diff --git a/ABB.SrcML.Data/CPlusPlusCodeParser.cs b/ABB.SrcML.Data/CPlusPlusCodeParser.cs index b63d069..b0c239a 100644 --- a/ABB.SrcML.Data/CPlusPlusCodeParser.cs +++ b/ABB.SrcML.Data/CPlusPlusCodeParser.cs @@ -27,7 +27,7 @@ public class CPlusPlusCodeParser : AbstractCodeParser { public CPlusPlusCodeParser() { this.SpecifierContainerNames = new HashSet(new XName[] { SRC.Private, SRC.Protected, SRC.Public }); this.TypeElementNames = new HashSet(new XName[] { - SRC.Class, SRC.Enum, SRC.Struct, SRC.Union, + SRC.Class, SRC.Enum, SRC.Struct, SRC.Union, SRC.Interface, SRC.ClassDeclaration, SRC.StructDeclaration, SRC.UnionDeclaration }); this.VariableDeclarationElementNames = new HashSet(new XName[] { SRC.Declaration, SRC.DeclarationStatement, SRC.FunctionDeclaration }); @@ -222,6 +222,7 @@ protected override NamespaceDefinition ParseNamespaceElement(XElement namespaceE return nd; } + protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { return new UsingBlockStatement(); } /// /// Parses an element corresponding to a type definition and creates a TypeDefinition object /// @@ -265,7 +266,30 @@ protected override TypeDefinition ParseTypeElement(XElement typeElement, ParserC return typeDefinition; } + /// + /// Creates a object for . + /// The expression contained within will be parsed and placed in + /// Statement.Content. + /// + /// The SRC.DeclarationStatement element to parse. + /// The context to use. + /// A corresponding to . + /// The return type is so that subclasses can return another type, as necessary. + protected override Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { + if (stmtElement == null) + throw new ArgumentNullException("stmtElement"); + if (stmtElement.Name != SRC.DeclarationStatement && stmtElement.Name != SRC.Property) + throw new ArgumentException("Must be a SRC.DeclarationStatement or SRC.Property element", "stmtElement"); + if (context == null) + throw new ArgumentNullException("context"); + var stmt = new DeclarationStatement() { + ProgrammingLanguage = ParserLanguage, + Content = ParseExpression(GetChildExpressions(stmtElement), context) + }; + stmt.AddLocation(context.CreateLocation(stmtElement)); + return stmt; + } /// /// Parses the given and creates an ImportStatement or AliasStatement from it. /// @@ -281,15 +305,13 @@ protected override Statement ParseAliasElement(XElement aliasElement, ParserCont throw new ArgumentNullException("context"); Statement stmt = null; - bool containsNamespaceKeyword = (from textNode in GetTextNodes(aliasElement) - where textNode.Value.Contains("namespace") - select textNode).Any(); - if(containsNamespaceKeyword) { + var namespaceElement = aliasElement.Element(SRC.Namespace); + if(namespaceElement != null) { //import statement var import = new ImportStatement() {ProgrammingLanguage = ParserLanguage}; import.AddLocation(context.CreateLocation(aliasElement)); - var nameElement = aliasElement.Element(SRC.Name); + var nameElement = namespaceElement.Element(SRC.Name); if(nameElement != null) { import.ImportedNamespace = ParseNameUseElement(nameElement, context); } @@ -300,6 +322,7 @@ where textNode.Value.Contains("namespace") var alias = new AliasStatement() {ProgrammingLanguage = ParserLanguage}; alias.AddLocation(context.CreateLocation(aliasElement)); + //TODO: Make sure that using descendant is correct for nameElement var nameElement = aliasElement.Element(SRC.Name); var initElement = aliasElement.Element(SRC.Init); if(initElement != null) { diff --git a/ABB.SrcML.Data/CSharpCodeParser.cs b/ABB.SrcML.Data/CSharpCodeParser.cs index ff3e2f3..172f7ed 100644 --- a/ABB.SrcML.Data/CSharpCodeParser.cs +++ b/ABB.SrcML.Data/CSharpCodeParser.cs @@ -26,7 +26,7 @@ public class CSharpCodeParser : AbstractCodeParser { /// public CSharpCodeParser() : base() { - this.TypeElementNames = new HashSet { SRC.Class, SRC.Enum, SRC.Struct }; //SRC.Interface? + this.TypeElementNames = new HashSet { SRC.Class, SRC.Enum, SRC.Struct, SRC.Interface }; this.AliasElementName = SRC.Using; //TODO: what else needs to be set here? } @@ -245,10 +245,10 @@ protected override Statement ParseAliasElement(XElement aliasElement, ParserCont /// The SRC.Using element to parse. /// The parser context to use. /// A UsingBlockStatement created from the given usingElement. - protected virtual UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { + protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { if(usingElement == null) throw new ArgumentNullException("usingElement"); - if(usingElement.Name != SRC.Using) + if(usingElement.Name != SRC.Using_Stmt) throw new ArgumentException("Must be a SRC.Using element", "usingElement"); if(context == null) throw new ArgumentNullException("context"); @@ -310,43 +310,43 @@ protected override TypeDefinition ParseTypeElement(XElement typeElement, ParserC protected override Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { if(stmtElement == null) throw new ArgumentNullException("stmtElement"); - if(stmtElement.Name != SRC.DeclarationStatement) + if (stmtElement.Name != SRC.DeclarationStatement && stmtElement.Name != SRC.Property) throw new ArgumentException("Must be a SRC.DeclarationStatement element", "stmtElement"); if(context == null) throw new ArgumentNullException("context"); //first check if this is a property and parse accordingly - var declElement = stmtElement.Element(SRC.Declaration); - if(declElement != null) { - var blockElement = declElement.Element(SRC.Block); - if(blockElement != null) { - //this is a property - return ParsePropertyDeclarationElement(declElement, context); - } + if (stmtElement.Name == SRC.Property) { + return ParsePropertyDeclarationElement(stmtElement, context); + } else { + var stmt = new DeclarationStatement() { + ProgrammingLanguage = ParserLanguage, + Content = ParseExpression(GetChildExpressions(stmtElement), context) + }; + stmt.AddLocation(context.CreateLocation(stmtElement)); + return stmt; } - //otherwise, parse as base: - return base.ParseDeclarationStatementElement(stmtElement, context); } /// - /// Creates a object for . + /// Creates a object for . /// - /// The SRC.Declaration element to parse. This must be a declaration of a property. + /// The SRC.Declaration element to parse. This must be a declaration of a property. /// The context to use. - /// A corresponding to . - protected virtual PropertyDefinition ParsePropertyDeclarationElement(XElement declElement, ParserContext context) { - if(declElement == null) - throw new ArgumentNullException("declElement"); - if(declElement.Name != SRC.Declaration) - throw new ArgumentException("Must be a SRC.Declaration element", "declElement"); + /// A corresponding to . + protected virtual PropertyDefinition ParsePropertyDeclarationElement(XElement propertyElement, ParserContext context) { + if(propertyElement == null) + throw new ArgumentNullException("propertyElement"); + if(propertyElement.Name != SRC.Property) + throw new ArgumentException("Must be a SRC.Property element", "propertyElement"); if(context == null) throw new ArgumentNullException("context"); var propertyDef = new PropertyDefinition {ProgrammingLanguage = ParserLanguage}; - propertyDef.AddLocation(context.CreateLocation(declElement)); + propertyDef.AddLocation(context.CreateLocation(propertyElement)); - foreach(var child in declElement.Elements()) { + foreach(var child in propertyElement.Elements()) { if(child.Name == SRC.Type) { propertyDef.Accessibility = GetAccessModifierFromTypeUseElement(child); propertyDef.ReturnType = ParseTypeUseElement(child, context); diff --git a/ABB.SrcML.Data/InterfaceDefinition.cs b/ABB.SrcML.Data/InterfaceDefinition.cs new file mode 100644 index 0000000..1f786d3 --- /dev/null +++ b/ABB.SrcML.Data/InterfaceDefinition.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace ABB.SrcML.Data { + [DebuggerTypeProxy(typeof(StatementDebugView))] + public class InterfaceDefinition : NamedScope { + /// The XML name for InterfaceDefinition. + public new const string XmlName = "Interface"; + } +} diff --git a/ABB.SrcML.Data/JavaCodeParser.cs b/ABB.SrcML.Data/JavaCodeParser.cs index a43f3a3..1102d84 100644 --- a/ABB.SrcML.Data/JavaCodeParser.cs +++ b/ABB.SrcML.Data/JavaCodeParser.cs @@ -27,7 +27,7 @@ public class JavaCodeParser : AbstractCodeParser { /// Creates a new java code parser object /// public JavaCodeParser() { - this.TypeElementNames = new HashSet(new XName[] { SRC.Class, SRC.Enum }); + this.TypeElementNames = new HashSet(new XName[] { SRC.Class, SRC.Enum, SRC.Interface }); this.NamespaceElementNames = new HashSet(); this.AliasElementName = SRC.Import; } @@ -40,6 +40,7 @@ public override Language ParserLanguage { } + /// /// Gets the parent type from a java type /// @@ -95,6 +96,7 @@ protected override string GetTypeForStringLiteral(string literalValue) { throw new NotImplementedException(); } + protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { return new UsingBlockStatement(); } /// /// Creates a NamespaceDefinition object from the given Java package element. /// This will create a NamespaceDefinition for each component of the name, e.g. com.java.foo.bar, and link them as children of each other. @@ -192,8 +194,8 @@ protected override ConditionBlockStatement ParseForElement(XElement forElement, throw new ArgumentException("Must be a SRC.For element", "forElement"); if(context == null) throw new ArgumentNullException("context"); - - if(forElement.Element(SRC.Condition) != null) { + var controlElement = forElement.Element(SRC.Control); + if(controlElement.Element(SRC.Condition) != null) { //this is a standard for-loop, use the base processing return base.ParseForElement(forElement, context); } @@ -222,7 +224,30 @@ protected override ConditionBlockStatement ParseForElement(XElement forElement, return foreachStmt; } + /// + /// Creates a object for . + /// The expression contained within will be parsed and placed in + /// Statement.Content. + /// + /// The SRC.DeclarationStatement element to parse. + /// The context to use. + /// A corresponding to . + /// The return type is so that subclasses can return another type, as necessary. + protected override Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { + if (stmtElement == null) + throw new ArgumentNullException("stmtElement"); + if (stmtElement.Name != SRC.DeclarationStatement && stmtElement.Name != SRC.Property) + throw new ArgumentException("Must be a SRC.DeclarationStatement or SRC.Property element", "stmtElement"); + if (context == null) + throw new ArgumentNullException("context"); + var stmt = new DeclarationStatement() { + ProgrammingLanguage = ParserLanguage, + Content = ParseExpression(GetChildExpressions(stmtElement), context) + }; + stmt.AddLocation(context.CreateLocation(stmtElement)); + return stmt; + } /// /// Parses the given and creates an ImportStatement or AliasStatement from it. /// @@ -237,7 +262,8 @@ protected override Statement ParseAliasElement(XElement aliasElement, ParserCont if(context == null) throw new ArgumentNullException("context"); - var isNamespaceImport = GetTextNodes(aliasElement).Any(n => n.Value.Contains("*")); + var isNamespaceImport = aliasElement.Descendants(SRC.Name).Any(n => n.Value.Contains("*")); + //Elements("name").Any(n => n.Value.Contains("*")); //).Any(n => n.Value.Contains("*")); Statement stmt = null; if(isNamespaceImport) { @@ -246,6 +272,9 @@ protected override Statement ParseAliasElement(XElement aliasElement, ParserCont import.AddLocation(context.CreateLocation(aliasElement)); var nameElement = aliasElement.Element(SRC.Name); if(nameElement != null) { + //we have an import that ends with .*. We remove the . and *. + nameElement.LastNode.Remove();//remove * + nameElement.LastNode.Remove();//remove . import.ImportedNamespace = ParseNameUseElement(nameElement, context); //TODO: fix to handle the trailing operator tag } diff --git a/ABB.SrcML.Data/LiteralUse.cs b/ABB.SrcML.Data/LiteralUse.cs index 20a98df..70762dc 100644 --- a/ABB.SrcML.Data/LiteralUse.cs +++ b/ABB.SrcML.Data/LiteralUse.cs @@ -45,7 +45,7 @@ public class LiteralUse : Expression { public static LiteralKind GetLiteralKind(XElement literalElement) { if(literalElement == null) throw new ArgumentNullException("literalElement"); - if(literalElement.Name != LIT.Literal) + if(literalElement.Name != SRC.Literal) throw new ArgumentException("should be of type LIT.Literal", "literalElement"); var typeAttribute = literalElement.Attribute("type"); diff --git a/ABB.SrcML.Data/NameUse.cs b/ABB.SrcML.Data/NameUse.cs index aca1ba6..19ad271 100644 --- a/ABB.SrcML.Data/NameUse.cs +++ b/ABB.SrcML.Data/NameUse.cs @@ -319,7 +319,7 @@ protected IEnumerable GetCallingScope() { scopes.Add((NamedScope)match); } } - return scopes; + if (scopes.Count == 0) return null; else return scopes; } diff --git a/ABB.SrcML.Data/XNameMaps.cs b/ABB.SrcML.Data/XNameMaps.cs index a19f610..1fde8a1 100644 --- a/ABB.SrcML.Data/XNameMaps.cs +++ b/ABB.SrcML.Data/XNameMaps.cs @@ -36,6 +36,7 @@ public static TypeKind GetKindForXElement(XElement typeElement) { var map = new Dictionary() { { SRC.Struct, TypeKind.Struct }, { SRC.StructDeclaration, TypeKind.Struct }, + { SRC.Interface, TypeKind.Interface}, { SRC.Class, TypeKind.Class }, { SRC.ClassDeclaration, TypeKind.Class }, { SRC.Union, TypeKind.Union }, diff --git a/ABB.SrcML.Test/ABB.SrcML.Test.csproj b/ABB.SrcML.Test/ABB.SrcML.Test.csproj index 7eadaf7..deb4ae9 100644 --- a/ABB.SrcML.Test/ABB.SrcML.Test.csproj +++ b/ABB.SrcML.Test/ABB.SrcML.Test.csproj @@ -14,6 +14,7 @@ v4.0 512 ..\ + true true @@ -96,6 +97,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + TestPassed + + \ No newline at end of file diff --git a/TestInputs/function_def.xml b/TestInputs/function_def.xml index 246fbd9..ced6495 100644 --- a/TestInputs/function_def.xml +++ b/TestInputs/function_def.xml @@ -1,5 +1,5 @@ -#include <iostream> +#include <iostream> char* MyFunction(int foo) { if(foo > 0) { @@ -10,7 +10,7 @@ } int main(int argc, char* argv[]) { - std::cout<<MyFunction(42); + int foo = 17; return 0; } diff --git a/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs b/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs index 72303fe..14c4e02 100644 --- a/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs +++ b/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs @@ -32,7 +32,7 @@ public class SyntacticCategoryTest { public IEnumerable QueryForNew(XElement element) { - var uses = from use in element.Descendants(OP.Operator) + var uses = from use in element.Descendants(SRC.Operator) where use.Value == "new" select use; return uses;