-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#41 Add a wrapper for the case when the select matches attributes.
- Loading branch information
AlexJitianu
committed
Jun 11, 2020
1 parent
3396c12
commit cfe20a5
Showing
5 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.oxygenxml.xspec.jfx; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import com.oxygenxml.xspec.XSpecUtil; | ||
|
||
import ro.sync.util.URLUtil; | ||
|
||
/** | ||
* Asserts the XSpec transformation meta data and the special report. | ||
* | ||
* @author alex_jitianu | ||
*/ | ||
public class XSpecMeta2Test extends XSpecViewTestBase { | ||
|
||
/** | ||
* An assert with match on attributes. | ||
* | ||
* https://github.com/xspec/oXygen-XML-editor-xspec-support/issues/41 | ||
* | ||
* @throws Exception If it fails. | ||
*/ | ||
public void testRunXSpec() throws Exception { | ||
URL xspecURL = getClass().getClassLoader().getResource("#41/to-test.xspec"); | ||
URL xslURL = getClass().getClassLoader().getResource("#41/to-test.xsl"); | ||
File xspecFile = URLUtil.getCanonicalFileFromFileUrl(xspecURL); | ||
File outputFile = new File(xspecFile.getParentFile(), "to-test.html"); | ||
|
||
executeANT(xspecFile, outputFile); | ||
|
||
String firstID = XSpecUtil.generateId("template name code-to-code"); | ||
|
||
File xmlFormatOutput = new File(xspecFile.getParentFile(), "xspec/to-test-result.xml"); | ||
|
||
assertEquals("<x:result xmlns:test=\"http://www.jenitennison.com/xslt/unit-test\"\n" + | ||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + | ||
" xmlns:x=\"http://www.jenitennison.com/xslt/xspec\"\n" + | ||
" xmlns:f=\"uri:some\"\n" + | ||
" select=\"/*/@*\">\n" + | ||
" <pseudo-attribute xmlns=\"http://www.jenitennison.com/xslt/xspec\" code=\"F\"/>\n" + | ||
" <pseudo-attribute xmlns=\"http://www.jenitennison.com/xslt/xspec\" codeSystem=\"null\"/>\n" + | ||
" <pseudo-attribute xmlns=\"http://www.jenitennison.com/xslt/xspec\" displayName=\"Vrouw\"/>\n" + | ||
" </x:result>", executeXPath(xmlFormatOutput, "//*:result")); | ||
|
||
assertEquals("<x:expect xmlns:test=\"http://www.jenitennison.com/xslt/unit-test\"\n" + | ||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + | ||
" xmlns:x=\"http://www.jenitennison.com/xslt/xspec\"\n" + | ||
" xmlns:f=\"uri:some\"\n" + | ||
" select=\"/*/@*\">\n" + | ||
" <pseudo-attribute xmlns=\"http://www.jenitennison.com/xslt/xspec\" code=\"false\"/>\n" + | ||
" <pseudo-attribute xmlns=\"http://www.jenitennison.com/xslt/xspec\"\n" + | ||
" codeSystem=\"2.16.840.1.113883.5.1\"/>\n" + | ||
" <pseudo-attribute xmlns=\"http://www.jenitennison.com/xslt/xspec\" displayName=\"Vrouw\"/>\n" + | ||
" </x:expect>", executeXPath(xmlFormatOutput, "//*:expect")); | ||
|
||
|
||
|
||
assertTrue(outputFile.exists()); | ||
|
||
File css = new File("frameworks/xspec/oxygen-results-view/test-report.css"); | ||
File js = new File("frameworks/xspec/oxygen-results-view/test-report.js"); | ||
|
||
|
||
String htmlContent = simplify(read(outputFile.toURI().toURL()).toString()); | ||
Pattern compile = Pattern.compile("<pre class=\"embeded\\.diff\\.data\" style=\"display:none;\">.*</pre>"); | ||
Matcher matcher = compile.matcher(htmlContent); | ||
matcher.find(); | ||
String actual = matcher.group(); | ||
|
||
assertEquals("<pre class=\"embeded.diff.data\" style=\"display:none;\"><div class=\"embeded.diff.result\" style=\"white-space:pre;\"><wrapper code=\"F\" codeSystem=\"null\" displayName=\"Vrouw\"/></div><div class=\"embeded.diff.expected\" style=\"white-space:pre;\"><wrapper code=\"false\" codeSystem=\"2.16.840.1.113883.5.1\" displayName=\"Vrouw\"/></div></pre>", actual); | ||
} | ||
|
||
private String simplify(String string) { | ||
return string.replaceAll("<span xmlns=\"http://www.w3.org/1999/xhtml\"", "<span"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
exclude-result-prefixes="xs" | ||
version="2.0"> | ||
<xsl:template name="code-to-code" as="attribute()+"> | ||
<xsl:param name="value" as="attribute(value)" select="."/> | ||
<xsl:param name="codeMap" as="element()*"/> | ||
|
||
<xsl:variable name="out" as="element()"> | ||
<xsl:choose> | ||
<xsl:when test="$codeMap[@inValue = $value]"> | ||
<xsl:copy-of select="$codeMap[@inValue = $value]"/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:copy-of select="."/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:variable> | ||
|
||
<xsl:attribute name="code" select="$out/@code"/> | ||
<xsl:attribute name="codeSystem" select="$out/@codeSystem"/> | ||
<xsl:if test="$out/@displayName"> | ||
<xsl:attribute name="displayName" select="$out/@displayName"/> | ||
</xsl:if> | ||
</xsl:template> | ||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" | ||
xmlns:f="uri:some" | ||
stylesheet="to-test.xsl"> | ||
|
||
<x:scenario label="template name code-to-code"> | ||
<x:call template="code-to-code"> | ||
<x:param name="value" select="f:gender/@value"> | ||
<f:gender value="female"/> | ||
</x:param> | ||
<x:param name="codeMap"> | ||
<map code="F" codeSystem="null" inValue="female" displayName="Vrouw"/> | ||
</x:param> | ||
</x:call> | ||
<x:expect label="attributes" select="geslacht/@*"> | ||
<geslacht code="false" codeSystem="2.16.840.1.113883.5.1" displayName="Vrouw"/> | ||
</x:expect> | ||
</x:scenario> | ||
|
||
</x:description> |