/*
* Copyright 2003-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package groovy.xml
import org.custommonkey.xmlunit.XMLUnit
import org.custommonkey.xmlunit.Diff
/**
* Common test cases for StreamingMarkupBuilder and MarkupBuilder.
*
* @author Paul King
* @author Scott Stirling
* @author Pilho Kim
*/
abstract class BuilderTestSupport extends GroovyTestCase {
protected abstract assertExpectedXml(Closure markup, String expectedXml)
protected abstract assertExpectedXml(Closure markup, Closure configureBuilder, String expectedXml)
protected checkXml(String expectedXml, StringWriter writer) {
XMLUnit.ignoreWhitespace = true
def xmlDiff = new Diff(expectedXml, writer.toString())
assert xmlDiff.similar(), xmlDiff.toString() + "\n" + writer.toString()
}
void testHref() {
def m = {
a(href: "http://groovy.codehaus.org", "groovy")
}
assertExpectedXml m, "groovy"
}
void testHrefDoubleQuotes() {
def m = {
a(href: "http://groovy.codehaus.org", "groovy")
}
assertExpectedXml m, { it.useDoubleQuotes = true }, 'groovy'
}
void testNestedQuotesSingle() {
def m = {
root {
one( foo:"bar('baz')", 'foo("baz")' )
two( foo:'bar("baz")', "foo('baz')" )
}
}
assertExpectedXml m, '
The quick brown fox jumped over the lazy dog & sleepy cat
''' } void testMixedMarkupWithEntityExpansion() { def m = { p { em('Usually') mkp.yield ' Hearts & Diamonds ' b('beats') mkp.yieldUnescaped ' Spades & Clubs' } } assertExpectedXml m, '''\Usually Hearts & Diamonds beats Spades & Clubs
''' } void testMixedMarkupWithEmptyNodes() { def m = { p { mkp.yield 'Red: Hearts & Diamonds' br() mkp.yieldUnescaped 'Black: Spades & Clubs' } } assertExpectedXml m, '''\Red: Hearts & Diamonds\n
Black: Spades & Clubs \n
| 999 | 99 |