tenjin 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/CHANGES.txt +163 -0
  2. data/MIT-LICENSE +16 -17
  3. data/README.txt +5 -5
  4. data/benchmark/Makefile +9 -0
  5. data/benchmark/bench.rb +3 -2
  6. data/bin/rbtenjin +6 -3
  7. data/doc/docstyle.css +25 -4
  8. data/doc/users-guide.html +2088 -1563
  9. data/lib/tenjin.rb +784 -158
  10. data/public_html/_layout.rbhtml +33 -0
  11. data/public_html/css/style.css +77 -0
  12. data/public_html/env.rbhtml +15 -0
  13. data/public_html/favicon.ico +0 -0
  14. data/public_html/hello.rbhtml +14 -0
  15. data/public_html/index.rbhtml +39 -0
  16. data/public_html/rbtenjin.cgi +188 -0
  17. data/tenjin.gemspec +9 -6
  18. data/test/data/examples/preprocessing/main.rb +1 -1
  19. data/test/data/examples/preprocessing/select.rbhtml +1 -1
  20. data/test/data/faq/{ex11-bench.rb → ex10-bench.rb} +3 -3
  21. data/test/data/faq/ex10-content.rbhtml +8 -11
  22. data/test/data/faq/{ex11-layout1.rbhtml → ex10-layout1.rbhtml} +0 -0
  23. data/test/data/faq/{ex11-layout2.rbhtml → ex10-layout2.rbhtml} +0 -0
  24. data/test/data/faq/{ex11.rb → ex10.rb} +1 -1
  25. data/test/data/faq/{ex11.rbhtml → ex10.rbhtml} +0 -0
  26. data/test/data/faq/{ex11.source → ex10.source} +2 -2
  27. data/test/data/faq/{ex11_arraybuffer.result → ex10_arraybuffer.result} +1 -1
  28. data/test/data/faq/{ex5.rbhtml → ex2.rbhtml} +0 -0
  29. data/test/data/faq/{ex5_template_args.source → ex2_template_args.source} +1 -1
  30. data/test/data/faq/{ex7-expr-pattern.rb → ex4-expr-pattern.rb} +1 -1
  31. data/test/data/faq/{ex7-expr-pattern.rbhtml → ex4-expr-pattern.rbhtml} +0 -0
  32. data/test/data/faq/{ex7_expr_pattern.result → ex4_expr_pattern.result} +1 -1
  33. data/test/data/faq/{ex6-content.rhtml → ex5-content.rhtml} +0 -0
  34. data/test/data/faq/{ex6-layout.rhtml → ex5-layout.rhtml} +0 -0
  35. data/test/data/faq/{ex6.rb → ex5.rb} +2 -2
  36. data/test/data/faq/{ex6_eruby.result → ex5_eruby.result} +1 -1
  37. data/test/data/faq/{ex2-content.rbhtml → ex6-content.rbhtml} +0 -0
  38. data/test/data/faq/{ex2-layout.rbhtml → ex6-layout.rbhtml} +0 -0
  39. data/test/data/faq/{ex2_removenl.result → ex6_removenl.result} +1 -1
  40. data/test/data/faq/ex7-m18n.rb +48 -0
  41. data/test/data/faq/{ex8-m18n.rbhtml → ex7-m18n.rbhtml} +0 -0
  42. data/test/data/faq/{ex8_m18n.result → ex7_m18n.result} +1 -1
  43. data/test/data/faq/ex8-baselayout.rbhtml +8 -0
  44. data/test/data/faq/ex8-content.rbhtml +6 -0
  45. data/test/data/faq/{ex9-mylayout.rbhtml → ex8-mylayout.rbhtml} +0 -0
  46. data/test/data/faq/{ex9_changelayout.result → ex8_changelayout.result} +1 -1
  47. data/test/data/faq/ex9-baselayout.rbhtml +24 -5
  48. data/test/data/faq/ex9-content.rbhtml +12 -6
  49. data/test/data/faq/{ex10-customlayout.rbhtml → ex9-customlayout.rbhtml} +1 -1
  50. data/test/data/faq/{ex10_inherit.result → ex9_inherit.result} +1 -1
  51. data/test/data/faq/helpers1.rb +17 -0
  52. data/test/data/faq/helpers1.rbhtml +4 -0
  53. data/test/data/faq/helpers1.result +11 -0
  54. data/test/data/faq/helpers2.rb +21 -0
  55. data/test/data/faq/helpers2.rbhtml +4 -0
  56. data/test/data/faq/helpers2.result +11 -0
  57. data/test/data/faq/weekday1.rb +6 -0
  58. data/test/data/faq/weekday1.rbhtml +9 -0
  59. data/test/data/faq/weekday1.result +23 -0
  60. data/test/data/faq/weekday2.rb +8 -0
  61. data/test/data/faq/weekday2.rbhtml +10 -0
  62. data/test/data/faq/weekday2.result +24 -0
  63. data/test/data/faq/weekday3.rb +22 -0
  64. data/test/data/faq/weekday3.rbhtml +3 -0
  65. data/test/data/faq/weekday3.result +28 -0
  66. data/test/data/users_guide/test_010/main.rb +14 -0
  67. data/test/data/users_guide/test_010/result.output +13 -0
  68. data/test/data/users_guide/test_010/views/page.rbhtml +11 -0
  69. data/test/data/users_guide/test_011/main.rb +14 -0
  70. data/test/data/users_guide/test_011/result.output +2 -0
  71. data/test/data/users_guide/test_011/views/page.rbhtml +11 -0
  72. data/test/data/users_guide/test_020/main.rb +14 -0
  73. data/test/data/users_guide/test_020/result.output +13 -0
  74. data/test/data/users_guide/test_020/views/page.rbhtml +11 -0
  75. data/test/data/users_guide/test_021/main.rb +12 -0
  76. data/test/data/users_guide/test_021/result.output +12 -0
  77. data/test/data/users_guide/test_021/views/page.rbhtml +11 -0
  78. data/test/data/users_guide/test_030/main.rb +14 -0
  79. data/test/data/users_guide/test_030/result.output +23 -0
  80. data/test/data/users_guide/test_030/views/_layout.rbhtml +10 -0
  81. data/test/data/users_guide/test_030/views/page.rbhtml +11 -0
  82. data/test/data/users_guide/test_040/main.rb +14 -0
  83. data/test/data/users_guide/test_040/result.output +23 -0
  84. data/test/data/users_guide/test_040/views/_layout.rbhtml +10 -0
  85. data/test/data/users_guide/test_040/views/page.rbhtml +12 -0
  86. data/test/data/users_guide/test_050/main.rb +14 -0
  87. data/test/data/users_guide/test_050/result.output +14 -0
  88. data/test/data/users_guide/test_050/views/_layout.rbhtml +10 -0
  89. data/test/data/users_guide/test_050/views/page.rbhtml +13 -0
  90. data/test/data/users_guide/test_051/main.rb +14 -0
  91. data/test/data/users_guide/test_051/result.output +12 -0
  92. data/test/data/users_guide/test_051/views/_layout.rbhtml +11 -0
  93. data/test/data/users_guide/test_051/views/page.rbhtml +13 -0
  94. data/test/data/users_guide/test_060/main.rb +14 -0
  95. data/test/data/users_guide/test_060/result.output +29 -0
  96. data/test/data/users_guide/test_060/views/_footer.rbhtml +3 -0
  97. data/test/data/users_guide/test_060/views/_header.rbhtml +3 -0
  98. data/test/data/users_guide/test_060/views/_layout.rbhtml +13 -0
  99. data/test/data/users_guide/test_060/views/page.rbhtml +13 -0
  100. data/test/data/users_guide/test_070/main.rb +14 -0
  101. data/test/data/users_guide/test_070/result.output +29 -0
  102. data/test/data/users_guide/test_070/views/_footer.rbhtml +3 -0
  103. data/test/data/users_guide/test_070/views/_header.rbhtml +3 -0
  104. data/test/data/users_guide/test_070/views/_layout.rbhtml +13 -0
  105. data/test/data/users_guide/test_070/views/page.rbhtml +13 -0
  106. data/test/data/users_guide/test_capturing/main.rb +24 -0
  107. data/test/data/users_guide/test_capturing/result.output +28 -0
  108. data/test/data/users_guide/test_capturing/views/_layout.rbhtml +21 -0
  109. data/test/data/users_guide/test_capturing/views/blog-post.rbhtml +13 -0
  110. data/test/data/users_guide/test_context/context.rb +5 -0
  111. data/test/data/users_guide/test_context/context.yaml +4 -0
  112. data/test/data/users_guide/test_context/example.rbhtml +5 -0
  113. data/test/data/users_guide/test_context/result1.output +6 -0
  114. data/test/data/users_guide/test_context/result2.output +6 -0
  115. data/test/data/users_guide/test_context/result3.output +6 -0
  116. data/test/data/users_guide/test_context/result4.output +6 -0
  117. data/test/data/users_guide/test_convert/example.rbhtml +5 -0
  118. data/test/data/users_guide/test_convert/result1.output +7 -0
  119. data/test/data/users_guide/test_convert/result2.output +6 -0
  120. data/test/data/users_guide/test_escape/main.rb +4 -0
  121. data/test/data/users_guide/test_escape/result.output +5 -0
  122. data/test/data/users_guide/test_escape/views/page.rbhtml +4 -0
  123. data/test/data/users_guide/test_execute/example.rbhtml +6 -0
  124. data/test/data/users_guide/test_execute/result.output +6 -0
  125. data/test/data/users_guide/test_fragmentcache/cache.d/items/1 +5 -0
  126. data/test/data/users_guide/test_fragmentcache/main.rb +21 -0
  127. data/test/data/users_guide/test_fragmentcache/result.output +8 -0
  128. data/test/data/users_guide/test_fragmentcache/result2.output +6 -0
  129. data/test/data/users_guide/test_fragmentcache/views/items.rbhtml +10 -0
  130. data/test/data/users_guide/test_logging/ex-logger.rb +11 -0
  131. data/test/data/users_guide/test_logging/example.rbhtml +0 -0
  132. data/test/data/users_guide/test_logging/result1.output +3 -0
  133. data/test/data/users_guide/test_logging/result2.output +2 -0
  134. data/test/data/users_guide/test_m17n/m17n.rb +44 -0
  135. data/test/data/users_guide/test_m17n/m17n.rbhtml +5 -0
  136. data/test/data/users_guide/test_m17n/result.output +9 -0
  137. data/test/data/users_guide/test_m17n/result_en.output +4 -0
  138. data/test/data/users_guide/test_m17n/result_fr.output +4 -0
  139. data/test/data/users_guide/test_nested/main.rb +8 -0
  140. data/test/data/users_guide/test_nested/result.output +15 -0
  141. data/test/data/users_guide/test_nested/views/_blog_layout.rbhtml +5 -0
  142. data/test/data/users_guide/{layout8_html.rbhtml → test_nested/views/_site_layout.rbhtml} +0 -0
  143. data/test/data/users_guide/test_nested/views/blog_post.rbhtml +4 -0
  144. data/test/data/users_guide/test_preprocessing/pp-example1.rb +14 -0
  145. data/test/data/users_guide/test_preprocessing/result1a.output +11 -0
  146. data/test/data/users_guide/test_preprocessing/result1b.output +5 -0
  147. data/test/data/users_guide/test_preprocessing/result1c.output +6 -0
  148. data/test/data/users_guide/test_preprocessing/result2a.output +10 -0
  149. data/test/data/users_guide/test_preprocessing/result2b.output +10 -0
  150. data/test/data/users_guide/test_preprocessing/result3a.output +2 -0
  151. data/test/data/users_guide/test_preprocessing/result3b.output +2 -0
  152. data/test/data/users_guide/test_preprocessing/views/pp-example1.rbhtml +4 -0
  153. data/test/data/users_guide/{example12.rbhtml → test_preprocessing/views/pp-example2.rbhtml} +4 -4
  154. data/test/data/users_guide/test_preprocessing/views/pp-example3.rbhtml +7 -0
  155. data/test/data/users_guide/test_retrieve/example.rbhtml +10 -0
  156. data/test/data/users_guide/test_retrieve/result1.output +11 -0
  157. data/test/data/users_guide/test_retrieve/result2.output +11 -0
  158. data/test/data/users_guide/test_retrieve/result3.output +11 -0
  159. data/test/data/users_guide/test_retrieve/result4.output +8 -0
  160. data/test/data/users_guide/test_retrieve/result5.output +5 -0
  161. data/test/data/users_guide/test_safe/result.output +6 -0
  162. data/test/data/users_guide/test_safe/safe-test.rb +21 -0
  163. data/test/data/users_guide/test_safehelper/main.rb +16 -0
  164. data/test/data/users_guide/test_safehelper/result.output +8 -0
  165. data/test/data/users_guide/{example3.rbhtml → test_syntax_check/example.rbhtml} +0 -0
  166. data/test/data/users_guide/test_syntax_check/result.output +2 -0
  167. data/test/data/users_guide/test_trace/layout.rbhtml +7 -0
  168. data/test/data/users_guide/test_trace/main.rbhtml +5 -0
  169. data/test/data/users_guide/test_trace/result.output +16 -0
  170. data/test/data/users_guide/test_trace/trace-example.rb +4 -0
  171. data/test/oktest.rb +755 -0
  172. data/test/test_all.rb +24 -14
  173. data/test/test_engine.rb +628 -63
  174. data/test/test_engine.yaml +40 -3
  175. data/test/test_examples.rb +14 -12
  176. data/test/test_faq.rb +17 -12
  177. data/test/test_htmlhelper.rb +104 -33
  178. data/test/test_main.rb +32 -21
  179. data/test/test_main.yaml +2 -2
  180. data/test/test_safe.rb +206 -0
  181. data/test/test_store.rb +220 -0
  182. data/test/test_tcache.rb +94 -0
  183. data/test/test_template.rb +65 -23
  184. data/test/test_template.yaml +7 -7
  185. data/test/test_users_guide.rb +75 -29
  186. data/test/testcase-helper.rb +20 -18
  187. data/test/testunit-assertions.rb +71 -0
  188. metadata +185 -159
  189. data/doc-api/classes/Tenjin.html +0 -141
  190. data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +0 -270
  191. data/doc-api/classes/Tenjin/BaseContext.html +0 -329
  192. data/doc-api/classes/Tenjin/Context.html +0 -126
  193. data/doc-api/classes/Tenjin/ContextHelper.html +0 -461
  194. data/doc-api/classes/Tenjin/Engine.html +0 -616
  195. data/doc-api/classes/Tenjin/ErubisTemplate.html +0 -166
  196. data/doc-api/classes/Tenjin/HtmlHelper.html +0 -359
  197. data/doc-api/classes/Tenjin/Preprocessor.html +0 -242
  198. data/doc-api/classes/Tenjin/Template.html +0 -916
  199. data/doc-api/created.rid +0 -1
  200. data/doc-api/files/README_txt.html +0 -188
  201. data/doc-api/files/lib/tenjin_rb.html +0 -136
  202. data/doc-api/fr_class_index.html +0 -36
  203. data/doc-api/fr_file_index.html +0 -28
  204. data/doc-api/fr_method_index.html +0 -91
  205. data/doc-api/index.html +0 -24
  206. data/doc-api/rdoc-style.css +0 -208
  207. data/doc/examples.html +0 -312
  208. data/doc/faq.html +0 -909
  209. data/examples/preprocessing/select.rbhtml.cache +0 -17
  210. data/test/Rookbook.yaml +0 -14
  211. data/test/assert-text-equal.rb +0 -45
  212. data/test/data/faq/ex10-baselayout.rbhtml +0 -27
  213. data/test/data/faq/ex11-content.rbhtml +0 -9
  214. data/test/data/faq/ex8-m18n.rb +0 -77
  215. data/test/data/users_guide/content6.rbhtml +0 -3
  216. data/test/data/users_guide/content7.rbhtml +0 -5
  217. data/test/data/users_guide/content8.rbhtml +0 -2
  218. data/test/data/users_guide/contextdata.rb +0 -7
  219. data/test/data/users_guide/datafile.rb +0 -5
  220. data/test/data/users_guide/datafile.yaml +0 -10
  221. data/test/data/users_guide/ex.rbhtml +0 -6
  222. data/test/data/users_guide/ex.result +0 -7
  223. data/test/data/users_guide/ex.script +0 -5
  224. data/test/data/users_guide/ex_script.result +0 -7
  225. data/test/data/users_guide/ex_source.result +0 -8
  226. data/test/data/users_guide/example1.rbhtml +0 -12
  227. data/test/data/users_guide/example1.result +0 -17
  228. data/test/data/users_guide/example10.rbhtml +0 -4
  229. data/test/data/users_guide/example10_template_args.result +0 -6
  230. data/test/data/users_guide/example11.rbhtml +0 -5
  231. data/test/data/users_guide/example11_template_args_result +0 -2
  232. data/test/data/users_guide/example12_preprocessed.result +0 -10
  233. data/test/data/users_guide/example12_preprocessed_source.result +0 -10
  234. data/test/data/users_guide/example13.rbhtml +0 -6
  235. data/test/data/users_guide/example13_preprocessed.result +0 -2
  236. data/test/data/users_guide/example13_preprocessed_source.result +0 -2
  237. data/test/data/users_guide/example14.rb +0 -32
  238. data/test/data/users_guide/example14.rbhtml +0 -6
  239. data/test/data/users_guide/example14_tmplclass.result +0 -15
  240. data/test/data/users_guide/example15.rb +0 -10
  241. data/test/data/users_guide/example15_escapefunc.result +0 -14
  242. data/test/data/users_guide/example16.rbhtml +0 -4
  243. data/test/data/users_guide/example16a.rb +0 -10
  244. data/test/data/users_guide/example16a.result +0 -4
  245. data/test/data/users_guide/example16b.rb +0 -13
  246. data/test/data/users_guide/example16b.result +0 -4
  247. data/test/data/users_guide/example16c.rb +0 -12
  248. data/test/data/users_guide/example16c.result +0 -4
  249. data/test/data/users_guide/example16d.rb +0 -27
  250. data/test/data/users_guide/example16d.result +0 -4
  251. data/test/data/users_guide/example1_S.result +0 -14
  252. data/test/data/users_guide/example1_SXNC.result +0 -10
  253. data/test/data/users_guide/example1_source.result +0 -14
  254. data/test/data/users_guide/example2.rbhtml +0 -3
  255. data/test/data/users_guide/example2_sb.result2 +0 -9
  256. data/test/data/users_guide/example3_syntaxcheck.result +0 -2
  257. data/test/data/users_guide/example4.rbhtml +0 -13
  258. data/test/data/users_guide/example4_datafile_rb.result +0 -13
  259. data/test/data/users_guide/example4_yaml.result +0 -13
  260. data/test/data/users_guide/example5.rbhtml +0 -9
  261. data/test/data/users_guide/example5_datastr_rb.result +0 -9
  262. data/test/data/users_guide/example5_datastr_yaml.result +0 -9
  263. data/test/data/users_guide/example6.rbhtml +0 -19
  264. data/test/data/users_guide/example6_layout.result +0 -29
  265. data/test/data/users_guide/example6_nested.result +0 -28
  266. data/test/data/users_guide/example7_layout2.result +0 -13
  267. data/test/data/users_guide/example8_layout3.result +0 -8
  268. data/test/data/users_guide/example9.rbhtml +0 -18
  269. data/test/data/users_guide/example9_capture.result +0 -26
  270. data/test/data/users_guide/footer.html +0 -5
  271. data/test/data/users_guide/footer.rbhtml +0 -4
  272. data/test/data/users_guide/layout6.rbhtml +0 -17
  273. data/test/data/users_guide/layout7.rbhtml +0 -9
  274. data/test/data/users_guide/layout8_xhtml.rbhtml +0 -6
  275. data/test/data/users_guide/layout9.rbhtml +0 -25
  276. data/test/data/users_guide/sidemenu.rbhtml +0 -5
  277. data/test/data/users_guide/user_app.cgi +0 -39
  278. data/test/data/users_guide/user_app.result +0 -30
  279. data/test/data/users_guide/user_create.rbhtml +0 -6
  280. data/test/data/users_guide/user_edit.rbhtml +0 -7
  281. data/test/data/users_guide/user_form.rbhtml +0 -10
  282. data/test/data/users_guide/user_layout.rbhtml +0 -16
@@ -1,17 +1,14 @@
1
1
  ###
2
- ### $Rev: 71 $
3
- ### $Release: 0.6.2 $
4
- ### copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
2
+ ### $Rev$
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
7
- require 'test/unit'
8
- #require 'testutil'
9
- require 'testcase-helper'
10
- require 'assert-text-equal'
7
+ require "#{File.dirname(File.expand_path(__FILE__))}/test_all"
11
8
 
12
- require 'tenjin'
13
9
 
14
- class TenjinTemplateTest < Test::Unit::TestCase
10
+ class TenjinTemplateTest
11
+ include Oktest::TestCase
15
12
 
16
13
  filename = __FILE__.sub(/\.\w+$/, '.yaml')
17
14
  #load_yaml_testdata(filename)
@@ -67,28 +64,30 @@ class TenjinTemplateTest < Test::Unit::TestCase
67
64
  if @exception.is_a?(String)
68
65
  @exception = @exception.split('::').inject(Object) {|klass, s| klass = klass.const_get(s) }
69
66
  end
70
- ex = assert_raise(@exception) do
71
- template = @templateclass.new(@options)
72
- template.convert(@input, @filename)
73
- template.render(@context)
74
- end
75
- #assert_equal(@exception, ex.class.name)
67
+ ex = ok_(proc {
68
+ template = @templateclass.new(@options)
69
+ template.convert(@input, @filename)
70
+ template.render(@context)
71
+ }).raise?(@exception)
72
+ #ok_(ex.class.name) == @exception
76
73
  if @errormsg
77
74
  errmsg = ex.to_s.sub(/:0x[0-9a-fA-F]+/, ':0x12345')
78
75
  if defined?(RBX_VERSION)
79
- assert_equal(@errormsg, errmsg[0, @errormsg.length-1] + '>')
76
+ ok_(errmsg[0, @errormsg.length-1] + '>') == @errormsg
80
77
  else
81
- assert_equal(@errormsg, errmsg)
78
+ ok_(errmsg) == @errormsg
82
79
  end
83
80
  end
84
- assert_equal(@filename, ex.filename) if @filename
81
+ if @filename
82
+ ok_(ex.filename, @filename)
83
+ end
85
84
  else
86
85
  template = @templateclass.new(@options)
87
86
  script = template.convert(@input, @filename)
88
- assert_text_equal(@source, script)
87
+ ok_(script) == @source
89
88
  if @expected
90
89
  output = template.render(@context)
91
- assert_text_equal(@expected, output)
90
+ ok_(output) == @expected
92
91
  end
93
92
  end
94
93
 
@@ -109,8 +108,8 @@ END
109
108
  File.open(filename, 'w') { |f| f.write(input) }
110
109
  template1 = Tenjin::Template.new(filename)
111
110
  template2 = Tenjin::Template.new()
112
- assert_text_equal(template1.script, template2.convert(input))
113
- assert_text_equal(template1.render(), template2.render())
111
+ ok_(template2.convert(input)) == template1.script
112
+ ok_(template2.render()) == template1.render()
114
113
  ensure
115
114
  File.unlink(filename)
116
115
  end
@@ -121,8 +120,51 @@ END
121
120
 
122
121
  #def test_import_module2()
123
122
 
123
+ def test_input
124
+ t = Tenjin::Template.new(:input=>"<p>Hello ${name}</p>")
125
+ ok_(t.script) == ' _buf << %Q`<p>Hello #{escape((name).to_s)}</p>`; ' + "\n"
126
+ ok_(t.filename) == nil
127
+ t = Tenjin::Template.new('example.rbhtml', :input=>"<p>Hello ${name}</p>")
128
+ ok_(t.filename) == 'example.rbhtml'
129
+ ok_(t.script) == ' _buf << %Q`<p>Hello #{escape((name).to_s)}</p>`; ' + "\n"
130
+ end
124
131
 
125
- self.select_target_test()
132
+ def test_trace
133
+ input = <<'END'
134
+ <ul>
135
+ <?rb for item in @items ?>
136
+ <li>#{item}<li>
137
+ <?rb end ?>
138
+ </ul>
139
+ END
140
+ t = Tenjin::Template.new('example.rbhtml', :input=>input, :trace=>true)
141
+ output = t.render({:items=>['A','B','C']})
142
+ ok_(output) == <<'END'
143
+ <!-- ***** begin: example.rbhtml ***** -->
144
+ <ul>
145
+ <li>A<li>
146
+ <li>B<li>
147
+ <li>C<li>
148
+ </ul>
149
+ <!-- ***** end: example.rbhtml ***** -->
150
+ END
151
+ end
152
+
153
+ def test_TRACE
154
+ orig = Tenjin::Template::TRACE
155
+ ok_(Tenjin::Template::TRACE) == false
156
+ ok_(Tenjin::Template.new.instance_variable_get('@trace')) == false
157
+ Tenjin::Template.TRACE = true
158
+ ok_(Tenjin::Template::TRACE) == true
159
+ ok_(Tenjin::Template.new.instance_variable_get('@trace')) == true
160
+ ensure
161
+ Tenjin::Template.TRACE = false
162
+ end
163
+
164
+
165
+ end
126
166
 
127
167
 
168
+ if __FILE__ == $0
169
+ Oktest.run_all()
128
170
  end
@@ -361,7 +361,7 @@
361
361
  input*:
362
362
  "python": |
363
363
  <ul>
364
- <?py for i in xrange(1,4): ?>
364
+ <?py for i in range(1,4): ?>
365
365
  <li>
366
366
  #{i}
367
367
  </li>
@@ -377,7 +377,7 @@
377
377
  source*:
378
378
  "python": |
379
379
  _buf.extend(('''<ul>\n''', ));
380
- for i in xrange(1,4):
380
+ for i in range(1,4):
381
381
  _buf.extend(('''<li>
382
382
  ''', to_str(i), '''
383
383
  </li>\n''', ));
@@ -564,7 +564,7 @@
564
564
  "python": |
565
565
  <p>^
566
566
  <?py^
567
- for value in xrange(0,3):^
567
+ for value in range(0,3):^
568
568
  ?>^
569
569
  i = #{value}^
570
570
  #{value}^
@@ -587,7 +587,7 @@
587
587
  "python": |
588
588
  _buf.extend(('''<p>\r\n''', ));
589
589
 
590
- for value in xrange(0,3):
590
+ for value in range(0,3):
591
591
 
592
592
  _buf.extend(('''i = ''', to_str(value), '''^
593
593
  ''', to_str(value), '''\r\n''', ));
@@ -748,7 +748,7 @@
748
748
  - name: option_encoding1
749
749
  desc: encoding option
750
750
  disabled*:
751
- "python": false
751
+ "python": true
752
752
  "ruby": true
753
753
  options: { encoding: utf-8 }
754
754
  testopts: { encoding: utf-8 }
@@ -961,7 +961,7 @@
961
961
  <?PY "FL": "Florida", } ?>
962
962
  <?PY # ?>
963
963
  <?py chk = { params['state']: ' checked="checked"' } ?>
964
- <?PY codes = states.keys() ?>
964
+ <?PY codes = list(states.keys()) ?>
965
965
  <?PY codes.sort() ?>
966
966
  <select name="state">
967
967
  <option value="">-</option>
@@ -1014,7 +1014,7 @@
1014
1014
  "FL": "Florida", }
1015
1015
  #
1016
1016
  _buf.extend(('''<?py chk = { params[\'state\']: \' checked="checked"\' } ?>\n''', ));
1017
- codes = states.keys()
1017
+ codes = list(states.keys())
1018
1018
  codes.sort()
1019
1019
  _buf.extend(('''<select name="state">
1020
1020
  <option value="">-</option>\n''', ));
@@ -1,13 +1,11 @@
1
1
  ###
2
- ### $Rev: 48 $
3
- ### $Release: 0.6.2 $
4
- ### copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
2
+ ### $Rev$
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
7
- require 'test/unit'
8
- #require 'testutil'
9
- #require 'testcase-helper'
10
- require 'assert-text-equal'
7
+ require "#{File.dirname(File.expand_path(__FILE__))}/test_all"
8
+ require 'fileutils'
11
9
 
12
10
  #class Symbol
13
11
  # def <=>(other)
@@ -24,46 +22,85 @@ require 'assert-text-equal'
24
22
  # end
25
23
  #end
26
24
 
27
- require 'tenjin'
28
25
 
29
- class TenjinUsersGuideTest < Test::Unit::TestCase
26
+ class TenjinUsersGuideTest
27
+ include Oktest::TestCase
30
28
 
31
- DIR = File.expand_path(File.dirname(__FILE__) + '/data/users_guide')
29
+ DIR = ARGV[0] || File.expand_path(File.dirname(__FILE__) + '/data/users_guide')
32
30
  CWD = Dir.pwd()
33
31
 
34
-
35
- def setup
32
+ def before
36
33
  Dir.chdir DIR
37
34
  end
38
35
 
39
36
 
40
- def teardown
37
+ def after
41
38
  Dir.chdir CWD
42
39
  end
43
40
 
44
41
 
45
42
  def _test
46
- @name = (caller()[0] =~ /`(.*?)'/) && $1
47
- s = File.read(@filename)
48
- s =~ /\A\$ (.*?)\n/
49
- command = $1
50
- expected = $'
51
- result = `#{command}`
52
- assert_text_equal(expected, result)
43
+ #@name = (caller()[0] =~ /`(.*?)'/) && $1
44
+ Dir.chdir @name do
45
+ Dir.glob("*.output").each do |filename|
46
+ s = File.read(filename)
47
+ s =~ /\A\$ (.*?)\n/
48
+ command = $1
49
+ expected = $'
50
+ result = `#{command}`
51
+ #
52
+ if RUBY_VERSION >= '1.9'
53
+ expected.gsub!(/expecting kEND/, 'expecting keyword_end')
54
+ end
55
+ case @name
56
+ when 'test_nested'
57
+ expected.gsub!(/ *\# .*$/, '')
58
+ when 'test_logging'
59
+ result .gsub!(/\d+/, '9999')
60
+ expected.gsub!(/\d+/, '9999')
61
+ end
62
+ #
63
+ ok_(result) == expected
64
+ end
65
+ end
53
66
  end
54
67
 
68
+ def self.prepare
69
+ ## remove cache files
70
+ Dir.glob("test_*/**/*.cache").each do |fpath|
71
+ File.unlink(fpath)
72
+ end
73
+ ## copy necessary files
74
+ pathlist = Dir.glob("test_*")
75
+ d = {}
76
+ pathlist.select {|dirpath| dirpath =~ /_\d\d\d$/ }.each do |dirpath|
77
+ Dir.glob("#{dirpath}/**/*").each do |path|
78
+ next unless File.file?(path)
79
+ key = path.sub(/^[^\/]*\//, '')
80
+ d[key] = path
81
+ end
82
+ d.each_pair do |k, v|
83
+ fpath = "#{dirpath}/#{k}"
84
+ unless File.exist?(fpath)
85
+ dirname = File.dirname(fpath)
86
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
87
+ #puts "cp #{v} #{fpath}"
88
+ FileUtils.copy(v, fpath)
89
+ else
90
+ #puts "#cp #{v} #{fpath}"
91
+ end
92
+ end
93
+ end
94
+ end
55
95
 
56
- Dir.chdir DIR do
57
- filenames = []
58
- filenames += Dir.glob('*.result')
59
- filenames += Dir.glob('*.source')
60
- filenames.each do |filename|
61
- name = filename.gsub(/[^\w]/, '_')
96
+ def self.define_tests
97
+ dirnames = Dir.glob("test_*")
98
+ dirnames.each do |dirname|
99
+ name = dirname
62
100
  s = <<-END
63
- def test_#{name}
64
- # $stderr.puts "*** debug: test_#{name}"
101
+ def #{name}
102
+ # $stderr.puts "*** debug: #{name}
65
103
  @name = '#{name}'
66
- @filename = '#{filename}'
67
104
  _test()
68
105
  end
69
106
  END
@@ -71,5 +108,14 @@ class TenjinUsersGuideTest < Test::Unit::TestCase
71
108
  end
72
109
  end
73
110
 
111
+ Dir.chdir DIR do
112
+ self.prepare()
113
+ self.define_tests()
114
+ end
115
+
116
+ end
117
+
74
118
 
119
+ if __FILE__ == $0
120
+ Oktest.run_all()
75
121
  end
@@ -1,7 +1,7 @@
1
1
  ###
2
- ### $Rev: 72 $
3
- ### $Release: 0.6.2 $
4
- ### copyright(c) 2007-2008 kuwata-lab.com all rights reserved.
2
+ ### $Rev$
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
7
7
  if defined?(RBX_VERSION)
@@ -53,10 +53,11 @@ end
53
53
 
54
54
 
55
55
 
56
- class Test::Unit::TestCase # :nodoc:
56
+ #class Test::Unit::TestCase # :nodoc:
57
+ module Oktest::ClassMethodHelper
57
58
 
58
59
 
59
- def self.select_target_test(target_name=ENV['TEST'])
60
+ def select_target_test(target_name=ENV['TEST'])
60
61
  if target_name
61
62
  self.instance_methods.each do |method|
62
63
  private method if method =~ /^test_(.*)/ && $1 != target_name
@@ -65,7 +66,7 @@ class Test::Unit::TestCase # :nodoc:
65
66
  end
66
67
 
67
68
 
68
- def self._untabify(str, width=8) # :nodoc:
69
+ def _untabify(str, width=8) # :nodoc:
69
70
  list = str.split(/\t/, -1)
70
71
  return list.first if list.length == 1
71
72
  last = list.pop
@@ -87,8 +88,9 @@ class Test::Unit::TestCase # :nodoc:
87
88
  end
88
89
 
89
90
 
90
- def self.load_yaml_documents(filename, options={}) # :nodoc:
91
+ def load_yaml_documents(filename, options={}) # :nodoc:
91
92
  str = File.read(filename)
93
+ str.force_encoding('utf-8') if str.respond_to?(:force_encoding)
92
94
  if filename =~ /\.rb$/
93
95
  str =~ /^__END__$/ or raise "*** error: __END__ is not found in '#{filename}'."
94
96
  str = $'
@@ -113,11 +115,11 @@ class Test::Unit::TestCase # :nodoc:
113
115
  table[ident] = ydoc
114
116
  end
115
117
  #
116
- target = $target || ENV['TEST']
117
- if target
118
- table[target] or raise "*** target '#{target}' not found."
119
- list = [ table[target] ]
120
- end
118
+ #target = $target || ENV['TEST']
119
+ #if target
120
+ # table[target] or raise "*** target '#{target}' not found."
121
+ # list = [ table[target] ]
122
+ #end
121
123
  #
122
124
  list.each do |ydoc| yield(ydoc) end if block_given?
123
125
  #
@@ -127,7 +129,7 @@ class Test::Unit::TestCase # :nodoc:
127
129
 
128
130
  SPECIAL_KEYS = %[exception errormsg]
129
131
 
130
- def self.load_yaml_testdata(filename, options={}) # :nodoc:
132
+ def load_yaml_testdata(filename, options={}) # :nodoc:
131
133
  identkey = options[:identkey] || 'name'
132
134
  testmethod = options[:testmethod] || '_test'
133
135
  lang = options[:lang]
@@ -150,24 +152,24 @@ class Test::Unit::TestCase # :nodoc:
150
152
  end
151
153
  s << " #{testmethod}\n"
152
154
  s << "end\n"
153
- $stderr.puts "*** #{method_name()}(): eval_str=<<'END'\n#{s}END" if $DEBUG
155
+ $stderr.puts "*** #{_method_name()}(): eval_str=<<'END'\n#{s}END" if $DEBUG
154
156
  end
155
157
  #module_eval s # not eval!
156
158
  return s
157
159
  end
158
160
 
159
161
 
160
- def self.method_name # :nodoc:
162
+ def _method_name # :nodoc:
161
163
  return (caller[0] =~ /in `(.*?)'/) && $1
162
164
  end
163
165
 
164
166
 
165
- def self.load_yaml_testdata_with_each_lang(filename, options={}) # :nodoc:
167
+ def load_yaml_testdata_with_each_lang(filename, options={}) # :nodoc:
166
168
  identkey = options[:identkey] || 'name'
167
169
  testmethod = options[:testmethod] || '_test'
168
170
  special_keys = options[:special_keys] || SPECIAL_KEYS
169
171
  langs = defined?($lang) && $lang ? [ $lang ] : options[:langs]
170
- langs or raise "*** #{method_name()}(): option ':langs' is required."
172
+ langs or raise "*** #{_method_name()}(): option ':langs' is required."
171
173
 
172
174
  load_yaml_documents(filename, options) do |ydoc|
173
175
  ident = ydoc[identkey]
@@ -184,7 +186,7 @@ class Test::Unit::TestCase # :nodoc:
184
186
  end
185
187
  s << " #{testmethod}\n"
186
188
  s << "end\n"
187
- #$stderr.puts "*** #{method_name()}(): eval_str=<<'END'\n#{s}END" if $DEBUG
189
+ #$stderr.puts "*** #{_method_name()}(): eval_str=<<'END'\n#{s}END" if $DEBUG
188
190
  module_eval s # not eval!
189
191
  end
190
192
  end
@@ -0,0 +1,71 @@
1
+ ###
2
+ ### $Rev$
3
+ ### 0.7.0
4
+ ### copyright(c) 2007-2011 kuwata-lab.com all rights reserved
5
+ ###
6
+
7
+ require 'test/unit'
8
+ require 'tempfile'
9
+
10
+
11
+ module Test::Unit::Assertions
12
+
13
+ def assert_text_equal(expected, actual, message=nil, diffopt='-u', flag_cut=true)
14
+ if expected == actual
15
+ assert(true)
16
+ return
17
+ end
18
+ if expected && actual && (expected[-1] != ?\n || actual[-1] != ?\n)
19
+ expected += "\n"
20
+ actual += "\n"
21
+ end
22
+ begin
23
+ expfile = Tempfile.new(".expected.")
24
+ expfile.write(expected); expfile.flush()
25
+ actfile = Tempfile.new(".actual.")
26
+ actfile.write(actual); actfile.flush()
27
+ diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
28
+ ensure
29
+ expfile.close(true) if expfile
30
+ actfile.close(true) if actfile
31
+ end
32
+ # cut 1st & 2nd lines
33
+ message = (flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff) unless message
34
+ #raise Test::Unit::AssertionFailedError.new(message)
35
+ assert_block(message) { false } # or assert(false, message)
36
+ end
37
+
38
+ alias assert_equal_with_diff assert_text_equal # for compatibility
39
+ alias assert_text_equals assert_text_equal # for typo
40
+
41
+ # def assert_true(val, message=nil)
42
+ # message ||= "true is expected but got #{val.inspect}"
43
+ # assert(val == true, message)
44
+ # end
45
+ #
46
+ # def assert_false(val, message=nil)
47
+ # message ||= "false is expected but got #{val.inspect}"
48
+ # assert(val == false, message)
49
+ # end
50
+
51
+ def assert_exist(path, message=nil)
52
+ message ||= "'#{path}' doesn't exist"
53
+ assert(File.exist?(path), message)
54
+ end
55
+
56
+ def assert_not_exist(path, message=nil)
57
+ message ||= "'#{path}' exist"
58
+ assert(! File.exist?(path), message)
59
+ end
60
+
61
+ def assert_file_exist(path, message=nil)
62
+ message ||= "'#{path}' doesn't exist or not a file"
63
+ assert(File.file?(path), message)
64
+ end
65
+
66
+ def assert_dir_exist(path, message=nil)
67
+ message ||= "'#{path}' doesn't exist or not a directory"
68
+ assert(File.file?(path), message)
69
+ end
70
+
71
+ end