more code

This commit is contained in:
leaf corcoran
2013-10-23 23:10:48 -07:00
parent dfdeae21d7
commit 8957308167
2 changed files with 171 additions and 42 deletions

95
spec/elua_spec.moon Normal file
View File

@@ -0,0 +1,95 @@
import compile, render, Parser from require "elua"
describe "elua", ->
describe "Parser", ->
cases = {
{
"hello world"
"hello world"
}
{
"one surf-zone two"
"one <%= var %> two"
{var: "surf-zone"}
}
{
"a ((1))((2))((3)) b"
"a <% for i=1,3 do %>((<%= i %>))<% end %> b"
}
{
"y%>u"
[[<%= "y%>u" %>]]
}
{
[[
This is my message to you
This is my message to 4
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
hello 10
message: yeah
This is my message to oh yeah %>"]]
[[
This is my message to <%= "you" %>
This is my message to <%= 4 %>
<% if things then %>
I love things
<% end %>
<% for i=1,10 do%>
hello <%= i %>
<% end %>
message: <%= visitor %>
This is my message to <%= [=[oh yeah %>"]=] %>]]
{
visitor: "yeah"
}
}
}
for case in *cases
it "should run template", ->
assert.same case[1], render unpack case, 2
describe "Parser.in_string", ->
cases = {
{ "hello world", false }
{ "hello 'world", true }
{ [[hello "hello \" world]], true }
{ "hello [=[ wor'ld ]=]dad", false }
}
for {str, expected} in *cases
it "should detect if in string", ->
assert.same expected, Parser.in_string { :str }, 1