PageRenderTime 145ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/training-web/vendor/bundle/gems/erubis-2.7.0/test/test-erubis.rb

https://bitbucket.org/ohimmelreich/asalia-training
Ruby | 887 lines | 821 code | 35 blank | 31 comment | 31 complexity | 744bd3f45515215e95fb72b2304dd59b MD5 | raw file
  1. ##
  2. ## $Release: 2.7.0 $
  3. ## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
  4. ##
  5. require "#{File.dirname(__FILE__)}/test.rb"
  6. require 'stringio'
  7. require 'erubis'
  8. require 'erubis/engine/enhanced'
  9. require 'erubis/engine/optimized'
  10. require 'erubis/tiny'
  11. class ErubisTest < Test::Unit::TestCase
  12. testdata_list = load_yaml_datafile(__FILE__)
  13. define_testmethods(testdata_list)
  14. def _test()
  15. @src.gsub!(/\^/, ' ')
  16. @output.gsub!(/\^/, ' ') if @output.is_a?(String)
  17. if @class
  18. k = Erubis
  19. @class.split('::').each do |name| k = k.const_get(name) end
  20. @klass = k
  21. else
  22. @klass = Erubis::Eruby
  23. end
  24. @options ||= {}
  25. @chomp.each do |target|
  26. case target
  27. when 'src' ; @src.chomp!
  28. when 'input' ; @input.chomp!
  29. when 'expected' ; @expected.chomp!
  30. else
  31. raise "#{@name}: invalid chomp value: #{@chomp.inspect}"
  32. end
  33. end if @chomp
  34. if @testopt == 'load_file'
  35. filename = "tmp.#{@name}.eruby"
  36. begin
  37. File.open(filename, 'w') { |f| f.write(@input) }
  38. eruby = @klass.load_file(filename, @options)
  39. ensure
  40. cachename = filename + '.cache'
  41. File.unlink(cachename) if test(?f, cachename)
  42. File.unlink(filename) if test(?f, filename)
  43. end
  44. else
  45. if @klass == Erubis::TinyEruby
  46. eruby = @klass.new(@input)
  47. else
  48. eruby = @klass.new(@input, @options)
  49. end
  50. end
  51. assert_text_equal(@src, eruby.src)
  52. return if @testopt == 'skip_output'
  53. list = ['<aaa>', 'b&b', '"ccc"']
  54. context = @testopt == 'context' ? Erubis::Context.new : {}
  55. context[:list] = list
  56. case @testopt
  57. when /\Aeval\(/
  58. eval eruby.src
  59. actual = eval @testopt
  60. assert_text_equal(@output, actual)
  61. when 'stdout', 'print'
  62. begin
  63. orig = $stdout
  64. $stdout = stringio = StringIO.new
  65. #actual = eruby.evaluate(context)
  66. actual = eruby.result(context)
  67. ensure
  68. $stdout = orig
  69. end
  70. if @testopt == 'stdout'
  71. assert_equal("", actual)
  72. else
  73. assert_nil(actual)
  74. end
  75. assert_text_equal(@output, stringio.string)
  76. when 'evaluate', 'context'
  77. actual = eruby.evaluate(context)
  78. assert_text_equal(@output, actual)
  79. when 'binding'
  80. actual = eruby.result(binding())
  81. assert_text_equal(@output, actual)
  82. else
  83. actual = eruby.result(context)
  84. assert_text_equal(@output, actual)
  85. end
  86. end
  87. def test_load_file_cache1
  88. @input = <<END
  89. <ul>
  90. <% for item in @list %>
  91. <li><%= item %></li>
  92. <% end %>
  93. </ul>
  94. END
  95. @src = <<END
  96. _buf = ''; _buf << '<ul>
  97. '; for item in @list
  98. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  99. '; end
  100. _buf << '</ul>
  101. ';
  102. _buf.to_s
  103. END
  104. @klass = Erubis::Eruby
  105. filename = 'tmp.load_file_timestamp1'
  106. cachename = filename + '.cache'
  107. begin
  108. ## when cache doesn't exist then it is created automatically
  109. File.open(filename, 'w') { |f| f.write(@input) }
  110. mtime = Time.now - 2.0
  111. File.utime(mtime, mtime, filename)
  112. !test(?f, cachename) or raise "** failed"
  113. engine = @klass.load_file(filename)
  114. assert_block() { test(?f, cachename) }
  115. assert_block() { File.mtime(filename) <= File.mtime(cachename) }
  116. assert_text_equal(@src, engine.src)
  117. ## when cache has different timestamp then it is recreated
  118. input2 = @input.gsub(/ul>/, 'ol>')
  119. src2 = @src.gsub(/ul>/, 'ol>')
  120. File.open(filename, 'w') { |f| f.write(input2) }
  121. t1 = Time.now()
  122. sleep(1)
  123. t2 = Time.now()
  124. #
  125. File.utime(t1, t1, filename)
  126. File.utime(t2, t2, cachename)
  127. File.mtime(filename) < File.mtime(cachename) or raise "** failed"
  128. engine = @klass.load_file(filename)
  129. assert_block('cache should have same timestamp') { File.mtime(filename) == File.mtime(cachename) }
  130. #assert_text_equal(@src, engine.src)
  131. assert_text_equal(src2, engine.src)
  132. #
  133. File.utime(t2, t2, filename)
  134. File.utime(t1, t1, cachename)
  135. File.mtime(filename) > File.mtime(cachename) or raise "** failed"
  136. engine = @klass.load_file(filename)
  137. assert_block('cache should have same timestamp') { File.mtime(filename) == File.mtime(cachename) }
  138. assert_text_equal(src2, engine.src)
  139. ensure
  140. File.unlink(cachename) if File.file?(cachename)
  141. File.unlink(filename) if File.file?(filename)
  142. end
  143. end
  144. class Dummy
  145. end
  146. def _class_has_instance_method(klass, method)
  147. return klass.instance_methods.collect{|m| m.to_s}.include?(method.to_s)
  148. end
  149. def test_def_method1
  150. s = "<%for i in list%>i=<%=i%>\n<%end%>"
  151. eruby = Erubis::Eruby.new(s)
  152. assert(! _class_has_instance_method(Dummy, 'render'))
  153. eruby.def_method(Dummy, 'render(list)', 'foo.rhtml')
  154. assert(_class_has_instance_method(Dummy, 'render'))
  155. actual = Dummy.new().render(%w[1 2 3])
  156. assert_equal("i=1\ni=2\ni=3\n", actual)
  157. end
  158. def test_def_method2
  159. s = "<%for i in list%>i=<%=i%>\n<%end%>"
  160. eruby = Erubis::Eruby.new(s)
  161. assert(! (eruby.respond_to? :render))
  162. eruby.def_method(eruby, 'render(list)', 'foo.rhtml')
  163. assert eruby.respond_to?(:render)
  164. actual = eruby.render([1, 2, 3])
  165. assert_equal("i=1\ni=2\ni=3\n", actual)
  166. assert(! _class_has_instance_method(eruby.class, 'render'))
  167. end
  168. def test_evaluate_creates_proc
  169. s = "hello <%= @name %>"
  170. eruby = Erubis::Eruby.new(s)
  171. assert_nil(eruby.instance_variable_get('@_proc'))
  172. actual1 = eruby.evaluate(:name=>'world')
  173. assert_not_nil(eruby.instance_variable_get('@_proc'))
  174. assert_instance_of(Proc, eruby.instance_variable_get('@_proc'))
  175. actual2 = eruby.evaluate(:name=>'world')
  176. assert_equal(actual1, actual2)
  177. # convert() must clear @_proc
  178. eruby.convert(s)
  179. assert_nil(eruby.instance_variable_get('@_proc'))
  180. end
  181. #def test_toplevel_binding
  182. # s = "locals = <%= local_variables().inspect %>\n<% x = 50 %>\n"
  183. # eruby = Erubis::Eruby.new(s)
  184. # _x = eval 'x', TOPLEVEL_BINDING
  185. # _y = eval 'y', TOPLEVEL_BINDING
  186. # actual = eruby.evaluate(:x=>_x, :y=>_y)
  187. # _x = eval 'x', TOPLEVEL_BINDING
  188. # _y = eval 'y', TOPLEVEL_BINDING
  189. # puts "*** actual=#{actual.inspect}, x=#{_x.inspect}, y=#{_y.inspect}"
  190. #end
  191. self.post_definition()
  192. end
  193. x = 10
  194. y = 20
  195. __END__
  196. - name: basic1
  197. input: &basic1_input|
  198. <ul>
  199. <% for item in list %>
  200. <li><%= item %></li>
  201. <% end %>
  202. </ul>
  203. src: &basic1_src|
  204. _buf = ''; _buf << '<ul>
  205. '; for item in list
  206. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  207. '; end
  208. _buf << '</ul>
  209. ';
  210. _buf.to_s
  211. output: &basic1_output|
  212. <ul>
  213. <li><aaa></li>
  214. <li>b&b</li>
  215. <li>"ccc"</li>
  216. </ul>
  217. ##
  218. - name: basic2
  219. input: |
  220. <ul>
  221. <% i = 0
  222. for item in list
  223. i += 1
  224. %>
  225. <li><%= item %></li>
  226. <% end %>
  227. </ul>
  228. src: |
  229. _buf = ''; _buf << '<ul>
  230. '; i = 0
  231. for item in list
  232. i += 1
  233. ^^^
  234. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  235. '; end
  236. _buf << '</ul>
  237. ';
  238. _buf.to_s
  239. output: *basic1_output
  240. # <ul>
  241. # <li><aaa></li>
  242. # <li>b&b</li>
  243. # <li>"ccc"</li>
  244. # </ul>
  245. ##
  246. - name: basic3
  247. input: |
  248. <ul><% i = 0
  249. for item in list
  250. i += 1 %><li><%= item %></li><% end %>
  251. </ul>
  252. src: |
  253. _buf = ''; _buf << '<ul>'; i = 0
  254. for item in list
  255. i += 1 ; _buf << '<li>'; _buf << ( item ).to_s; _buf << '</li>'; end ; _buf << '
  256. '; _buf << '</ul>
  257. ';
  258. _buf.to_s
  259. output: |
  260. <ul><li><aaa></li><li>b&b</li><li>"ccc"</li>
  261. </ul>
  262. ##
  263. - name: context1
  264. testopt: context
  265. input: |
  266. <ul>
  267. <% for item in @list %>
  268. <li><%= item %></li>
  269. <% end %>
  270. </ul>
  271. src: |
  272. _buf = ''; _buf << '<ul>
  273. '; for item in @list
  274. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  275. '; end
  276. _buf << '</ul>
  277. ';
  278. _buf.to_s
  279. output: *basic1_output
  280. ##
  281. - name: ignore1
  282. input: |
  283. <ul>
  284. <%# i = 0 %>
  285. <% for item in list %>
  286. <%#
  287. i += 1
  288. color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'
  289. %>
  290. <li> <%#= i %> : <%= item %> </li>
  291. <% end %>
  292. </ul>
  293. src: |
  294. _buf = ''; _buf << '<ul>
  295. ';
  296. for item in list
  297. _buf << ' <li> ';; _buf << ' : '; _buf << ( item ).to_s; _buf << ' </li>
  298. '; end
  299. _buf << '</ul>
  300. ';
  301. _buf.to_s
  302. output: |
  303. <ul>
  304. <li> : <aaa> </li>
  305. <li> : b&b </li>
  306. <li> : "ccc" </li>
  307. </ul>
  308. ##
  309. - name: quotation1
  310. desc: single quotation and backslash
  311. class: Eruby
  312. input: &quotation1_input|
  313. a = "'"
  314. b = "\""
  315. c = '\''
  316. src: |
  317. _buf = ''; _buf << 'a = "\'"
  318. b = "\\""
  319. c = \'\\\'\'
  320. ';
  321. _buf.to_s
  322. output: *quotation1_input
  323. ##
  324. - name: minus1
  325. desc: '<%- -%>'
  326. class: Eruby
  327. input: |
  328. <ul>
  329. <%- for item in list -%>
  330. <li><%= item -%></li>
  331. <% end -%>
  332. </ul>
  333. src: *basic1_src
  334. output: *basic1_output
  335. ##
  336. - name: pattern1
  337. options:
  338. :pattern : '\[@ @\]'
  339. input: |
  340. <ul>
  341. [@ for item in list @]
  342. <li>[@= item @]</li>
  343. [@ end @]
  344. </ul>
  345. src: |
  346. _buf = ''; _buf << '<ul>
  347. '; for item in list
  348. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  349. '; end
  350. _buf << '</ul>
  351. ';
  352. _buf.to_s
  353. output: *basic1_output
  354. # <ul>
  355. # <li><aaa></li>
  356. # <li>b&b</li>
  357. # <li>"ccc"</li>
  358. # </ul>
  359. ##
  360. - name: pattern2
  361. options:
  362. :pattern : '<(?:!--)?% %(?:--)?>'
  363. input: |
  364. <ul>
  365. <!--% for item in list %-->
  366. <li><%= item %></li>
  367. <!--% end %-->
  368. </ul>
  369. src: |
  370. _buf = ''; _buf << '<ul>
  371. '; for item in list
  372. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  373. '; end
  374. _buf << '</ul>
  375. ';
  376. _buf.to_s
  377. output: *basic1_output
  378. # <ul>
  379. # <li><aaa></li>
  380. # <li>b&b</li>
  381. # <li>"ccc"</li>
  382. # </ul>
  383. ##
  384. - name: trim1
  385. options:
  386. :trim : false
  387. input: *basic1_input
  388. # <ul>
  389. # <% for item in list %>
  390. # <li><%= item %></li>
  391. # <% end %>
  392. # </ul>
  393. src: |
  394. _buf = ''; _buf << '<ul>
  395. '; _buf << ' '; for item in list ; _buf << '
  396. '; _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  397. '; _buf << ' '; end ; _buf << '
  398. '; _buf << '</ul>
  399. ';
  400. _buf.to_s
  401. output: |
  402. <ul>
  403. ^
  404. <li><aaa></li>
  405. ^
  406. <li>b&b</li>
  407. ^
  408. <li>"ccc"</li>
  409. ^
  410. </ul>
  411. ##
  412. - name: bodyonly1
  413. testopt: skip_output
  414. options: { :preamble: no, :postamble: no }
  415. input: *basic1_input
  416. src: |4
  417. _buf << '<ul>
  418. '; for item in list
  419. _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
  420. '; end
  421. _buf << '</ul>
  422. ';
  423. chomp: [src]
  424. expected: null
  425. ##
  426. - name: loadfile1
  427. testopt: load_file
  428. #input: |
  429. # <ul>
  430. # <% for item in list %>
  431. # <li><%= item %></li>
  432. # <% end %>
  433. # </ul>
  434. input:
  435. "<ul>\r\n <% for item in list %>\r\n <li><%= item %></li>\r\n <% end %>\r\n</ul>\r\n"
  436. #src: |
  437. # _buf = ''; _buf << "<ul>\n"
  438. # for item in list
  439. # _buf << " <li>"; _buf << ( item ).to_s; _buf << "</li>\n"
  440. # end
  441. # _buf << "</ul>\n"
  442. # _buf
  443. src:
  444. "_buf = ''; _buf << '<ul>\r\n'; for item in list \r\n _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>\r\n'; end \r\n _buf << '</ul>\r\n';\n_buf.to_s\n"
  445. #output: |
  446. # <ul>
  447. # <li><aaa></li>
  448. # <li>b&b</li>
  449. # <li>"ccc"</li>
  450. # </ul>
  451. output:
  452. "<ul>\n <li><aaa></li>\n <li>b&b</li>\n <li>\"ccc\"</li>\n</ul>\n"
  453. # "<ul>\r\n <li><aaa></li>\r\n <li>b&b</li>\r\n <li>\"ccc\"</li>\r\n</ul>\r\n"
  454. ##
  455. - name: nomatch1
  456. desc: bug
  457. input: &nomatch1|
  458. <ul>
  459. <li>foo</li>
  460. </ul>
  461. src: |
  462. _buf = ''; _buf << '<ul>
  463. <li>foo</li>
  464. </ul>
  465. ';
  466. _buf.to_s
  467. output: *nomatch1
  468. ##
  469. - name: escape1
  470. options: { :escape: true }
  471. input: |
  472. <% str = '<>&"' %>
  473. <%= str %>
  474. <%== str %>
  475. src: |
  476. _buf = ''; str = '<>&"'
  477. _buf << Erubis::XmlHelper.escape_xml( str ); _buf << '
  478. '; _buf << ( str ).to_s; _buf << '
  479. ';
  480. _buf.to_s
  481. output: |
  482. &lt;&gt;&amp;&quot;
  483. <>&"
  484. ##
  485. - name: tailch1
  486. options:
  487. input: |
  488. <p>
  489. <% str = '<>&"' %>
  490. <%= str %>
  491. <%= str =%>
  492. <%= str -%>
  493. </p>
  494. src: |
  495. _buf = ''; _buf << '<p>
  496. '; str = '<>&"'
  497. _buf << ' '; _buf << ( str ).to_s; _buf << '
  498. '; _buf << ' '; _buf << ( str ).to_s; _buf << ' '; _buf << ( str ).to_s; _buf << '</p>
  499. ';
  500. _buf.to_s
  501. output: |
  502. <p>
  503. <>&"
  504. <>&" <>&"</p>
  505. ##
  506. - name: doublepercent1
  507. options:
  508. input: |
  509. <% x1 = 10 %>
  510. <%% x2 = 20 %>
  511. <%= x1 %>
  512. <%%= x2 %>
  513. src: |
  514. _buf = ''; x1 = 10
  515. _buf << '<% x2 = 20 %>
  516. '; _buf << ( x1 ).to_s; _buf << '
  517. '; _buf << '<%= x2 %>
  518. ';
  519. _buf.to_s
  520. output: |
  521. <% x2 = 20 %>
  522. 10
  523. <%= x2 %>
  524. ##
  525. - name: optimized1
  526. class: OptimizedEruby
  527. input: &optimized1_input|
  528. <table>
  529. <% for item in list %>
  530. <tr>
  531. <td><%= item %></td>
  532. <td><%== item %></td>
  533. </tr>
  534. <% end %>
  535. </table>
  536. <ul><% for item in list %><li><%= item %></li><% end %></ul>
  537. src: |
  538. _buf = '<table>
  539. '; for item in list
  540. _buf << ' <tr>
  541. <td>' << ( item ).to_s << '</td>
  542. <td>' << Erubis::XmlHelper.escape_xml( item ) << '</td>
  543. </tr>
  544. '; end
  545. _buf << '</table>
  546. <ul>'; for item in list ; _buf << '<li>' << ( item ).to_s << '</li>'; end ; _buf << '</ul>
  547. '
  548. _buf
  549. output: |
  550. <table>
  551. <tr>
  552. <td><aaa></td>
  553. <td>&lt;aaa&gt;</td>
  554. </tr>
  555. <tr>
  556. <td>b&b</td>
  557. <td>b&amp;b</td>
  558. </tr>
  559. <tr>
  560. <td>"ccc"</td>
  561. <td>&quot;ccc&quot;</td>
  562. </tr>
  563. </table>
  564. <ul><li><aaa></li><li>b&b</li><li>"ccc"</li></ul>
  565. ##
  566. - name: optimized2
  567. class: OptimizedXmlEruby
  568. input: *optimized1_input
  569. # <table>
  570. # <% for item in list %>
  571. # <tr>
  572. # <td><%= item %></td>
  573. # <td><%== item %></td>
  574. # </tr>
  575. # <% end %>
  576. # </table>
  577. # <ul><% for item in list %><li><%= item %></li><% end %></ul>
  578. src: |
  579. _buf = '<table>
  580. '; for item in list
  581. _buf << ' <tr>
  582. <td>' << Erubis::XmlHelper.escape_xml( item ) << '</td>
  583. <td>' << ( item ).to_s << '</td>
  584. </tr>
  585. '; end
  586. _buf << '</table>
  587. <ul>'; for item in list ; _buf << '<li>' << Erubis::XmlHelper.escape_xml( item ) << '</li>'; end ; _buf << '</ul>
  588. '
  589. _buf
  590. output: |
  591. <table>
  592. <tr>
  593. <td>&lt;aaa&gt;</td>
  594. <td><aaa></td>
  595. </tr>
  596. <tr>
  597. <td>b&amp;b</td>
  598. <td>b&b</td>
  599. </tr>
  600. <tr>
  601. <td>&quot;ccc&quot;</td>
  602. <td>"ccc"</td>
  603. </tr>
  604. </table>
  605. <ul><li>&lt;aaa&gt;</li><li>b&amp;b</li><li>&quot;ccc&quot;</li></ul>
  606. ##
  607. - name: optimized3
  608. desc: bug
  609. class: OptimizedEruby
  610. input: |
  611. user = <%= "Foo" %>
  612. <% for item in list %>
  613. <%= item %>
  614. <% end %>
  615. src: |
  616. _buf = 'user = '; _buf << ( "Foo" ).to_s << '
  617. '; for item in list
  618. _buf << ' ' << ( item ).to_s << '
  619. '; end
  620. _buf
  621. output: |
  622. user = Foo
  623. <aaa>
  624. b&b
  625. "ccc"
  626. ##
  627. - name: optimized4
  628. desc: single quotation and backslash
  629. class: OptimizedEruby
  630. input: &optimized4_input|
  631. a = "'"
  632. b = "\""
  633. c = '\''
  634. src: |
  635. _buf = 'a = "\'"
  636. b = "\\""
  637. c = \'\\\'\'
  638. ';
  639. _buf
  640. output: *optimized4_input
  641. ##
  642. - name: tiny1
  643. class: TinyEruby
  644. testopt: binding
  645. input: |
  646. <ul>
  647. <% for item in list %>
  648. <li><%= item %></li>
  649. <% end %>
  650. </ul>
  651. src: |
  652. _buf = ''; _buf << '<ul>
  653. '; for item in list ; _buf << '
  654. <li>'; _buf << ( item ).to_s; _buf << '</li>
  655. '; end ; _buf << '
  656. </ul>
  657. ';
  658. _buf.to_s
  659. output: |
  660. <ul>
  661. ^
  662. <li><aaa></li>
  663. ^
  664. <li>b&b</li>
  665. ^
  666. <li>"ccc"</li>
  667. ^
  668. </ul>
  669. ##
  670. - name: tiny2
  671. class: TinyEruby
  672. testopt: evaluate
  673. input: |
  674. <ul>
  675. <% for item in @list %>
  676. <li><%= item %></li>
  677. <% end %>
  678. </ul>
  679. src: |
  680. _buf = ''; _buf << '<ul>
  681. '; for item in @list ; _buf << '
  682. <li>'; _buf << ( item ).to_s; _buf << '</li>
  683. '; end ; _buf << '
  684. </ul>
  685. ';
  686. _buf.to_s
  687. output: |
  688. <ul>
  689. ^
  690. <li><aaa></li>
  691. ^
  692. <li>b&b</li>
  693. ^
  694. <li>"ccc"</li>
  695. ^
  696. </ul>
  697. ##
  698. - name: pi1
  699. class: PI::Eruby
  700. testopt: evaluate
  701. input: &input_pi1|
  702. <ul>
  703. <?rb for item in @list ?>
  704. <li>@{item}@ / @!{item}@</li>
  705. <li><%= item %> / <%== item %></li>
  706. <?rb end ?>
  707. </ul>
  708. src: &src_pi1|
  709. _buf = ''; _buf << '<ul>
  710. '; for item in @list
  711. _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' / '; _buf << (item).to_s; _buf << '</li>
  712. <li>'; _buf << ( item ).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</li>
  713. '; end
  714. _buf << '</ul>
  715. ';
  716. _buf.to_s
  717. output: &output_pi1|
  718. <ul>
  719. <li>&lt;aaa&gt; / <aaa></li>
  720. <li><aaa> / &lt;aaa&gt;</li>
  721. <li>b&amp;b / b&b</li>
  722. <li>b&b / b&amp;b</li>
  723. <li>&quot;ccc&quot; / "ccc"</li>
  724. <li>"ccc" / &quot;ccc&quot;</li>
  725. </ul>
  726. ##
  727. - name: pi2
  728. class: PI::Eruby
  729. options: { :escape: false }
  730. testopt: evaluate
  731. input: *input_pi1
  732. src: |
  733. _buf = ''; _buf << '<ul>
  734. '; for item in @list
  735. _buf << ' <li>'; _buf << (item).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
  736. <li>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' / '; _buf << ( item ).to_s; _buf << '</li>
  737. '; end
  738. _buf << '</ul>
  739. ';
  740. _buf.to_s
  741. output: |
  742. <ul>
  743. <li><aaa> / &lt;aaa&gt;</li>
  744. <li>&lt;aaa&gt; / <aaa></li>
  745. <li>b&b / b&amp;b</li>
  746. <li>b&amp;b / b&b</li>
  747. <li>"ccc" / &quot;ccc&quot;</li>
  748. <li>&quot;ccc&quot; / "ccc"</li>
  749. </ul>
  750. ##
  751. - name: pi3
  752. class: PI::Eruby
  753. options: { :pi: hoge, :embchar: '$' }
  754. testopt: evaluate
  755. input: |
  756. <ul>
  757. <?hoge for item in @list ?>
  758. <li>${item}$ / $!{item}$</li>
  759. <li><%= item %> / <%== item %></li>
  760. <?hoge end ?>
  761. </ul>
  762. src: *src_pi1
  763. output: *output_pi1
  764. - name: pi4
  765. class: PI::Eruby
  766. testopt: evaluate
  767. input: |
  768. <?rb-header
  769. def show(list)
  770. ?>
  771. <ul>
  772. <?rb for item in list ?>
  773. <?rb-value item ?>
  774. <?rb end ?>
  775. <?rb-comment
  776. # comment
  777. # comment
  778. ?>
  779. </ul>
  780. <?rb-footer
  781. end
  782. show(@list) ?>
  783. src: |4
  784. def show(list)
  785. _buf = ''; _buf << '<ul>
  786. '; for item in list
  787. _buf << ( item
  788. ).to_s; end
  789. _buf << '</ul>
  790. ';
  791. _buf.to_s
  792. end
  793. show(@list)
  794. output: |
  795. <ul>
  796. <aaa>b&b"ccc"</ul>
  797. - name: pitiny1
  798. class: PI::TinyEruby
  799. testopt: evaluate
  800. input: |
  801. <ul>
  802. <?rb for item in @list ?>
  803. <li>@{item}@ / @!{item}@</li>
  804. <?rb end ?>
  805. </ul>
  806. src: |
  807. _buf = ''; _buf << '<ul>
  808. '; for item in @list
  809. _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' / '; _buf << (item).to_s; _buf << '</li>
  810. '; end
  811. _buf << '</ul>
  812. ';
  813. _buf.to_s
  814. output: |
  815. <ul>
  816. <li>&lt;aaa&gt; / <aaa></li>
  817. <li>b&amp;b / b&b</li>
  818. <li>&quot;ccc&quot; / "ccc"</li>
  819. </ul>