summaryrefslogtreecommitdiff
path: root/scalatexApi/src/test/scala/scalatex/Main.scala
blob: fa0d213aedde9be462ade5d136e5cc1c00646513 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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)))
        ))
      )
    }
  }

}