From 25d3233bae4ca89ba3a3916dfa9b45ee42d66435 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 3 Nov 2014 22:41:55 -0800 Subject: Enabled a bunch more tests... --- .../src/test/scala/scalatex/BasicTests.scala | 256 ++++++++++----------- .../src/test/scala/scalatex/ParserTests.scala | 66 +++++- 2 files changed, 189 insertions(+), 133 deletions(-) (limited to 'scalatexApi/src/test/scala/scalatex') 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 -// """), -// "|iamcowhearmemoo|" -// ) -// } + + '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 + """), + "|iamcowhearmemoo|" + ) + } '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 -// """), -// """ -// omg -// omg -// """ -// ) -// } + 'parenArgumentLists{ + 'attributes{ + check( + tw(""" + @div(id:="my-id"){ omg } + @div(id:="my-id") + omg + """), + """ + omg + omg + """ + ) + } // '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 -// """), -// """ -//

HelloWorld

-//

helloWorld2

-//

Cow

-// """ -// ) -// } + } + '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 + """), + """ +

HelloWorld

+

helloWorld2

+

Cow

+ """ + ) + } // '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}"""), -// """
HelloWorld
""" -// ) -// } -// 'multiline{ -// check( -// tw(""" -// @div{ -// Hello -// } -// """), -// """ -//
Hello
-// """ -// ) -// } -// } + 'crasher{ + tw(""" +@html + @head + @meta + @div + @a + @span + """) + } + } + 'curlies{ + 'simple{ + val world = "World2" + + check( + tw("""@div{Hello World}"""), + """
HelloWorld
""" + ) + } + 'multiline{ + check( + tw(""" + @div{ + Hello + } + """), + """ +
Hello
+ """ + ) + } + } // 'mixed{ // check( // tw(""" @@ -420,6 +420,6 @@ object BasicTests extends TestSuite{ // "

lols2

" // ) // } -// } + } } } 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} |@{ -- cgit v1.2.3