public void TestRemoveClass_Global() { ////Foo.cs //class Foo { // private int bar; // public Foo() { bar = 42; } // public int GetBar() { return bar; } //} string fooXml = @"<class>class <name>Foo</name> <block>{ <decl_stmt><decl><type><specifier>private</specifier> <name>int</name></type> <name>bar</name></decl>;</decl_stmt> <constructor><specifier>public</specifier> <name>Foo</name><parameter_list>()</parameter_list> <block>{ <expr_stmt><expr><name>bar</name> <op:operator>=</op:operator> <lit:literal type=""number"">42</lit:literal></expr>;</expr_stmt> }</block></constructor> <function><type><specifier>public</specifier> <name>int</name></type> <name>GetBar</name><parameter_list>()</parameter_list> <block>{ <return>return <expr><name>bar</name></expr>;</return> }</block></function> }</block></class>"; var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(fooXml, "Foo.cs"); var beforeScope = CodeParser.ParseFileUnit(fooFileUnit); ////Baz.cs //class Baz { // public static int DoWork(string arg) { return 0; } //} string bazXml = @"<class>class <name>Baz</name> <block>{ <function><type><specifier>public</specifier> <specifier>static</specifier> <name>int</name></type> <name>DoWork</name><parameter_list>(<param><decl><type><name>string</name></type> <name>arg</name></decl></param>)</parameter_list> <block>{ <return>return <expr><lit:literal type=""number"">0</lit:literal></expr>;</return> }</block></function> }</block></class>"; var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(bazXml, "Baz.cs"); var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit)); Assert.AreEqual(0, afterScope.ChildScopes.OfType <INamespaceDefinition>().Count()); Assert.AreEqual(2, afterScope.ChildScopes.OfType <ITypeDefinition>().Count()); afterScope.RemoveFile("Baz.cs"); Assert.IsTrue(TestHelper.ScopesAreEqual(beforeScope, afterScope)); }
public void TestRemoveClass_Global() { 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 <UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs"); var beforeScope = CodeParser.ParseFileUnit(fooFileUnit); 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 <UInt32>() { 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 <NamespaceDefinition>().Count()); Assert.AreEqual(2, afterScope.ChildStatements.OfType <TypeDefinition>().Count()); afterScope.RemoveFile("Baz.cs"); DataAssert.StatementsAreEqual(beforeScope, afterScope); }