$LOAD_PATH.unshift File.dirname(__FILE__)
require 'helper'
class ParserTest < Test::Unit::TestCase
def test_parser
lexer = Mustache::Parser.new
tokens = lexer.compile(<<-EOF)
{{header}}
{{#items}}
{{#first}}
{{name}}
{{/first}}
{{#link}}
{{name}}
{{/link}}
{{/items}}
{{#empty}}
The list is empty.
{{/empty}}
EOF
expected = [:multi,
[:static, ""],
[:mustache, :etag, [:mustache, :fetch, ["header"]]],
[:static, "
\n"],
[:mustache,
:section,
[:mustache, :fetch, ["items"]],
[:multi,
[:mustache,
:section,
[:mustache, :fetch, ["first"]],
[:multi,
[:static, " "],
[:mustache, :etag, [:mustache, :fetch, ["name"]]],
[:static, "\n"]],
%Q' {{name}}\n'],
[:mustache,
:section,
[:mustache, :fetch, ["link"]],
[:multi,
[:static, " "],
[:mustache, :etag, [:mustache, :fetch, ["name"]]],
[:static, "\n"]],
%Q' {{name}}\n']],
%Q'{{#first}}\n {{name}}\n{{/first}}\n{{#link}}\n {{name}}\n{{/link}}\n'],
[:static, "\n"],
[:mustache,
:section,
[:mustache, :fetch, ["empty"]],
[:multi, [:static, "The list is empty.
\n"]],
%Q'The list is empty.
\n']]
assert_equal expected, tokens
end
def test_raw_content_and_whitespace
lexer = Mustache::Parser.new
tokens = lexer.compile("{{#list}}\t{{/list}}")
expected = [:multi,
[:mustache,
:section,
[:mustache, :fetch, ["list"]],
[:multi, [:static, "\t"]],
"\t"]]
assert_equal expected, tokens
end
end