diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-03 01:01:00 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-03 01:01:00 -0800 |
commit | 52373d64b86ed514998ff5e6a128bf26b77e9f2e (patch) | |
tree | 4e45978fc21de186e71549b139934165a9bcd2cb /scalatexApi/src/test/scala/scalatex/ParserTests.scala | |
parent | 5cf89bb9d5e0d3c42610d3d2be47815ef41ecd65 (diff) | |
download | hands-on-scala-js-52373d64b86ed514998ff5e6a128bf26b77e9f2e.tar.gz hands-on-scala-js-52373d64b86ed514998ff5e6a128bf26b77e9f2e.tar.bz2 hands-on-scala-js-52373d64b86ed514998ff5e6a128bf26b77e9f2e.zip |
WIP
Diffstat (limited to 'scalatexApi/src/test/scala/scalatex/ParserTests.scala')
-rw-r--r-- | scalatexApi/src/test/scala/scalatex/ParserTests.scala | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/scalatexApi/src/test/scala/scalatex/ParserTests.scala b/scalatexApi/src/test/scala/scalatex/ParserTests.scala new file mode 100644 index 0000000..34c6fdb --- /dev/null +++ b/scalatexApi/src/test/scala/scalatex/ParserTests.scala @@ -0,0 +1,69 @@ +package scalatex + + +import org.parboiled2._ +import torimatomeru.ScalaSyntax + +object ParserTests extends utest.TestSuite{ + import Ast._ + import utest._ + def check[T](input: String, parse: ScalatexParser => scala.util.Try[T], expected: T) = { + val parsed = parse(new ScalatexParser(input)) + assert(parsed.get == expected) + } + def tests = TestSuite{ + 'Test { + * - check("i am a cow", _.Text.run(), Block.Text("i am a cow")) + * - check("i am a @cow", _.Text.run(), Block.Text("i am a ")) + * - check("i am a @@cow", _.Text.run(), Block.Text("i am a @cow")) + * - check("i am a @@@cow", _.Text.run(), Block.Text("i am a @")) + * - check("i am a @@@@cow", _.Text.run(), Block.Text("i am a @@cow")) + + } + 'Code{ + * - check("@(1 + 1)", _.Code.run(), Code("(1 + 1)")) + * - check("@{{1} + (1)}", _.Code.run(), Code("{{1} + (1)}")) + * - check("@{val x = 1; 1}", _.Code.run(), Code("{val x = 1; 1}")) + * - check("@{`{}}{()@`}", _.Code.run(), Code("{`{}}{()@`}")) + } + + 'Block{ + * - check("{i am a cow}", _.TBlock.run(), Block(Seq(Block.Text("i am a cow")))) + * - check("{i @am a @cow}", _.TBlock.run(), + Block(Seq( + Block.Text("i "), + Chain(Code("am"),Seq()), + Block.Text(" a "), + Chain(Code("cow"),Seq()) + )) + ) + } + 'Chain{ + * - check("@omg.bbq[omg].fff[fff](123)", _.ScalaChain.run(), + Chain(Code("omg"),Seq(Chain.Prop(".bbq[omg]"), Chain.Prop(".fff[fff]"), Chain.Args("(123)"))) + ) + * - check("@omg{bbq}.cow(moo){a @b}", _.ScalaChain.run(), + Chain(Code("omg"),Seq( + Block(Seq(Block.Text("bbq"))), + Chain.Prop(".cow"), + Chain.Args("(moo)"), + Block(Seq(Block.Text("a "), Chain(Code("b"), Nil))) + )) + ) + } + 'Body{ + + val str = + """ + |@omg + | @wtf + | @bbq + | @lol + """.stripMargin + new ScalatexParser(str).Body.run() + } + } + +} + + |