Skip to content

Commit

Permalink
Fixing node to be inserted is from a different document context big.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayprabhu committed Apr 18, 2011
1 parent 0bf40c4 commit 42acbe8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ build
[Db]ebug*/
obj/
[Rr]elease*/
_ReSharper*/
_ReSharper*/
*.vs10x
4 changes: 3 additions & 1 deletion src/MacroDefInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ private void ReplaceElementPlaceHolderWithInvocationContents(XmlElement invocati
Log(Level.Verbose, "Replacing element " + elementPlaceHolder.OuterXml + " in " + parentElement.OuterXml);
foreach (XmlNode definitionStep in invocationElementDefinition.ChildNodes)
{
parentElement.InsertBefore(definitionStep.CloneNode(true), elementPlaceHolder);
//needs to be imported because the context where it came from could be different (different xml file)
XmlNode actualNodeToBeInserted = parentElement.OwnerDocument.ImportNode(definitionStep, true);
parentElement.InsertBefore(actualNodeToBeInserted, elementPlaceHolder);
}
parentElement.RemoveChild(elementPlaceHolder);
}
Expand Down
14 changes: 14 additions & 0 deletions test/macrodefinitions.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<project name="duplicate-test" xmlns="http://nant.sf.net/schemas/nant.xsd">
<loadtasks assembly="../build/Macrodef.dll" verbose="true" />

<macrodef name="elements-context-test">
<elements>
<element name="test-element"/>
</elements>
<sequential>
<test-element/>
</sequential>
</macrodef>
</project>

14 changes: 13 additions & 1 deletion test/tests.build
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@
</if>
</target>

<include buildfile="macrodefinitions.build" />

<target name="test-element-from-different-context">
<elements-context-test>
<test-element>
<property name="test-element_executed" value="true"/>
<echo message ="This is a node from a different context"/>
</test-element>
</elements-context-test>
<fail if="${ test-element_executed != 'true'}" message="test-element_executed: expected true but was ${test-element_executed}"/>
</target>

<target name="test" depends="
test-macro-defined,
Expand All @@ -123,7 +134,8 @@
test-property-subst,
test-elements,
test-duplicate-macrodef,
test-duplicate-macrodef-redefinition
test-duplicate-macrodef-redefinition,
test-element-from-different-context
"/>

</project>
Expand Down

0 comments on commit 42acbe8

Please sign in to comment.