diff --git a/lib/simplates/pagination.ex b/lib/simplates/pagination.ex
index b963013..61c57d5 100644
--- a/lib/simplates/pagination.ex
+++ b/lib/simplates/pagination.ex
@@ -10,31 +10,46 @@ defmodule Simplates.Pagination do
import Simplates.Simplate, only: [config: 1]
- @script_regex ~r/^\
-
-
- I could be a handlebars template or something, who knows :
-
-
-
-"""
-)
-
-IO.inspect(doc)
-
-Enum.each(XmlNode.all(doc, "//root/template"), fn(node) ->
- IO.inspect(node)
- IO.puts "#{XmlNode.node_name(node)} id=#{XmlNode.attr(node, "id")} text=#{XmlNode.text(node)}"
-end)
-
-IO.puts(
- doc
- |> XmlNode.first("//child[@id='2']")
- |> XmlNode.text
-)
-
-IO.puts(
- doc
- |> XmlNode.first("//child[@id='3']")
- |> XmlNode.text
-)
-
-IO.puts(
- doc
- |> XmlNode.first("//root")
- |> XmlNode.first("template")
- |> XmlNode.text
-)
\ No newline at end of file
diff --git a/test/simplates/fake-www/index.spt b/test/simplates/fake-www/index.spt
index 1e7fbdd..4a9e0fb 100644
--- a/test/simplates/fake-www/index.spt
+++ b/test/simplates/fake-www/index.spt
@@ -1 +1,3 @@
-Greetings, program!
\ No newline at end of file
+
+Greetings, program!
+
\ No newline at end of file
diff --git a/test/simplates/pagination_test.exs b/test/simplates/pagination_test.exs
index 4711e44..2b4a23e 100644
--- a/test/simplates/pagination_test.exs
+++ b/test/simplates/pagination_test.exs
@@ -4,7 +4,7 @@ defmodule Simplates.PaginationTest do
alias Simplates.Pagination, as: Pagination
test "single page adds one code pages" do
- pages = Pagination.parse_pages("Hello, world! I have no code!")
+ pages = Pagination.parse_pages("\nHello, world! I have no code!\n")
assert pages.code.raw == ""
assert pages.templates[nil].raw == "Hello, world! I have no code!"
@@ -12,8 +12,12 @@ defmodule Simplates.PaginationTest do
test "two page adds nothing" do
pages = Pagination.parse_pages("
-
- Hello, world! I have SOME code!")
+
+
+Hello, world! I have SOME code!
+")
assert String.trim(pages.code.raw) == "some_code = 3"
assert String.trim(pages.templates[nil].raw) == "Hello, world! I have SOME code!"
@@ -21,17 +25,20 @@ defmodule Simplates.PaginationTest do
test "two page adds nothing with specline" do
pages = Pagination.parse_pages("
-
-
- Hello, world! I have SOME code and a specline!
- ")
+
+
+Hello, world! I have SOME code and a specline!
+")
assert String.trim(pages.code.raw) == "some_code = 2"
assert String.trim(pages.templates["media/type"].raw) == "Hello, world! I have SOME code and a specline!"
end
test "parser ignores any non-root level tags" do
- pages = Pagination.parse_pages(~s(
+ pages = Pagination.parse_pages(~s(
+
This test ensures anything inside this template tag is ignored entirely by the parser.
+
-
- Greetings, program!
-
+
+Greetings, program!
+
-
- Greetings, program!
-
+
+Greetings, program!
+
"""
test "render is happy not to negotiate" do
@@ -38,7 +40,7 @@ defmodule Simplates.SimplateTest do
end
test "render is happy not to negotiate with defaults" do
- res = Simplate.render(simple_simplate(" Greetings, program!", "index.spt"))
+ res = Simplate.render(simple_simplate("\n\nGreetings, program!\n", "index.spt"))
assert res.output == "Greetings, program!"
end
@@ -58,19 +60,19 @@ defmodule Simplates.SimplateTest do
end
test "create simplate sets default_content_type when bound simplate" do
- simp = simple_simplate(" content
", "index.html.spt")
+ simp = simple_simplate("\n\ncontent
\n", "index.html.spt")
assert simp.default_content_type == "text/html"
end
test "create simplate sets content_type on template page for bound simplate" do
- simp = simple_simplate(" example", "index.json.spt")
+ simp = simple_simplate("\n\nexample\n", "index.json.spt")
assert simp.templates["application/json"]
assert simp.templates["application/json"].content_type == "application/json"
end
test "render bound simplate properly uses simplate.default_content_type" do
- res = Simplate.render(simple_simplate(" example", "index.json.spt"), "application/json")
+ res = Simplate.render(simple_simplate("\n\nexample\n", "index.json.spt"), "application/json")
assert res.content_type == "application/json"
end
diff --git a/test/spt_parser_test.exs b/test/spt_parser_test.exs
new file mode 100755
index 0000000..07b7095
--- /dev/null
+++ b/test/spt_parser_test.exs
@@ -0,0 +1,42 @@
+defmodule Simplates.SptParserTest do
+ use ExUnit.Case, async: true
+
+ import Simplates.Parser, only: [parse: 1]
+
+ test "basic root document parsing" do
+ src = "\nhello world\n"
+
+ assert parse(src) == [src]
+ end
+
+ test "ignores html inside templates" do
+ src = "\nhello derp
world\n"
+
+ assert parse(src) == [src]
+ end
+
+ test "handles pure unicode" do
+ src = "\nŦħɇꝗᵾɨȼꝁƀɍøwnføxɉᵾmᵽsøvɇɍŧħɇłȺƶɏđøǥ\n"
+
+ assert parse(src) == [src]
+ end
+
+ test "ignores unicode templates" do
+ src = "\nhello world Ŧħɇ ꝗᵾɨȼꝁ ƀɍøwn føx ɉᵾmᵽs øvɇɍ ŧħɇ łȺƶɏ đøǥ\n"
+
+ assert parse(src) == [src]
+ end
+
+ test "ignores template inside templates" do
+ src = "\nhello this is just dumb html ignore it world\n"
+
+ assert parse(src) == [src]
+ end
+
+ test "parses multiple" do
+ src = "\nHello world\n\n\nHello Paul\n"
+
+ assert parse(src) == ["\nHello world\n","\nHello Paul\n"]
+ end
+
+end