Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

Commit

Permalink
Added preliminary specs for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Feb 14, 2011
1 parent 7768051 commit 245116b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
target/
project/boot/
lib_managed/
8 changes: 8 additions & 0 deletions project/build/Project.scala
@@ -0,0 +1,8 @@
import sbt._

class Project(info: ProjectInfo) extends DefaultProject(info) {
val scalaTools = "scalaTools" at "http://scala-tools.org/repo/"
val specs = "org.scala-tools.testing" %% "specs" % "1.6.7.1" % "test"

override def includeTest(s: String) = s endsWith "Specs"
}
35 changes: 35 additions & 0 deletions src/test/scala/com/codecommit/antixml/XMLSpecs.scala
@@ -0,0 +1,35 @@
package com.codecommit.antixml

import org.specs._

object XMLSpecs extends Specification {
import XML._

"xml parsing" should {
"parse an empty elem" in {
fromString("<test/>") mustEqual NodeSeq(elem("test"))
}

"parse an elem with text" in {
fromString("<test>This is a test</test>") mustEqual NodeSeq(elem("test", Text("This is a test")))
}

"parse an elem with sub-elements" in {
fromString("<test><sub1/><sub2/></test>") mustEqual NodeSeq(elem("test", elem("sub1"), elem("sub2")))
}

"parse a deeply-nested structure" in {
fromString("<test><sub1><subsub1><subsubsub1/><subsubsub2/></subsub1></sub1><sub2/><sub3><subsub1/></sub3></test>") mustEqual NodeSeq(elem("test", elem("sub1", elem("subsub1", elem("subsubsub1"), elem("subsubsub2"))), elem("sub2"), elem("sub3", elem("subsub1"))))
}

"parse mixed content" in {
fromString("<test>This is a <inner-test/> of great glory!</test>") mustEqual NodeSeq(elem("test", Text("This is a "), elem("inner-test"), Text(" of great glory!")))
}

"preserve whitespace" in {
fromString("<test>\n \n\t\n</test>") mustEqual NodeSeq(elem("test", Text("\n \n\t\n")))
}
}

def elem(name: String, children: Node*) = Elem(None, name, Map(), NodeSeq(children: _*))
}

0 comments on commit 245116b

Please sign in to comment.