[2:3]
mailtoのテスト
- 3名前: ななしさん 投稿日: Fri Jan 26 19:00:44 JST 2001されたみたい
- 3名前: ななしさん 投稿日: Fri Jan 26 19:00:44 JST 2001されたみたい
|
END
#parse_and_print(h)
assert_equal('special_tag("%=", " Time.new ") ',
parse('<%= Time.new %>').to_ruby)
assert_equal('<%= Time.new %>',
parse('<%= Time.new %>').to_s)
assert_equal('',
parse('').to_s)
assert_equal('',
parse('').to_s)
assert_equal('',
parse('').to_s)
# assert_equal('',
# parse('').to_s)
assert_equal('',
parse('').to_s)
assert_equal('',
parse('').to_s)
end
def test_parser2
assert_equal('e(:ul) { e(:li) { "abc" } }',parse("").to_ruby)
assert_equal('e(:ul) { [ e(:li) { "abc" }, e(:li) { "efg" }, e(:li) { "xyz" } ] }',
parse("").to_ruby)
assert_equal('e(:ul) { [ e(:li) { "abc" }, e(:li) { "efg" }, e(:li) { "xyz" } ] }',
parse("").to_ruby)
assert_equal('e(:ul) { [ e(:li) { "abc" }, e(:li) { "efg" }, e(:li) { "xyz" } ] }',
parse("").to_ruby)
assert_equal('e(:ul) { [ e(:li) { "abc" }, e(:li) { "efg" }, e(:li) { "xyz" } ] }',
parse("").to_ruby)
assert_equal('[ e(:p) { "a" }, e(:p) { "b" } ]',
parse("a
b").to_ruby)
assert_equal('e(:dl) { [ e(:dt) { "a" }, e(:dd) { "b" }, e(:dd) { "c" } ] }',
parse("
- a
- b
- c").to_ruby)
#assert_equal('[ e(:p) { [ "a", e(:em) { "b" }, "c" ] }, e(:br) , e(:hr) , e(:p) { "x" } ]',
assert_equal('[ e(:p) { [ "a", e(:em) { "b" }, "c", e(:br) ] }, e(:hr) , e(:p) { "x" } ]',
parse("
abc
x").to_ruby)
assert_equal('e(:table) { e(:tr) { e(:td) { e(:p) { "a" } } } }',
parse("
").to_ruby)
assert_equal('e(:table) { e(:tbody) { e(:tr) { e(:td) { e(:p) { "a" } } } } }',
parse("").to_ruby)
template_text = <
title
title
END
assert_equal('[ ' +
'special_tag("!--", " start of template -----------") , "\n", ' +
'e(:html) { [ "\n", e(:head) { [ "\n ", e(:title,a(:id, "title")) { "title" }, "\n" ] }, "\n", ' +
'e(:body) { [ "\n", e(:h1,a(:id, "title")) { "title" }, "\n ", e(:ul) { [ "\n ", e(:li,a(:id, "list")) { " " }, "\n " ] }, "\n" ] }, "\n" ] }, "\n" ]',
parse(template_text).to_ruby)
end
def test_parser_error
assert_exception(HtmlParseError) { parse('') }
assert_exception(HtmlParseError) { parse('') }
assert_exception(HtmlParseError) { parse('')}
assert_exception(HtmlParseError) { parse('- ')}
assert_exception(HtmlParseError) { parse('
aaa
') }
end
def test_expander1
template = "
xx
"
d = { :title => "expand title" }
assert_equal('expand title
',
format_inline(d) { e(:h1, a(:id, "title") { "xx" }) })
assert_equal('expand title
',
format_inline(d) { parse(template) })
s1 = Struct.new("SS", :title)
d = s1.new("struct title")
d.extend ExpandByMember
assert_equal('struct title
',
format_inline(d) { parse(template) })
end
class S1 < Struct.new("S1", :name, :email)
include Amrita::ExpandByMember
end
def test_expander2
template = "xx
zz
"
d = { :title1 => "expand title1" , :title2 => "expand title2"}
assert_equal('expand title1
expand title2
',
format_inline(d) { parse(template) })
d = { :title1 => (e(:em) { "expand title1" } ), :title2 => "expand title2"}
assert_equal('expand title1
expand title2
',
format_inline(d) { parse(template) })
template = ""
d = { :list => [
{ :name => 'aaa', :email => 'aaa@xxx' },
{ :name => 'bbb', :email => 'bbb@xxx' },
{ :name => 'ccc', :email => 'ccc@xxx' },
]
}
assert_equal(
'' +
'- aaa aaa@xxx
' +
'- bbb bbb@xxx
' +
'- ccc ccc@xxx
' +
'
',
format_inline(d) { parse(template) })
# puts gen_html_multi(d) { parse(template) }
# puts format_inline(d) { parse(template) }
d = { :list =>
[
S1.new("aaa","aaa@xxx"),
S1.new("bbb","bbb@xxx"),
S1.new("ccc","ccc@xxx")
]
}
assert_equal(
'' +
'- aaa aaa@xxx
' +
'- bbb bbb@xxx
' +
'- ccc ccc@xxx
' +
'
',
format_inline(d) { parse(template) })
end
def test_expander3
template = ""
template += "- name email
"
#puts parse(template).to_ruby
d = { :list1 =>
[
S1.new("aaa","aaa@xxx"),
S1.new("bbb","bbb@xxx"),
],
:list2 =>
[
S1.new("xxx","xxx@zzz"),
S1.new("yyy","yyy@zzz"),
]
}
assert_equal(
'' +
'- aaa aaa@xxx
' +
'- bbb bbb@xxx
' +
'
' +
'' +
'- xxx xxx@zzz
' +
'- yyy yyy@zzz
' +
'
',
format_inline(d) { parse(template) })
end
def test_prettyprint
s = ""
f = PrettyPrintFormatter.new(s)
f.format(parse(''))
assert_equal("\n\n", s)
s = ""
f = PrettyPrintFormatter.new(s)
f.format(parse("\n\n"))
assert_equal(" \n \n", s)
html = <
walrusのサンプル
END
s = ""
f = PrettyPrintFormatter.new(s)
f.format(parse(html))
result = <
walrusのサンプル
END
assert_equal(result, s)
end
def test_proc
template = HtmlParser.parse_inline <<-END
END
colomun_data = [[ "aa", "bb"], ["cc", "dd"], ["ee", "ff"], ["gg", "hh"]]
data = {
:table1 => proc do |table, context|
h = table.find { |e| e.hid == "header" }
l1 = table.find { |e| e.hid == "line1" }
l2 = table.find { |e| e.hid == "line2" }
l1.delete_attr!(:id)
l2.delete_attr!(:id)
ret = [ h ]
colomun_data.each_with_index do |d, i|
if i%2 == 0
ret << l1.expand({ :col11 => d[0], :col12 => d[1] }, context)
else
ret << l2.expand({ :col21 => d[0], :col22 => d[1] }, context)
end
end
ret
end
}
result = <
| aa |
bb |
| cc |
dd |
| ee |
ff |
| gg |
hh |
END
s = ""
f = PrettyPrintFormatter.new(s)
f.format(template.expand(data))
assert_equal(result, s)
end
def test_dt
template = HtmlParser.parse_inline <<-END
- 1
- 2
- 3
- 4
- 5
- 6
END
assert_equal(" - 1
- 2
- 3
- 4
- 5
- 6
", template.to_s)
end
def test_pre
pre_text = <<-END
1
2
3
4
5
END
template = HtmlParser.parse_text(pre_text)
assert_equal(pre_text.strip, template.to_s.strip)
d = {
:xxx=> CompactSpace.new(false) { "\nabc\nefg\n" }
}
assert_equal('
abc
efg
', template.expand(d).to_s)
assert_equal(pre_text.strip, template.to_s.strip)
end
def test_noescape
template = HtmlParser.parse_inline <<-END
END
d = {
:list => [
"aaaa",
e(:span) { [ "bbbb", e(:br), "cccc" ] },
noescape { "dddd
eeee" }
]
}
assert_equal("",
template.expand(d).to_s.gsub(/\s/, ""))
end
def test_attrarray
template = HtmlParser.parse_inline <<-END
END
d = {
:body=>a(:bgcolor,"blue", :text, "red") {
{
:table=>a(:border, 1) {
{
:list=> [
{ :xxx=>"x1", :yyy=>"y1" },
{ :xxx=>"x2", :yyy=>"y2" },
]
}
}
}
}
}
assert_equal((<