diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-03 22:41:55 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-03 22:41:55 -0800 |
commit | 25d3233bae4ca89ba3a3916dfa9b45ee42d66435 (patch) | |
tree | d7cefbcc72cb7eb8e8a0abb120b375208bd4fd15 /scalatexApi/src/test/scala/scalatex | |
parent | ed923d3445e1f304949eee2ee414987d98756a86 (diff) | |
download | hands-on-scala-js-25d3233bae4ca89ba3a3916dfa9b45ee42d66435.tar.gz hands-on-scala-js-25d3233bae4ca89ba3a3916dfa9b45ee42d66435.tar.bz2 hands-on-scala-js-25d3233bae4ca89ba3a3916dfa9b45ee42d66435.zip |
Enabled a bunch more tests...
Diffstat (limited to 'scalatexApi/src/test/scala/scalatex')
-rw-r--r-- | scalatexApi/src/test/scala/scalatex/BasicTests.scala | 256 | ||||
-rw-r--r-- | scalatexApi/src/test/scala/scalatex/ParserTests.scala | 66 |
2 files changed, 189 insertions, 133 deletions
diff --git a/scalatexApi/src/test/scala/scalatex/BasicTests.scala b/scalatexApi/src/test/scala/scalatex/BasicTests.scala index 91291dd..c7e2d6a 100644 --- a/scalatexApi/src/test/scala/scalatex/BasicTests.scala +++ b/scalatexApi/src/test/scala/scalatex/BasicTests.scala @@ -11,42 +11,42 @@ object BasicTests extends TestSuite{ import TestUtil._ val tests = TestSuite{ -// -// 'helloWorld{ -// object omg { -// def wtf(s: Frag*): Frag = Seq[Frag]("|", s, "|") -// } -// def str = "hear me moo" -// check( -// tw(""" -// @omg.wtf -// i @b{am} cow @str -// """), -// "|i<b>am</b>cowhearmemoo|" -// ) -// } + + 'helloWorld{ + object omg { + def wtf(s: Frag*): Frag = Seq[Frag]("|", s, "|") + } + def str = "hear me moo" + check( + tw(""" + @omg.wtf + i @b{am} cow @str + """), + "|i<b>am</b>cowhearmemoo|" + ) + } 'interpolation{ -// 'chained-check( -// tw("omg @scala.math.pow(0.5, 3) wtf"), -// "omg 0.125 wtf" -// ) -// 'parens-check( -// tw("omg @(1 + 2 + 3 + 4) wtf"), -// "omg 10 wtf" -// ) -// 'block-check( -// tw(""" -// @{"lol" * 3} -// @{ -// val omg = "omg" -// omg * 2 -// } -// """), -// """ -// lollollol -// omgomg -// """ -// ) + 'chained-check( + tw("omg @scala.math.pow(0.5, 3) wtf"), + "omg 0.125 wtf" + ) + 'parens-check( + tw("omg @(1 + 2 + 3 + 4) wtf"), + "omg 10 wtf" + ) + 'block-check( + tw(""" + @{"lol" * 3} + @{ + val omg = "omg" + omg * 2 + } + """), + """ + lollollol + omgomg + """ + ) } // 'imports{ // object Whee{ @@ -70,20 +70,20 @@ object BasicTests extends TestSuite{ // """ // ) // } -// 'parenArgumentLists{ -// 'attributes{ -// check( -// tw(""" -// @div(id:="my-id"){ omg } -// @div(id:="my-id") -// omg -// """), -// """ -// <divid="my-id">omg</div> -// <divid="my-id">omg</div> -// """ -// ) -// } + 'parenArgumentLists{ + 'attributes{ + check( + tw(""" + @div(id:="my-id"){ omg } + @div(id:="my-id") + omg + """), + """ + <divid="my-id">omg</div> + <divid="my-id">omg</div> + """ + ) + } // 'multiline{ // // check( @@ -101,51 +101,51 @@ object BasicTests extends TestSuite{ // """ // ) // } -// } -// 'grouping{ -// 'negative{ -// // The indentation for "normal" text is ignored; we only -// // create blocks from the indentation following a scala -// // @xxx expression -// check( -// tw(""" -// I am cow hear me moo -// I weigh twice as much as you -// And I look good on the barbecue -// Yoghurt curds cream cheese and butter -// Comes from liquids from my udder -// I am cow I am cow hear me moooooo -// """), -// """ -// I am cow hear me moo -// I weigh twice as much as you -// And I look good on the barbecue -// Yoghurt curds cream cheese and butter -// Comes from liquids from my udder -// I am cow I am cow hear me moooooo -// """ -// ) -// } -// 'indentation{ -// 'simple{ -// val world = "World2" -// -// check( -// tw(""" -// @h1 -// Hello World -// @h2 -// hello @world -// @h3 -// Cow -// """), -// """ -// <h1>HelloWorld</h1> -// <h2>helloWorld2</h2> -// <h3>Cow</h3> -// """ -// ) -// } + } + 'grouping{ + 'negative{ + // The indentation for "normal" text is ignored; we only + // create blocks from the indentation following a scala + // @xxx expression + check( + tw(""" + I am cow hear me moo + I weigh twice as much as you + And I look good on the barbecue + Yoghurt curds cream cheese and butter + Comes from liquids from my udder + I am cow I am cow hear me moooooo + """), + """ + I am cow hear me moo + I weigh twice as much as you + And I look good on the barbecue + Yoghurt curds cream cheese and butter + Comes from liquids from my udder + I am cow I am cow hear me moooooo + """ + ) + } + 'indentation{ + 'simple{ + val world = "World2" + + check( + tw(""" + @h1 + Hello World + @h2 + hello @world + @h3 + Cow + """), + """ + <h1>HelloWorld</h1> + <h2>helloWorld2</h2> + <h3>Cow</h3> + """ + ) + } // 'linearNested{ // check( // tw(""" @@ -162,39 +162,39 @@ object BasicTests extends TestSuite{ // """ // ) // } -// 'crasher{ -// tw(""" -//@html -// @head -// @meta -// @div -// @a -// @span -// """) -// } -// } -// 'curlies{ -// 'simple{ -// val world = "World2" -// -// check( -// tw("""@div{Hello World}"""), -// """<div>HelloWorld</div>""" -// ) -// } -// 'multiline{ -// check( -// tw(""" -// @div{ -// Hello -// } -// """), -// """ -// <div>Hello</div> -// """ -// ) -// } -// } + 'crasher{ + tw(""" +@html + @head + @meta + @div + @a + @span + """) + } + } + 'curlies{ + 'simple{ + val world = "World2" + + check( + tw("""@div{Hello World}"""), + """<div>HelloWorld</div>""" + ) + } + 'multiline{ + check( + tw(""" + @div{ + Hello + } + """), + """ + <div>Hello</div> + """ + ) + } + } // 'mixed{ // check( // tw(""" @@ -420,6 +420,6 @@ object BasicTests extends TestSuite{ // "<p>lols2</p>" // ) // } -// } + } } } diff --git a/scalatexApi/src/test/scala/scalatex/ParserTests.scala b/scalatexApi/src/test/scala/scalatex/ParserTests.scala index b6e64ec..45d6b50 100644 --- a/scalatexApi/src/test/scala/scalatex/ParserTests.scala +++ b/scalatexApi/src/test/scala/scalatex/ParserTests.scala @@ -16,7 +16,63 @@ object ParserTests extends utest.TestSuite{ assert(parsed.get == expected) } def tests = TestSuite{ - 'Test { + 'Trim{ + def wrap(s: String) = "|" + s + "|" + * - { + val trimmed = wrap(stages.Trim(""" + i am cow + hear me moo + i weigh twice as much as you + """)) + val expected = wrap(""" + |i am cow + | hear me moo + | i weigh twice as much as you + |""".stripMargin) + assert(trimmed == expected) + + } + * - { + val trimmed = wrap(stages.Trim( + """ + @{"lol" * 3} + @{ + val omg = "omg" + omg * 2 + } + """ + )) + val expected = wrap( + """ + |@{"lol" * 3} + |@{ + | val omg = "omg" + | omg * 2 + |} + |""".stripMargin + ) + assert(trimmed == expected) + } + 'dropTrailingWhitespace - { + + val trimmed = wrap(stages.Trim( + Seq( + " i am a cow ", + " hear me moo ", + " i weigh twice as much as you" + ).mkString("\n") + )) + val expected = wrap( + Seq( + "i am a cow", + " hear me moo", + " i weigh twice as much as you" + ).mkString("\n") + ) + assert(trimmed == expected) + } + } + 'Text { * - 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")) @@ -63,7 +119,7 @@ object ParserTests extends utest.TestSuite{ ) } 'Body{ - * - check( + 'indents - check( """ |@omg | @wtf @@ -84,7 +140,7 @@ object ParserTests extends utest.TestSuite{ )))) )) ) - * - check( + 'dedents - check( """ |@omg | @wtf @@ -101,7 +157,7 @@ object ParserTests extends utest.TestSuite{ Chain("bbq", Seq()) )) ) - * - check( + 'dedentText - check( """ |@omg("lol", 1, 2) | @wtf @@ -139,7 +195,7 @@ object ParserTests extends utest.TestSuite{ // Text("bbq") // )) // ) - * - check( + 'codeBlocks - check( """ |@{"lol" * 3} |@{ |