diff options
Diffstat (limited to 'libxslt/tests/exslt/strings')
22 files changed, 442 insertions, 0 deletions
diff --git a/libxslt/tests/exslt/strings/Makefile.am b/libxslt/tests/exslt/strings/Makefile.am new file mode 100644 index 0000000..41a6ce6 --- /dev/null +++ b/libxslt/tests/exslt/strings/Makefile.am @@ -0,0 +1,52 @@ +## Process this file with automake to produce Makefile.in + +$(top_builddir)/xsltproc/xsltproc: + @(cd ../../../xsltproc ; $(MAKE) xsltproc) + +EXTRA_DIST = \ + align.1.xml align.1.xsl align.1.out \ + padding.1.xml padding.1.xsl padding.1.out \ + replace.1.xml replace.1.xsl replace.1.out \ + split.1.xml split.1.xsl split.1.out \ + tokenize.1.xml tokenize.1.xsl tokenize.1.out \ + tokenize.2.xml tokenize.2.xsl tokenize.2.out \ + tokenize.3.xml tokenize.3.xsl tokenize.3.out + +CLEANFILES = .memdump + +valgrind: + @echo '## Running the regression tests under Valgrind' + $(MAKE) CHECKER='libtool --mode=execute valgrind -q --leak-check=full' tests + +test tests: $(top_builddir)/xsltproc/xsltproc + @echo '## Running exslt string tests' + @(echo > .memdump) + @(for i in $(srcdir)/*.xsl ; do \ + name=`basename $$i .xsl` ; \ + if [ ! -f $(srcdir)/$$name.xml ] ; then continue ; fi ; \ + log=`$(CHECKER) $(top_builddir)/xsltproc/xsltproc \ + $(srcdir)/$$name.xsl $(srcdir)/$$name.xml > $$name.res 2>$$name.bad;\ + if [ ! -f $(srcdir)/$$name.out ] ; then \ + cp $$name.res $(srcdir)/$$name.out ; \ + if [ -s $$name.bad ] ; then \ + mv $$name.bad $(srcdir)/$$name.err ; \ + fi ; \ + else \ + if [ ! -s $$name.res ] ; then \ + echo "Fatal error, no $$name.res\n" ; \ + else \ + diff $(srcdir)/$$name.out $$name.res ; \ + if [ -s $(srcdir)/$$name.err ] ; then \ + diff $(srcdir)/$$name.err $$name.bad; \ + else \ + diff /dev/null $$name.bad; \ + fi ; \ + fi ; \ + fi; \ + grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" || true`;\ + if [ -n "$$log" ] ; then \ + echo $$name result ; \ + echo "$$log" ; \ + fi ; \ + rm -f $$name.res $$name.bad ; \ + done) diff --git a/libxslt/tests/exslt/strings/align.1.out b/libxslt/tests/exslt/strings/align.1.out new file mode 100644 index 0000000..0b639e5 --- /dev/null +++ b/libxslt/tests/exslt/strings/align.1.out @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<test-results> + <test-result>déja vu––––––</test-result> + <test-result>–––déja vu–––</test-result> + <test-result>––––––déja vu</test-result> + <test-result>déja</test-result> + <test-result>déja vu</test-result> +</test-results> diff --git a/libxslt/tests/exslt/strings/align.1.xml b/libxslt/tests/exslt/strings/align.1.xml new file mode 100644 index 0000000..f32b2dc --- /dev/null +++ b/libxslt/tests/exslt/strings/align.1.xml @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<test-cases> + <test-case string="déja vu" padding="–––––––––––––" alignment="left"/> + <test-case string="déja vu" padding="–––––––––––––" alignment="center"/> + <test-case string="déja vu" padding="–––––––––––––" alignment="right"/> + <test-case string="déja vu" padding="––––" alignment="left"/> + <test-case string="déja vu" padding="–––––––" alignment="left"/> +</test-cases> + diff --git a/libxslt/tests/exslt/strings/align.1.xsl b/libxslt/tests/exslt/strings/align.1.xsl new file mode 100644 index 0000000..3de033d --- /dev/null +++ b/libxslt/tests/exslt/strings/align.1.xsl @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + exclude-result-prefixes="str"> + +<xsl:output indent="yes"/> + +<xsl:template match="test-cases"> + <test-results> + <xsl:apply-templates select="test-case"/> + </test-results> +</xsl:template> + +<xsl:template match="test-case"> + <test-result> + <xsl:value-of select="str:align(@string, @padding, @alignment)"/> + </test-result> +</xsl:template> + +</xsl:stylesheet> + diff --git a/libxslt/tests/exslt/strings/padding.1.out b/libxslt/tests/exslt/strings/padding.1.out new file mode 100644 index 0000000..1833a65 --- /dev/null +++ b/libxslt/tests/exslt/strings/padding.1.out @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<test-results> + <test-result> + <padding> </padding> + <length-check>OK</length-check> + </test-result> + <test-result> + <padding>--------</padding> + <length-check>OK</length-check> + </test-result> + <test-result> + <padding>abcabcabca</padding> + <length-check>OK</length-check> + </test-result> + <test-result> + <padding>–––––––</padding> + <length-check>OK</length-check> + </test-result> + <test-result> + <padding>– – – – – –</padding> + <length-check>OK</length-check> + </test-result> + <test-result> + <padding>ÄÖÜÄÖÜ</padding> + <length-check>OK</length-check> + </test-result> +</test-results> diff --git a/libxslt/tests/exslt/strings/padding.1.xml b/libxslt/tests/exslt/strings/padding.1.xml new file mode 100644 index 0000000..16d0824 --- /dev/null +++ b/libxslt/tests/exslt/strings/padding.1.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<test-cases> + <test-case length="5"/> + <test-case length="8">-</test-case> + <test-case length="10">abc</test-case> + <test-case length="7">–</test-case> + <test-case length="11">– </test-case> + <test-case length="6">ÄÖÜ</test-case> +</test-cases> + diff --git a/libxslt/tests/exslt/strings/padding.1.xsl b/libxslt/tests/exslt/strings/padding.1.xsl new file mode 100644 index 0000000..c5d621d --- /dev/null +++ b/libxslt/tests/exslt/strings/padding.1.xsl @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + exclude-result-prefixes="str"> + +<xsl:output indent="yes"/> + +<xsl:template match="test-cases"> + <test-results> + <xsl:apply-templates select="test-case"/> + </test-results> +</xsl:template> + +<xsl:template match="test-case"> + <test-result> + <xsl:variable name="padding"> + <xsl:choose> + <xsl:when test="string(.)"> + <xsl:value-of select="str:padding(@length, .)"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="str:padding(@length)"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <padding> + <xsl:value-of select="$padding"/> + </padding> + <length-check> + <xsl:choose> + <xsl:when test="string-length($padding) = @length">OK</xsl:when> + <xsl:otherwise>FAIL</xsl:otherwise> + </xsl:choose> + </length-check> + </test-result> +</xsl:template> + +</xsl:stylesheet> + diff --git a/libxslt/tests/exslt/strings/replace.1.out b/libxslt/tests/exslt/strings/replace.1.out new file mode 100644 index 0000000..f41d67c --- /dev/null +++ b/libxslt/tests/exslt/strings/replace.1.out @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<out>; + result nodes: 1 + result text nodes: 1 + result string: a + + str:replace('a, simple, list', ', ', '-') + a-simple-list + + str:replace('a, simple, list', 'a, ', 'the ') + the simple, list + + str:replace('a, simple, list', 'list', 'array') + a, simple, array + + str:replace('a, simple, list', 'i', 'I') + a, sImple, lIst + + str:replace('a, simple, list', ', ', '') + asimplelist + + str:replace('fee, fi, fo, fum', $x, $y) + tee, eye, billow, a longer string + + str:replace('fee, fi, fo, fum', $x, 'j') + j, , , + + str:replace('foo', '', 'baz') + fbazobazo + + str:replace('Price is $1.10', $from, $to) + Price is \$1.10</out> diff --git a/libxslt/tests/exslt/strings/replace.1.xml b/libxslt/tests/exslt/strings/replace.1.xml new file mode 100644 index 0000000..16aac14 --- /dev/null +++ b/libxslt/tests/exslt/strings/replace.1.xml @@ -0,0 +1,16 @@ +<doc> + <strings> + <x>fee</x> + <x>fi</x> + <x>fo</x> + <x>fum</x> + <y>tee</y> + <y>eye</y> + <y>billow</y> + <y>a longer string</y> + <from>$</from> + <from>\</from> + <to>\$</to> + <to>$\backslash$</to> + </strings> +</doc> diff --git a/libxslt/tests/exslt/strings/replace.1.xsl b/libxslt/tests/exslt/strings/replace.1.xsl new file mode 100644 index 0000000..f9a7442 --- /dev/null +++ b/libxslt/tests/exslt/strings/replace.1.xsl @@ -0,0 +1,49 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + exclude-result-prefixes="str"> + +<xsl:template match="/"> + <xsl:variable name="x" select="doc/strings/x"/> + <xsl:variable name="y" select="doc/strings/y"/> + <xsl:variable name="from" select="doc/strings/from"/> + <xsl:variable name="to" select="doc/strings/to"/> + <xsl:variable name="result" select="str:replace('a', 'b', 'c')"/> + +<out>; + result nodes: <xsl:value-of select="count($result)"/> + result text nodes: <xsl:value-of select="count($result/self::text())"/> + result string: <xsl:value-of select="$result/self::text()"/> + + str:replace('a, simple, list', ', ', '-') + <xsl:copy-of select="str:replace('a, simple, list', ', ', '-')"/> + + str:replace('a, simple, list', 'a, ', 'the ') + <xsl:copy-of select="str:replace('a, simple, list', 'a, ', 'the ')"/> + + str:replace('a, simple, list', 'list', 'array') + <xsl:copy-of select="str:replace('a, simple, list', 'list', 'array')"/> + + str:replace('a, simple, list', 'i', 'I') + <xsl:copy-of select="str:replace('a, simple, list', 'i', 'I')"/> + + str:replace('a, simple, list', ', ', '') + <xsl:copy-of select="str:replace('a, simple, list', ', ', '')"/> + + str:replace('fee, fi, fo, fum', $x, $y) + <xsl:copy-of select="str:replace('fee, fi, fo, fum', $x, $y)" /> + + str:replace('fee, fi, fo, fum', $x, 'j') + <xsl:copy-of select="str:replace('fee, fi, fo, fum', $x, 'j')" /> + + str:replace('foo', '', 'baz') + <xsl:copy-of select="str:replace('foo', '', 'baz')" /> + + str:replace('Price is $1.10', $from, $to) + <xsl:copy-of select="str:replace('Price is $1.10', $from, $to)" /> + +</out> +</xsl:template> + +</xsl:stylesheet> diff --git a/libxslt/tests/exslt/strings/split.1.out b/libxslt/tests/exslt/strings/split.1.out new file mode 100644 index 0000000..1fbb470 --- /dev/null +++ b/libxslt/tests/exslt/strings/split.1.out @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<out>; + str:split('a, simple, list', ', ') + <token>a</token><token>simple</token><token>list</token> + + str:split('data math str') + <token>data</token><token>math</token><token>str</token> + + str:split('foobar', '') + <token>f</token><token>o</token><token>o</token><token>b</token><token>a</token><token>r</token> + + str:split('-*- hello - world -*-', '-') + <token>*</token><token> hello </token><token> world </token><token>*</token> + + str:split('data &math str;') + <token>data</token><token>&math</token><token>str;</token></out> diff --git a/libxslt/tests/exslt/strings/split.1.xml b/libxslt/tests/exslt/strings/split.1.xml new file mode 100644 index 0000000..69d62f2 --- /dev/null +++ b/libxslt/tests/exslt/strings/split.1.xml @@ -0,0 +1 @@ +<doc/> diff --git a/libxslt/tests/exslt/strings/split.1.xsl b/libxslt/tests/exslt/strings/split.1.xsl new file mode 100644 index 0000000..7958bd1 --- /dev/null +++ b/libxslt/tests/exslt/strings/split.1.xsl @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + exclude-result-prefixes="str"> + +<xsl:template match="/"> +<out>; + str:split('a, simple, list', ', ') + <xsl:copy-of select="str:split('a, simple, list', ', ')"/> + + str:split('data math str') + <xsl:copy-of select="str:split('data math str')"/> + + str:split('foobar', '') + <xsl:copy-of select="str:split('foobar', '')"/> + + str:split('-*- hello - world -*-', '-') + <xsl:copy-of select="str:split('-*- hello - world -*-', '-')"/> + + str:split('data &math str;') + <xsl:copy-of select="str:split('data &math str;')"/> +</out> +</xsl:template> + +</xsl:stylesheet> diff --git a/libxslt/tests/exslt/strings/tokenize.1.out b/libxslt/tests/exslt/strings/tokenize.1.out new file mode 100644 index 0000000..debb251 --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.1.out @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<out>; + str:tokenize('2001-06-03T11:40:23', '-T:') + <token>2001</token><token>06</token><token>03</token><token>11</token><token>40</token><token>23</token>; + + str:tokenize('date math str') + <token>date</token><token>math</token><token>str</token>; + + str:tokenize('This is & strange behavior', ' ') + <token>This</token><token>is</token><token>&</token><token>strange</token><token>behavior</token>; + + str:tokenize('This is & strange; behavior', ' ') + <token>This</token><token>is</token><token>&</token><token>strange;</token><token>behavior</token>; + + str:tokenize('This is &strange; behavior', ' ') + <token>This</token><token>is</token><token>&strange;</token><token>behavior</token>; +</out> diff --git a/libxslt/tests/exslt/strings/tokenize.1.xml b/libxslt/tests/exslt/strings/tokenize.1.xml new file mode 100644 index 0000000..04e42ea --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.1.xml @@ -0,0 +1,5 @@ +<?xml version="1.0"?> + +<doc> + +</doc> diff --git a/libxslt/tests/exslt/strings/tokenize.1.xsl b/libxslt/tests/exslt/strings/tokenize.1.xsl new file mode 100644 index 0000000..0e801d0 --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.1.xsl @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + exclude-result-prefixes="str"> + +<xsl:template match="/"> +<out>; + str:tokenize('2001-06-03T11:40:23', '-T:') + <xsl:copy-of select="str:tokenize('2001-06-03T11:40:23', '-T:')"/>; + + str:tokenize('date math str') + <xsl:copy-of select="str:tokenize('date math str')"/>; + + str:tokenize('This is & strange behavior', ' ') + <xsl:copy-of select="str:tokenize('This is & strange behavior', ' ')"/>; + + str:tokenize('This is & strange; behavior', ' ') + <xsl:copy-of select="str:tokenize('This is & strange; behavior', ' ')"/>; + + str:tokenize('This is &strange; behavior', ' ') + <xsl:copy-of select="str:tokenize('This is &strange; behavior', ' ')"/>; +</out> +</xsl:template> + +</xsl:stylesheet> diff --git a/libxslt/tests/exslt/strings/tokenize.2.out b/libxslt/tests/exslt/strings/tokenize.2.out new file mode 100644 index 0000000..32bf7e1 --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.2.out @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<tok>This</tok><tok>is</tok><tok>strange</tok><tok>behavior</tok> diff --git a/libxslt/tests/exslt/strings/tokenize.2.xml b/libxslt/tests/exslt/strings/tokenize.2.xml new file mode 100644 index 0000000..69d62f2 --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.2.xml @@ -0,0 +1 @@ +<doc/> diff --git a/libxslt/tests/exslt/strings/tokenize.2.xsl b/libxslt/tests/exslt/strings/tokenize.2.xsl new file mode 100644 index 0000000..c60a6fe --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.2.xsl @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + extension-element-prefixes="str"> + +<xsl:template match="/"> +<xsl:for-each select="str:tokenize('This is strange behavior', ' ')" > + <tok><xsl:value-of select="."/></tok> +</xsl:for-each> +</xsl:template> + +</xsl:stylesheet> diff --git a/libxslt/tests/exslt/strings/tokenize.3.out b/libxslt/tests/exslt/strings/tokenize.3.out new file mode 100644 index 0000000..539a2fb --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.3.out @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +/foo/bar + 'foo' + 'bar' +//foo/bar + 'foo' + 'bar' +foo//bar + 'foo' + 'bar' +foo/bar/ + 'foo' + 'bar' +foo/bar// + 'foo' + 'bar' + diff --git a/libxslt/tests/exslt/strings/tokenize.3.xml b/libxslt/tests/exslt/strings/tokenize.3.xml new file mode 100644 index 0000000..9d5c293 --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.3.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + version="1.0"> + +<xsl:template match="/"> + <xsl:for-each select="//string"> + <xsl:text><xsl:value-of select="text()"/></xsl:text> + <xsl:for-each select="str:tokenize(text(), '/')"> + <xsl:text> '</xsl:text> + <xsl:value-of select="."/> + <xsl:text>'</xsl:text> + </xsl:for-each> + </xsl:for-each> +</xsl:template> + +<xsl:template name="foobar"> + <string>/foo/bar</string> + <string>//foo/bar</string> + <string>foo//bar</string> + <string>foo/bar/</string> + <string>foo/bar//</string> +</xsl:template> + +</xsl:stylesheet> diff --git a/libxslt/tests/exslt/strings/tokenize.3.xsl b/libxslt/tests/exslt/strings/tokenize.3.xsl new file mode 100644 index 0000000..2ea6b12 --- /dev/null +++ b/libxslt/tests/exslt/strings/tokenize.3.xsl @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:str="http://exslt.org/strings" + version="1.0"> + +<xsl:template match="/"> + <xsl:for-each select="//string"> + <xsl:value-of select="text()"/> + <xsl:text> +</xsl:text> + <xsl:for-each select="str:tokenize(text(), '/')"> + <xsl:text> '</xsl:text> + <xsl:value-of select="."/> + <xsl:text>' +</xsl:text> + </xsl:for-each> + </xsl:for-each> +</xsl:template> + +<xsl:template name="foobar"> + <string>/foo/bar</string> + <string>//foo/bar</string> + <string>foo//bar</string> + <string>foo/bar/</string> + <string>foo/bar//</string> +</xsl:template> + +</xsl:stylesheet> |