From 52373d64b86ed514998ff5e6a128bf26b77e9f2e Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 3 Nov 2014 01:01:00 -0800 Subject: WIP --- scalatexApi/src/test/scala/scalatex/Main.scala | 58 ------------------ .../src/test/scala/scalatex/ParserTests.scala | 69 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 58 deletions(-) delete mode 100644 scalatexApi/src/test/scala/scalatex/Main.scala create mode 100644 scalatexApi/src/test/scala/scalatex/ParserTests.scala (limited to 'scalatexApi/src/test') diff --git a/scalatexApi/src/test/scala/scalatex/Main.scala b/scalatexApi/src/test/scala/scalatex/Main.scala deleted file mode 100644 index fa0d213..0000000 --- a/scalatexApi/src/test/scala/scalatex/Main.scala +++ /dev/null @@ -1,58 +0,0 @@ -package scalatex - - -import org.parboiled2._ -import torimatomeru.ScalaSyntax - -object Main 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))) - )) - ) - } - } - -} - - 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() + } + } + +} + + -- cgit v1.2.3