Permalink
Browse files

equivalent string xpath no-namespace tests as well

  • Loading branch information...
1 parent ffab796 commit df49edd4bf262f796494bed6d24dc1a768e10297 @chris-twiner committed Jul 5, 2012
@@ -0,0 +1,69 @@
+package scales.xml.jaxen
+
+class JaxenXmlReaderTest extends junit.framework.TestCase {
+ import junit.framework.Assert._
+ import scales.utils._
+ import ScalesUtils._
+ import scales.xml._
+ import ScalesXml._
+
+ /**
+ * Thanks to Richard for this
+ */
+ def testYahoo : Unit = {
+ val urlListing = resource(this, "/data/yahoo.htm")
+
+ val doc = loadXmlReader(urlListing, parsers = NuValidatorFactoryPool)
+ val root = top(doc)
+
+ val ns = Namespace("http://www.w3.org/1999/xhtml")
+
+ val strPath = ScalesXPath("/ns:html/ns:body/ns:p[2]/ns:table[2]/ns:tbody/ns:tr/ns:td/ns:table/ns:tbody/ns:tr/ns:td[1]/ns:a/ns:font", ns.prefixed("ns"))
+
+ assertEquals(9, strPath.evaluate(root).size)
+
+ assertEquals(5, ScalesXPath("//ns:table", ns.prefixed("ns")).evaluate(root).size)
+ assertEquals(1, ScalesXPath("//ns:table//ns:table", ns.prefixed("ns")).evaluate(root).size)
+ }
+
+
+ /**
+ * Thanks to Richard for this
+ */
+ def testYahooNoNS : Unit = {
+ val urlListing = resource(this, "/data/yahoo.htm")
+
+ val doc = loadXmlReader(urlListing, parsers = NuValidatorFactoryPool)
+ val root = top(doc)
+
+ val ns = Namespace("http://www.w3.org/1999/xhtml")
+
+ val strPath = ScalesXPath("/html/body/p[2]/table[2]/tbody/tr/td/table/tbody/tr/td[1]/a/font").withNameConversion(ScalesXPath.localOnly)
+
+ assertEquals(9, strPath.evaluate(root).size)
+
+ assertEquals(5, ScalesXPath("//table").withNameConversion(ScalesXPath.localOnly).evaluate(root).size)
+ assertEquals(1, ScalesXPath("//table//table").withNameConversion(ScalesXPath.localOnly).evaluate(root).size)
+ }
+
+ /**
+ * Thanks to Richard for this
+ */
+ def testYahooNoNSTagSoup : Unit = {
+ val urlListing = resource(this, "/data/yahoo.htm")
+
+ val doc = loadXmlReader(urlListing, parsers = TagSoupFactoryPool)
+ val root = top(doc)
+
+ val ns = Namespace("http://www.w3.org/1999/xhtml")
+
+ // tag soup doesn't add tbodys
+ val strPath = ScalesXPath("/html/body/p[2]/table[2]/tr/td/table/tr/td[1]/a/font").withNameConversion(ScalesXPath.localOnly)
+
+ assertEquals(9, strPath.evaluate(root).size)
+
+ assertEquals(5, ScalesXPath("//table").withNameConversion(ScalesXPath.localOnly).evaluate(root).size)
+ assertEquals(1, ScalesXPath("//table//table").withNameConversion(ScalesXPath.localOnly).evaluate(root).size)
+ }
+
+}
@@ -10,6 +10,9 @@ import SiteKeys.{siteCSS, siteResourceDir,
siteMarkupDocHeaders,
menuBarTitle}
+import de.johoop.jacoco4sbt._
+import JacocoPlugin._
+
object ScalesXmlRoot extends Build {
object sonatype extends org.improving.PublishToSonatype(ScalesXmlRoot) {
@@ -76,7 +79,7 @@ object ScalesXmlRoot extends Build {
*/
organization := "org.scalesxml",
offline := true,
- version := "0.3-RC7",
+ version := "0.3",
scalaVersion := "2.9.2",
crossScalaVersions := Seq("2.8.1", "2.8.2", "2.9.1", "2.9.2"),// "2.10.0-M4"),
//publishSetting,
@@ -92,8 +95,9 @@ object ScalesXmlRoot extends Build {
),
autoCompilerPlugins := false,
fork in run := true,
- parallelExecution in runSecurely := false
- ) ++ sonatype.settings
+ parallelExecution in runSecurely := false,
+ parallelExecution in jacoco.Config := false
+ ) ++ sonatype.settings ++ jacoco.settings
// ++ crazyness
val reconPerf = TaskKey[Unit]("recon-perf")
View
@@ -5,9 +5,13 @@ libraryDependencies ++= Seq(
"org.eclipse.mylyn.wikitext.mediawiki" % "mw.core" % "1.4.0-I20110104-0100-e3x",
"scales.sbtplugins" % "resources" % "0.1",
// markdown lib
- "com.tristanhunt" %% "knockoff" % "0.8.0-16"
+ "com.tristanhunt" %% "knockoff" % "0.8.0-16",
+ "org.jacoco" % "org.jacoco.core" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
+ "org.jacoco" % "org.jacoco.report" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.report", "jar", "jar"))
)
resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
-addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
+addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
+
+addSbtPlugin("de.johoop" % "jacoco4sbt" % "1.2.1")
View
@@ -24,7 +24,7 @@ As of Scales 0.3 there is direct support for SAX parsers via the loadXmlReader f
${cscala}
import org.xml.sax.XMLReader
- object NuValidatorFactoryPool extends scales.utils.SimpleUnboundedPool[XMLReader] {
+ object NuValidatorFactoryPool extends scales.utils.SimpleUnboundedPool[XMLReader] with DefaultSaxSupport {
def create = {
import nu.validator.htmlparser.{sax,common}
@@ -43,4 +43,24 @@ ${cscala}
val nuxml = loadXmlReader(xmlFile, parsers = NuValidatorFactoryPool)
${cend}
-Developers can also call readXml directly with a given XMLReader instance instead of using the pooled version.
+Developers can also call readXml directly with a given XMLReader instance instead of using the pooled version.
+
+If a given XMLReader cannot work with the DefaultSaxSupport it can override the appropriate functions. For example TagSoup doesn't support XmlVersion information, as such a TagSoupFactoryPool would look like:
+
+${cscala}
+object TagSoupFactoryPool extends scales.utils.SimpleUnboundedPool[XMLReader] with DefaultSaxSupport {
+
+ // doesn't support xml version retrieval
+ override def getXmlVersion( reader : XMLReader ) : AnyRef =
+ null
+
+ def create = {
+ import org.ccil.cowan.tagsoup.Parser
+ val reader = new Parser
+ // disable namespaces
+ reader.setFeature(Parser.namespacesFeature, false)
+ reader
+ }
+
+}
+${cend}

0 comments on commit df49edd

Please sign in to comment.