Skip to content

Commit

Permalink
add math/min test for exslt
Browse files Browse the repository at this point in the history
  • Loading branch information
wamuir committed Jan 11, 2022
1 parent bd48e8f commit 57f01a0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions xslt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,66 @@ func TestStylesheetTransform(t *testing.T) {
}
}

func TestStylesheetTransformExslt(t *testing.T) {
tests := []struct {
name string
xml []byte
xsl []byte
res []byte
}{
{
"math/min",
[]byte(`<?xml version="1.0" encoding="UTF-8"?>
<values>
<value>7</value>
<value>11</value>
<value>8</value>
<value>4</value>
</values>
`),
[]byte(`<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math"
extension-element-prefixes="math">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="values">
<result>
<xsl:text>Minimum: </xsl:text>
<xsl:value-of select="math:min(value)" />
</result>
</xsl:template>
</xsl:stylesheet>
`),
[]byte(`<?xml version="1.0" encoding="UTF-8"?>
<result>Minimum: 4</result>
`),
},
}

for _, c := range tests {
t.Run(c.name, func(t *testing.T) {
xs, err := xslt.NewStylesheet(c.xsl)
if err != nil {
t.Fatal(err)
}

got, err := xs.Transform(c.xml)
if err != nil {
t.Fatal(err)
}

want := c.res
if !bytes.Equal(got, want) {
t.Errorf("got: %s, want: %s", got, want)
}
})
}

}

func BenchmarkStylesheetTransform(b *testing.B) {
xml, _ := ioutil.ReadFile("testdata/document.xml")
xsl, _ := ioutil.ReadFile("testdata/style1.xsl")
Expand Down

0 comments on commit 57f01a0

Please sign in to comment.