fluentd 0.14.4-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (328) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +26 -0
  4. data/.travis.yml +45 -0
  5. data/AUTHORS +2 -0
  6. data/CONTRIBUTING.md +35 -0
  7. data/COPYING +14 -0
  8. data/ChangeLog +276 -0
  9. data/Gemfile +9 -0
  10. data/README.md +51 -0
  11. data/Rakefile +53 -0
  12. data/Vagrantfile +17 -0
  13. data/appveyor.yml +41 -0
  14. data/bin/fluent-debug +5 -0
  15. data/example/copy_roundrobin.conf +39 -0
  16. data/example/filter_stdout.conf +22 -0
  17. data/example/in_forward.conf +11 -0
  18. data/example/in_http.conf +14 -0
  19. data/example/in_out_forward.conf +17 -0
  20. data/example/in_syslog.conf +15 -0
  21. data/example/in_tail.conf +14 -0
  22. data/example/in_tcp.conf +13 -0
  23. data/example/in_udp.conf +13 -0
  24. data/example/multi_filters.conf +61 -0
  25. data/example/out_buffered_null.conf +32 -0
  26. data/example/out_copy.conf +20 -0
  27. data/example/out_file.conf +13 -0
  28. data/example/out_forward.conf +35 -0
  29. data/example/out_forward_buf_file.conf +23 -0
  30. data/example/v0_12_filter.conf +78 -0
  31. data/example/v1_literal_example.conf +36 -0
  32. data/fluent.conf +139 -0
  33. data/fluentd.gemspec +51 -0
  34. data/lib/fluent/agent.rb +194 -0
  35. data/lib/fluent/command/bundler_injection.rb +45 -0
  36. data/lib/fluent/command/cat.rb +319 -0
  37. data/lib/fluent/command/debug.rb +102 -0
  38. data/lib/fluent/command/fluentd.rb +273 -0
  39. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  40. data/lib/fluent/compat/exec_util.rb +129 -0
  41. data/lib/fluent/compat/file_util.rb +54 -0
  42. data/lib/fluent/compat/filter.rb +68 -0
  43. data/lib/fluent/compat/formatter.rb +111 -0
  44. data/lib/fluent/compat/formatter_utils.rb +85 -0
  45. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  46. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  47. data/lib/fluent/compat/input.rb +49 -0
  48. data/lib/fluent/compat/output.rb +677 -0
  49. data/lib/fluent/compat/output_chain.rb +60 -0
  50. data/lib/fluent/compat/parser.rb +180 -0
  51. data/lib/fluent/compat/parser_utils.rb +40 -0
  52. data/lib/fluent/compat/propagate_default.rb +62 -0
  53. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  54. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  55. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  56. data/lib/fluent/compat/socket_util.rb +165 -0
  57. data/lib/fluent/compat/string_util.rb +34 -0
  58. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  59. data/lib/fluent/compat/type_converter.rb +90 -0
  60. data/lib/fluent/config.rb +56 -0
  61. data/lib/fluent/config/basic_parser.rb +123 -0
  62. data/lib/fluent/config/configure_proxy.rb +366 -0
  63. data/lib/fluent/config/dsl.rb +149 -0
  64. data/lib/fluent/config/element.rb +218 -0
  65. data/lib/fluent/config/error.rb +26 -0
  66. data/lib/fluent/config/literal_parser.rb +251 -0
  67. data/lib/fluent/config/parser.rb +107 -0
  68. data/lib/fluent/config/section.rb +212 -0
  69. data/lib/fluent/config/types.rb +136 -0
  70. data/lib/fluent/config/v1_parser.rb +190 -0
  71. data/lib/fluent/configurable.rb +176 -0
  72. data/lib/fluent/daemon.rb +15 -0
  73. data/lib/fluent/engine.rb +220 -0
  74. data/lib/fluent/env.rb +27 -0
  75. data/lib/fluent/event.rb +287 -0
  76. data/lib/fluent/event_router.rb +259 -0
  77. data/lib/fluent/filter.rb +21 -0
  78. data/lib/fluent/formatter.rb +23 -0
  79. data/lib/fluent/input.rb +21 -0
  80. data/lib/fluent/label.rb +38 -0
  81. data/lib/fluent/load.rb +36 -0
  82. data/lib/fluent/log.rb +445 -0
  83. data/lib/fluent/match.rb +141 -0
  84. data/lib/fluent/mixin.rb +31 -0
  85. data/lib/fluent/msgpack_factory.rb +62 -0
  86. data/lib/fluent/output.rb +26 -0
  87. data/lib/fluent/output_chain.rb +23 -0
  88. data/lib/fluent/parser.rb +23 -0
  89. data/lib/fluent/plugin.rb +161 -0
  90. data/lib/fluent/plugin/bare_output.rb +63 -0
  91. data/lib/fluent/plugin/base.rb +130 -0
  92. data/lib/fluent/plugin/buf_file.rb +154 -0
  93. data/lib/fluent/plugin/buf_memory.rb +34 -0
  94. data/lib/fluent/plugin/buffer.rb +603 -0
  95. data/lib/fluent/plugin/buffer/chunk.rb +160 -0
  96. data/lib/fluent/plugin/buffer/file_chunk.rb +323 -0
  97. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  98. data/lib/fluent/plugin/exec_util.rb +22 -0
  99. data/lib/fluent/plugin/file_util.rb +22 -0
  100. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  101. data/lib/fluent/plugin/filter.rb +93 -0
  102. data/lib/fluent/plugin/filter_grep.rb +75 -0
  103. data/lib/fluent/plugin/filter_record_transformer.rb +342 -0
  104. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  105. data/lib/fluent/plugin/formatter.rb +45 -0
  106. data/lib/fluent/plugin/formatter_csv.rb +47 -0
  107. data/lib/fluent/plugin/formatter_hash.rb +29 -0
  108. data/lib/fluent/plugin/formatter_json.rb +44 -0
  109. data/lib/fluent/plugin/formatter_ltsv.rb +41 -0
  110. data/lib/fluent/plugin/formatter_msgpack.rb +29 -0
  111. data/lib/fluent/plugin/formatter_out_file.rb +78 -0
  112. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  113. data/lib/fluent/plugin/formatter_stdout.rb +74 -0
  114. data/lib/fluent/plugin/in_debug_agent.rb +64 -0
  115. data/lib/fluent/plugin/in_dummy.rb +135 -0
  116. data/lib/fluent/plugin/in_exec.rb +149 -0
  117. data/lib/fluent/plugin/in_forward.rb +366 -0
  118. data/lib/fluent/plugin/in_gc_stat.rb +52 -0
  119. data/lib/fluent/plugin/in_http.rb +422 -0
  120. data/lib/fluent/plugin/in_monitor_agent.rb +401 -0
  121. data/lib/fluent/plugin/in_object_space.rb +90 -0
  122. data/lib/fluent/plugin/in_syslog.rb +204 -0
  123. data/lib/fluent/plugin/in_tail.rb +838 -0
  124. data/lib/fluent/plugin/in_tcp.rb +41 -0
  125. data/lib/fluent/plugin/in_udp.rb +37 -0
  126. data/lib/fluent/plugin/in_unix.rb +201 -0
  127. data/lib/fluent/plugin/input.rb +33 -0
  128. data/lib/fluent/plugin/multi_output.rb +95 -0
  129. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  130. data/lib/fluent/plugin/out_buffered_stdout.rb +70 -0
  131. data/lib/fluent/plugin/out_copy.rb +42 -0
  132. data/lib/fluent/plugin/out_exec.rb +114 -0
  133. data/lib/fluent/plugin/out_exec_filter.rb +393 -0
  134. data/lib/fluent/plugin/out_file.rb +167 -0
  135. data/lib/fluent/plugin/out_forward.rb +646 -0
  136. data/lib/fluent/plugin/out_null.rb +27 -0
  137. data/lib/fluent/plugin/out_relabel.rb +28 -0
  138. data/lib/fluent/plugin/out_roundrobin.rb +80 -0
  139. data/lib/fluent/plugin/out_stdout.rb +48 -0
  140. data/lib/fluent/plugin/out_stream.rb +130 -0
  141. data/lib/fluent/plugin/output.rb +1020 -0
  142. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  143. data/lib/fluent/plugin/parser.rb +175 -0
  144. data/lib/fluent/plugin/parser_apache.rb +28 -0
  145. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  146. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  147. data/lib/fluent/plugin/parser_csv.rb +33 -0
  148. data/lib/fluent/plugin/parser_json.rb +79 -0
  149. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  150. data/lib/fluent/plugin/parser_multiline.rb +104 -0
  151. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  152. data/lib/fluent/plugin/parser_none.rb +36 -0
  153. data/lib/fluent/plugin/parser_regexp.rb +73 -0
  154. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  155. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  156. data/lib/fluent/plugin/socket_util.rb +22 -0
  157. data/lib/fluent/plugin/storage.rb +84 -0
  158. data/lib/fluent/plugin/storage_local.rb +132 -0
  159. data/lib/fluent/plugin/string_util.rb +22 -0
  160. data/lib/fluent/plugin_helper.rb +42 -0
  161. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  162. data/lib/fluent/plugin_helper/compat_parameters.rb +224 -0
  163. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  164. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  165. data/lib/fluent/plugin_helper/formatter.rb +149 -0
  166. data/lib/fluent/plugin_helper/inject.rb +125 -0
  167. data/lib/fluent/plugin_helper/parser.rb +147 -0
  168. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  169. data/lib/fluent/plugin_helper/storage.rb +331 -0
  170. data/lib/fluent/plugin_helper/thread.rb +147 -0
  171. data/lib/fluent/plugin_helper/timer.rb +90 -0
  172. data/lib/fluent/plugin_id.rb +63 -0
  173. data/lib/fluent/process.rb +504 -0
  174. data/lib/fluent/registry.rb +99 -0
  175. data/lib/fluent/root_agent.rb +314 -0
  176. data/lib/fluent/rpc.rb +94 -0
  177. data/lib/fluent/supervisor.rb +680 -0
  178. data/lib/fluent/system_config.rb +122 -0
  179. data/lib/fluent/test.rb +56 -0
  180. data/lib/fluent/test/base.rb +85 -0
  181. data/lib/fluent/test/driver/base.rb +179 -0
  182. data/lib/fluent/test/driver/base_owned.rb +70 -0
  183. data/lib/fluent/test/driver/base_owner.rb +125 -0
  184. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  185. data/lib/fluent/test/driver/filter.rb +57 -0
  186. data/lib/fluent/test/driver/formatter.rb +30 -0
  187. data/lib/fluent/test/driver/input.rb +31 -0
  188. data/lib/fluent/test/driver/multi_output.rb +52 -0
  189. data/lib/fluent/test/driver/output.rb +76 -0
  190. data/lib/fluent/test/driver/parser.rb +30 -0
  191. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  192. data/lib/fluent/test/filter_test.rb +77 -0
  193. data/lib/fluent/test/formatter_test.rb +65 -0
  194. data/lib/fluent/test/helpers.rb +79 -0
  195. data/lib/fluent/test/input_test.rb +172 -0
  196. data/lib/fluent/test/log.rb +73 -0
  197. data/lib/fluent/test/output_test.rb +156 -0
  198. data/lib/fluent/test/parser_test.rb +70 -0
  199. data/lib/fluent/time.rb +175 -0
  200. data/lib/fluent/timezone.rb +133 -0
  201. data/lib/fluent/unique_id.rb +39 -0
  202. data/lib/fluent/version.rb +21 -0
  203. data/lib/fluent/winsvc.rb +71 -0
  204. data/test/compat/test_calls_super.rb +166 -0
  205. data/test/compat/test_parser.rb +82 -0
  206. data/test/config/assertions.rb +42 -0
  207. data/test/config/test_config_parser.rb +507 -0
  208. data/test/config/test_configurable.rb +1194 -0
  209. data/test/config/test_configure_proxy.rb +386 -0
  210. data/test/config/test_dsl.rb +415 -0
  211. data/test/config/test_element.rb +403 -0
  212. data/test/config/test_literal_parser.rb +297 -0
  213. data/test/config/test_section.rb +184 -0
  214. data/test/config/test_system_config.rb +120 -0
  215. data/test/config/test_types.rb +171 -0
  216. data/test/helper.rb +119 -0
  217. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  218. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  219. data/test/plugin/data/2010/01/20100102.log +0 -0
  220. data/test/plugin/data/log/bar +0 -0
  221. data/test/plugin/data/log/foo/bar.log +0 -0
  222. data/test/plugin/data/log/test.log +0 -0
  223. data/test/plugin/test_bare_output.rb +118 -0
  224. data/test/plugin/test_base.rb +75 -0
  225. data/test/plugin/test_buf_file.rb +571 -0
  226. data/test/plugin/test_buf_memory.rb +42 -0
  227. data/test/plugin/test_buffer.rb +1200 -0
  228. data/test/plugin/test_buffer_chunk.rb +168 -0
  229. data/test/plugin/test_buffer_file_chunk.rb +771 -0
  230. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  231. data/test/plugin/test_file_util.rb +96 -0
  232. data/test/plugin/test_filter.rb +353 -0
  233. data/test/plugin/test_filter_grep.rb +119 -0
  234. data/test/plugin/test_filter_record_transformer.rb +600 -0
  235. data/test/plugin/test_filter_stdout.rb +211 -0
  236. data/test/plugin/test_formatter_csv.rb +94 -0
  237. data/test/plugin/test_formatter_json.rb +30 -0
  238. data/test/plugin/test_formatter_ltsv.rb +52 -0
  239. data/test/plugin/test_formatter_msgpack.rb +28 -0
  240. data/test/plugin/test_formatter_out_file.rb +95 -0
  241. data/test/plugin/test_formatter_single_value.rb +38 -0
  242. data/test/plugin/test_in_debug_agent.rb +28 -0
  243. data/test/plugin/test_in_dummy.rb +188 -0
  244. data/test/plugin/test_in_exec.rb +133 -0
  245. data/test/plugin/test_in_forward.rb +635 -0
  246. data/test/plugin/test_in_gc_stat.rb +39 -0
  247. data/test/plugin/test_in_http.rb +442 -0
  248. data/test/plugin/test_in_monitor_agent.rb +329 -0
  249. data/test/plugin/test_in_object_space.rb +64 -0
  250. data/test/plugin/test_in_syslog.rb +205 -0
  251. data/test/plugin/test_in_tail.rb +1001 -0
  252. data/test/plugin/test_in_tcp.rb +102 -0
  253. data/test/plugin/test_in_udp.rb +121 -0
  254. data/test/plugin/test_in_unix.rb +126 -0
  255. data/test/plugin/test_input.rb +122 -0
  256. data/test/plugin/test_multi_output.rb +180 -0
  257. data/test/plugin/test_out_buffered_null.rb +79 -0
  258. data/test/plugin/test_out_buffered_stdout.rb +122 -0
  259. data/test/plugin/test_out_copy.rb +160 -0
  260. data/test/plugin/test_out_exec.rb +155 -0
  261. data/test/plugin/test_out_exec_filter.rb +262 -0
  262. data/test/plugin/test_out_file.rb +383 -0
  263. data/test/plugin/test_out_forward.rb +590 -0
  264. data/test/plugin/test_out_null.rb +29 -0
  265. data/test/plugin/test_out_relabel.rb +28 -0
  266. data/test/plugin/test_out_roundrobin.rb +146 -0
  267. data/test/plugin/test_out_stdout.rb +92 -0
  268. data/test/plugin/test_out_stream.rb +93 -0
  269. data/test/plugin/test_output.rb +568 -0
  270. data/test/plugin/test_output_as_buffered.rb +1604 -0
  271. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  272. data/test/plugin/test_output_as_buffered_retries.rb +839 -0
  273. data/test/plugin/test_output_as_buffered_secondary.rb +817 -0
  274. data/test/plugin/test_output_as_standard.rb +374 -0
  275. data/test/plugin/test_owned_by.rb +35 -0
  276. data/test/plugin/test_parser_apache.rb +42 -0
  277. data/test/plugin/test_parser_apache2.rb +38 -0
  278. data/test/plugin/test_parser_apache_error.rb +45 -0
  279. data/test/plugin/test_parser_base.rb +32 -0
  280. data/test/plugin/test_parser_csv.rb +104 -0
  281. data/test/plugin/test_parser_json.rb +107 -0
  282. data/test/plugin/test_parser_labeled_tsv.rb +129 -0
  283. data/test/plugin/test_parser_multiline.rb +100 -0
  284. data/test/plugin/test_parser_nginx.rb +48 -0
  285. data/test/plugin/test_parser_none.rb +53 -0
  286. data/test/plugin/test_parser_regexp.rb +277 -0
  287. data/test/plugin/test_parser_syslog.rb +66 -0
  288. data/test/plugin/test_parser_time.rb +46 -0
  289. data/test/plugin/test_parser_tsv.rb +121 -0
  290. data/test/plugin/test_storage.rb +167 -0
  291. data/test/plugin/test_storage_local.rb +8 -0
  292. data/test/plugin/test_string_util.rb +26 -0
  293. data/test/plugin_helper/test_child_process.rb +608 -0
  294. data/test/plugin_helper/test_compat_parameters.rb +242 -0
  295. data/test/plugin_helper/test_event_emitter.rb +51 -0
  296. data/test/plugin_helper/test_event_loop.rb +52 -0
  297. data/test/plugin_helper/test_formatter.rb +252 -0
  298. data/test/plugin_helper/test_inject.rb +487 -0
  299. data/test/plugin_helper/test_parser.rb +263 -0
  300. data/test/plugin_helper/test_retry_state.rb +399 -0
  301. data/test/plugin_helper/test_storage.rb +521 -0
  302. data/test/plugin_helper/test_thread.rb +164 -0
  303. data/test/plugin_helper/test_timer.rb +131 -0
  304. data/test/scripts/exec_script.rb +32 -0
  305. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  306. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  307. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  308. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  309. data/test/test_config.rb +179 -0
  310. data/test/test_configdsl.rb +148 -0
  311. data/test/test_event.rb +329 -0
  312. data/test/test_event_router.rb +331 -0
  313. data/test/test_event_time.rb +184 -0
  314. data/test/test_filter.rb +121 -0
  315. data/test/test_formatter.rb +319 -0
  316. data/test/test_input.rb +31 -0
  317. data/test/test_log.rb +572 -0
  318. data/test/test_match.rb +137 -0
  319. data/test/test_mixin.rb +351 -0
  320. data/test/test_output.rb +214 -0
  321. data/test/test_plugin_classes.rb +136 -0
  322. data/test/test_plugin_helper.rb +81 -0
  323. data/test/test_process.rb +48 -0
  324. data/test/test_root_agent.rb +278 -0
  325. data/test/test_supervisor.rb +339 -0
  326. data/test/test_time_formatter.rb +186 -0
  327. data/test/test_unique_id.rb +47 -0
  328. metadata +823 -0
@@ -0,0 +1,403 @@
1
+ require_relative '../helper'
2
+ require 'fluent/config/element'
3
+ require 'fluent/config/configure_proxy'
4
+ require 'fluent/configurable'
5
+
6
+ class TestConfigElement < ::Test::Unit::TestCase
7
+ def element(name = 'ROOT', arg = '', attrs = {}, elements = [], unused = nil)
8
+ Fluent::Config::Element.new(name, arg, attrs, elements, unused)
9
+ end
10
+
11
+ sub_test_case '#elements=' do
12
+ test 'elements can be set by others' do
13
+ e = element()
14
+ assert_equal [], e.elements
15
+
16
+ e1 = element('e1')
17
+ e2 = element('e2')
18
+ e.elements = [e1, e2]
19
+ assert_equal [e1, e2], e.elements
20
+ end
21
+ end
22
+
23
+ sub_test_case '#elements' do
24
+ setup do
25
+ @c1 = element('source')
26
+ @c2 = element('source', 'yay')
27
+ @c3 = element('match', 'test.**')
28
+ @c4 = element('label', '@mytest', {}, [ element('filter', '**'), element('match', '**') ])
29
+ children = [@c1, @c2, @c3, @c4]
30
+ @e = Fluent::Config::Element.new('ROOT', '', {}, children)
31
+ end
32
+
33
+ test 'returns all elements without arguments' do
34
+ assert_equal [@c1, @c2, @c3, @c4], @e.elements
35
+ end
36
+
37
+ test 'returns elements with specified names' do
38
+ assert_equal [@c1, @c2, @c3], @e.elements('source', 'match')
39
+ assert_equal [@c3, @c4], @e.elements('match', 'label')
40
+ end
41
+
42
+ test 'returns elements with specified name, and arg if specified' do
43
+ assert_equal [@c1, @c2], @e.elements(name: 'source')
44
+ assert_equal [@c2], @e.elements(name: 'source', arg: 'yay')
45
+ end
46
+
47
+ test 'keyword argument name/arg and names are exclusive' do
48
+ assert_raise ArgumentError do
49
+ @e.elements('source', name: 'match')
50
+ end
51
+ assert_raise ArgumentError do
52
+ @e.elements('source', 'match', name: 'label', arg: '@mytest')
53
+ end
54
+ end
55
+
56
+ test 'specifying only arg without name is invalid' do
57
+ assert_raise ArgumentError do
58
+ @e.elements(arg: '@mytest')
59
+ end
60
+ end
61
+ end
62
+
63
+ sub_test_case '#initialize' do
64
+ test 'creates object with blank attrs and elements' do
65
+ e = element('ROOT', '', {}, [])
66
+ assert_equal([], e.elements)
67
+ end
68
+
69
+ test 'creates object which contains attrs and elements' do
70
+ e = element('ROOT', '', {"k1" => "v1", "k2" => "v2"}, [
71
+ element('test', 'mydata', {'k3' => 'v3'}, [])
72
+ ])
73
+ assert_equal('ROOT', e.name)
74
+ assert_equal('', e.arg)
75
+ assert_equal('v1', e["k1"])
76
+ assert_equal('v2', e["k2"])
77
+ assert_equal(1, e.elements.size)
78
+ e.each_element('test') do |el|
79
+ assert_equal('test', el.name)
80
+ assert_equal('mydata', el.arg)
81
+ assert_equal('v3', el["k3"])
82
+ end
83
+ end
84
+
85
+ test 'creates object which contains attrs, elements and unused' do
86
+ e = element('ROOT', '', {"k1" => "v1", "k2" => "v2", "k4" => "v4"}, [
87
+ element('test', 'mydata', {'k3' => 'v3'}, [])
88
+ ], "k3")
89
+ assert_equal("k3", e.unused)
90
+ assert_equal('ROOT', e.name)
91
+ assert_equal('', e.arg)
92
+ assert_equal('v1', e["k1"])
93
+ assert_equal('v2', e["k2"])
94
+ assert_equal('v4', e["k4"])
95
+ assert_equal(1, e.elements.size)
96
+ e.each_element('test') do |el|
97
+ assert_equal('test', el.name)
98
+ assert_equal('mydata', el.arg)
99
+ assert_equal('v3', el["k3"])
100
+ end
101
+ assert_equal("k3", e.unused)
102
+ end
103
+ end
104
+
105
+ sub_test_case "@unused" do
106
+ sub_test_case '#[] has side effect for @unused' do
107
+ test 'without unused argument' do
108
+ e = element('ROOT', '', {"k1" => "v1", "k2" => "v2", "k4" => "v4"}, [
109
+ element('test', 'mydata', {'k3' => 'v3'}, [])
110
+ ])
111
+ assert_equal(["k1", "k2", "k4"], e.unused)
112
+ assert_equal('v1', e["k1"])
113
+ assert_equal(["k2", "k4"], e.unused)
114
+ assert_equal('v2', e["k2"])
115
+ assert_equal(["k4"], e.unused)
116
+ assert_equal('v4', e["k4"])
117
+ assert_equal([], e.unused)
118
+ end
119
+
120
+ test 'with unused argument' do
121
+ e = element('ROOT', '', {"k1" => "v1", "k2" => "v2", "k4" => "v4"}, [
122
+ element('test', 'mydata', {'k3' => 'v3'}, [])
123
+ ], ["k4"])
124
+ assert_equal(["k4"], e.unused)
125
+ assert_equal('v1', e["k1"])
126
+ assert_equal(["k4"], e.unused)
127
+ assert_equal('v2', e["k2"])
128
+ assert_equal(["k4"], e.unused)
129
+ assert_equal('v4', e["k4"])
130
+ # only consume for "k4"
131
+ assert_equal([], e.unused)
132
+ end
133
+ end
134
+ end
135
+
136
+ sub_test_case '#add_element' do
137
+ test 'elements can be set by #add_element' do
138
+ e = element()
139
+ assert_equal [], e.elements
140
+
141
+ e.add_element('e1', '')
142
+ e.add_element('e2', '')
143
+ assert_equal [element('e1', ''), element('e2', '')], e.elements
144
+ end
145
+ end
146
+
147
+ sub_test_case '#==' do
148
+ sub_test_case 'compare with two element objects' do
149
+ test 'equal' do
150
+ e1 = element('ROOT', '', {}, [])
151
+ e2 = element('ROOT', '', {}, [])
152
+ assert_true(e1 == e2)
153
+ end
154
+
155
+ data("differ args" => [Fluent::Config::Element.new('ROOT', '', {}, []),
156
+ Fluent::Config::Element.new('ROOT', 'mydata', {}, [])],
157
+ "differ keys" => [Fluent::Config::Element.new('ROOT', 'mydata', {}, []),
158
+ Fluent::Config::Element.new('ROOT', 'mydata', {"k1" => "v1"}, [])],
159
+ "differ elemnts" =>
160
+ [Fluent::Config::Element.new('ROOT', 'mydata', {"k1" => "v1"}, []),
161
+ Fluent::Config::Element.new('ROOT', 'mydata', {"k1" => "v1"}, [
162
+ Fluent::Config::Element.new('test', 'mydata', {'k3' => 'v3'}, [])
163
+ ])])
164
+ test 'not equal' do |data|
165
+ e1, e2 = data
166
+ assert_false(e1 == e2)
167
+ end
168
+ end
169
+ end
170
+
171
+ sub_test_case '#+' do
172
+ test 'can merge 2 elements: object side is primary' do
173
+ e1 = element('ROOT', 'mydata', {"k1" => "v1"}, [])
174
+ e2 = element('ROOT', 'mydata2', {"k1" => "ignored", "k2" => "v2"}, [
175
+ element('test', 'ext', {'k3' => 'v3'}, [])
176
+ ])
177
+ e = e1 + e2
178
+
179
+ assert_equal('ROOT', e.name)
180
+ assert_equal('mydata', e.arg)
181
+ assert_equal('v1', e['k1'])
182
+ assert_equal('v2', e['k2'])
183
+ assert_equal(1, e.elements.size)
184
+ e.each_element('test') do |el|
185
+ assert_equal('test', el.name)
186
+ assert_equal('ext', el.arg)
187
+ assert_equal('v3', el["k3"])
188
+ end
189
+ end
190
+ end
191
+
192
+ sub_test_case '#check_not_fetched' do
193
+ sub_test_case 'without unused' do
194
+ test 'can get attribute keys and original Config::Element' do
195
+ e = element('ROOT', 'mydata', {"k1" => "v1"}, [])
196
+ e.check_not_fetched { |key, elem|
197
+ assert_equal("k1", key)
198
+ assert_equal(e, elem)
199
+ }
200
+ end
201
+ end
202
+
203
+ sub_test_case 'with unused' do
204
+ test 'can get unused marked attribute keys and original Config::Element' do
205
+ e = element('ROOT', 'mydata', {"k1" => "v1", "k2" => "unused", "k3" => "k3"})
206
+ e.unused = "k2"
207
+ e.check_not_fetched { |key, elem|
208
+ assert_equal("k2", key)
209
+ assert_equal(e, elem)
210
+ }
211
+ end
212
+ end
213
+ end
214
+
215
+ sub_test_case '#has_key?' do
216
+ test 'can get boolean with key name' do
217
+ e = element('ROOT', 'mydata', {"k1" => "v1"}, [])
218
+ assert_true(e.has_key?("k1"))
219
+ assert_false(e.has_key?("noexistent"))
220
+ end
221
+ end
222
+
223
+
224
+ sub_test_case '#to_s' do
225
+ data("without v1_config" => [false, <<-CONF
226
+ <ROOT>
227
+ k1 v1
228
+ k2 "stringVal"
229
+ <test ext>
230
+ k2 v2
231
+ </test>
232
+ </ROOT>
233
+ CONF
234
+ ],
235
+ "with v1_config" => [true, <<-CONF
236
+ <ROOT>
237
+ k1 v1
238
+ k2 "stringVal"
239
+ <test ext>
240
+ k2 v2
241
+ </test>
242
+ </ROOT>
243
+ CONF
244
+ ],
245
+ )
246
+ test 'dump config element with #to_s' do |data|
247
+ v1_config, expected = data
248
+ e = element('ROOT', '', {'k1' => 'v1', "k2" =>"\"stringVal\""}, [
249
+ element('test', 'ext', {'k2' => 'v2'}, [])
250
+ ])
251
+ e.v1_config = v1_config
252
+ dump = expected
253
+ assert_not_equal(e.inspect, e.to_s)
254
+ assert_equal(dump, e.to_s)
255
+ end
256
+ end
257
+
258
+ sub_test_case '#inspect' do
259
+ test 'dump config element with #inspect' do
260
+ e = element('ROOT', '', {'k1' => 'v1'}, [
261
+ element('test', 'ext', {'k2' => 'v2'}, [])
262
+ ])
263
+ dump = <<-CONF
264
+ name:ROOT, arg:, {\"k1\"=>\"v1\"}, [name:test, arg:ext, {\"k2\"=>\"v2\"}, []]
265
+ CONF
266
+ assert_not_equal(e.to_s, e.inspect)
267
+ assert_equal(dump.chomp, e.inspect)
268
+ end
269
+ end
270
+
271
+ sub_test_case 'for sections which has secret parameter' do
272
+ setup do
273
+ @type_lookup = ->(type){ Fluent::Configurable.lookup_type(type) }
274
+ p1 = Fluent::Config::ConfigureProxy.new(:match, type_lookup: @type_lookup)
275
+ p1.config_param :str1, :string
276
+ p1.config_param :str2, :string, secret: true
277
+ p1.config_param :enum1, :enum, list: [:a, :b, :c]
278
+ p1.config_param :enum2, :enum, list: [:a, :b, :c], secret: true
279
+ p1.config_param :bool1, :bool
280
+ p1.config_param :bool2, :bool, secret: true
281
+ p1.config_param :int1, :integer
282
+ p1.config_param :int2, :integer, secret: true
283
+ p1.config_param :float1, :float
284
+ p1.config_param :float2, :float, secret: true
285
+ p2 = Fluent::Config::ConfigureProxy.new(:match, type_lookup: @type_lookup)
286
+ p2.config_param :size1, :size
287
+ p2.config_param :size2, :size, secret: true
288
+ p2.config_param :time1, :time
289
+ p2.config_param :time2, :time, secret: true
290
+ p2.config_param :array1, :array
291
+ p2.config_param :array2, :array, secret: true
292
+ p2.config_param :hash1, :hash
293
+ p2.config_param :hash2, :hash, secret: true
294
+ p1.config_section :mysection do
295
+ config_param :str1, :string
296
+ config_param :str2, :string, secret: true
297
+ config_param :enum1, :enum, list: [:a, :b, :c]
298
+ config_param :enum2, :enum, list: [:a, :b, :c], secret: true
299
+ config_param :bool1, :bool
300
+ config_param :bool2, :bool, secret: true
301
+ config_param :int1, :integer
302
+ config_param :int2, :integer, secret: true
303
+ config_param :float1, :float
304
+ config_param :float2, :float, secret: true
305
+ config_param :size1, :size
306
+ config_param :size2, :size, secret: true
307
+ config_param :time1, :time
308
+ config_param :time2, :time, secret: true
309
+ config_param :array1, :array
310
+ config_param :array2, :array, secret: true
311
+ config_param :hash1, :hash
312
+ config_param :hash2, :hash, secret: true
313
+ end
314
+ params = {
315
+ 'str1' => 'aaa', 'str2' => 'bbb', 'enum1' => 'a', 'enum2' => 'b', 'bool1' => 'true', 'bool2' => 'yes',
316
+ 'int1' => '1', 'int2' => '2', 'float1' => '1.0', 'float2' => '0.5', 'size1' => '1k', 'size2' => '1m',
317
+ 'time1' => '5m', 'time2' => '3h', 'array1' => 'a,b,c', 'array2' => 'd,e,f',
318
+ 'hash1' => 'a:1,b:2', 'hash2' => 'a:2,b:4',
319
+ 'unknown1' => 'yay', 'unknown2' => 'boo',
320
+ }
321
+ e2 = Fluent::Config::Element.new('mysection', '', params.dup, [])
322
+ e2.corresponding_proxies << p1.sections.values.first
323
+ @e = Fluent::Config::Element.new('match', '**', params, [e2])
324
+ @e.corresponding_proxies << p1
325
+ @e.corresponding_proxies << p2
326
+ end
327
+
328
+ sub_test_case '#to_masked_element' do
329
+ test 'returns a new element object which has masked values for secret parameters and elements' do
330
+ e = @e.to_masked_element
331
+ assert_equal 'aaa', e['str1']
332
+ assert_equal 'xxxxxx', e['str2']
333
+ assert_equal 'a', e['enum1']
334
+ assert_equal 'xxxxxx', e['enum2']
335
+ assert_equal 'true', e['bool1']
336
+ assert_equal 'xxxxxx', e['bool2']
337
+ assert_equal '1', e['int1']
338
+ assert_equal 'xxxxxx', e['int2']
339
+ assert_equal '1.0', e['float1']
340
+ assert_equal 'xxxxxx', e['float2']
341
+ assert_equal '1k', e['size1']
342
+ assert_equal 'xxxxxx', e['size2']
343
+ assert_equal '5m', e['time1']
344
+ assert_equal 'xxxxxx', e['time2']
345
+ assert_equal 'a,b,c', e['array1']
346
+ assert_equal 'xxxxxx', e['array2']
347
+ assert_equal 'a:1,b:2', e['hash1']
348
+ assert_equal 'xxxxxx', e['hash2']
349
+ assert_equal 'yay', e['unknown1']
350
+ assert_equal 'boo', e['unknown2']
351
+ e2 = e.elements.first
352
+ assert_equal 'aaa', e2['str1']
353
+ assert_equal 'xxxxxx', e2['str2']
354
+ assert_equal 'a', e2['enum1']
355
+ assert_equal 'xxxxxx', e2['enum2']
356
+ assert_equal 'true', e2['bool1']
357
+ assert_equal 'xxxxxx', e2['bool2']
358
+ assert_equal '1', e2['int1']
359
+ assert_equal 'xxxxxx', e2['int2']
360
+ assert_equal '1.0', e2['float1']
361
+ assert_equal 'xxxxxx', e2['float2']
362
+ assert_equal '1k', e2['size1']
363
+ assert_equal 'xxxxxx', e2['size2']
364
+ assert_equal '5m', e2['time1']
365
+ assert_equal 'xxxxxx', e2['time2']
366
+ assert_equal 'a,b,c', e2['array1']
367
+ assert_equal 'xxxxxx', e2['array2']
368
+ assert_equal 'a:1,b:2', e2['hash1']
369
+ assert_equal 'xxxxxx', e2['hash2']
370
+ assert_equal 'yay', e2['unknown1']
371
+ assert_equal 'boo', e2['unknown2']
372
+ end
373
+ end
374
+
375
+ sub_test_case '#secret_param?' do
376
+ test 'returns boolean which shows values of given key will be masked' do
377
+ assert !@e.secret_param?('str1')
378
+ assert @e.secret_param?('str2')
379
+ assert !@e.elements.first.secret_param?('str1')
380
+ assert @e.elements.first.secret_param?('str2')
381
+ end
382
+ end
383
+
384
+ sub_test_case '#param_type' do
385
+ test 'returns parameter type which are registered in corresponding proxy' do
386
+ assert_equal :string, @e.param_type('str1')
387
+ assert_equal :string, @e.param_type('str2')
388
+ assert_equal :enum, @e.param_type('enum1')
389
+ assert_equal :enum, @e.param_type('enum2')
390
+ assert_nil @e.param_type('unknown1')
391
+ assert_nil @e.param_type('unknown2')
392
+ end
393
+ end
394
+
395
+ # sub_test_case '#dump_value'
396
+ sub_test_case '#dump_value' do
397
+ test 'dumps parameter_name and values with leading indentation' do
398
+ assert_equal "str1 aaa\n", @e.dump_value("str1", @e["str1"], "")
399
+ assert_equal "str2 xxxxxx\n", @e.dump_value("str2", @e["str2"], "")
400
+ end
401
+ end
402
+ end
403
+ end
@@ -0,0 +1,297 @@
1
+ require_relative "../helper"
2
+ require_relative 'assertions'
3
+ require "fluent/config/error"
4
+ require "fluent/config/literal_parser"
5
+ require "fluent/config/v1_parser"
6
+ require 'json'
7
+
8
+ module Fluent::Config
9
+ class TestLiteralParser < ::Test::Unit::TestCase
10
+ def parse_text(text)
11
+ basepath = File.expand_path(File.dirname(__FILE__)+'/../../')
12
+ ss = StringScanner.new(text)
13
+ parser = Fluent::Config::V1Parser.new(ss, basepath, "(test)", eval_context)
14
+ parser.parse_literal
15
+ end
16
+
17
+ TestLiteralParserContext = Struct.new(:v1, :v2, :v3)
18
+
19
+ def v1
20
+ :test
21
+ end
22
+
23
+ def v2
24
+ true
25
+ end
26
+
27
+ def v3
28
+ nil
29
+ end
30
+
31
+ def eval_context
32
+ @eval_context ||= TestLiteralParserContext.new(v1, v2, v3)
33
+ end
34
+
35
+ sub_test_case 'boolean parsing' do
36
+ def test_true
37
+ assert_text_parsed_as('true', "true")
38
+ end
39
+ def test_false
40
+ assert_text_parsed_as('false', "false")
41
+ end
42
+ def test_trueX
43
+ assert_text_parsed_as('trueX', "trueX")
44
+ end
45
+ def test_falseX
46
+ assert_text_parsed_as('falseX', "falseX")
47
+ end
48
+ end
49
+
50
+ sub_test_case 'integer parsing' do
51
+ test('0') { assert_text_parsed_as('0', "0") }
52
+ test('1') { assert_text_parsed_as('1', "1") }
53
+ test('10') { assert_text_parsed_as('10', "10") }
54
+ test('-1') { assert_text_parsed_as('-1', "-1") }
55
+ test('-10') { assert_text_parsed_as('-10', "-10") }
56
+ test('0 ') { assert_text_parsed_as('0', "0 ") }
57
+ test(' -1 ') { assert_text_parsed_as("-1", ' -1 ') }
58
+ # string
59
+ test('01') { assert_text_parsed_as('01', "01") }
60
+ test('00') { assert_text_parsed_as('00', "00") }
61
+ test('-01') { assert_text_parsed_as('-01', "-01") }
62
+ test('-00') { assert_text_parsed_as('-00', "-00") }
63
+ test('0x61') { assert_text_parsed_as('0x61', "0x61") }
64
+ test('0s') { assert_text_parsed_as('0s', "0s") }
65
+ end
66
+
67
+ sub_test_case 'float parsing' do
68
+ test('1.1') { assert_text_parsed_as('1.1', "1.1") }
69
+ test('0.1') { assert_text_parsed_as('0.1', "0.1") }
70
+ test('0.0') { assert_text_parsed_as('0.0', "0.0") }
71
+ test('-1.1') { assert_text_parsed_as('-1.1', "-1.1") }
72
+ test('-0.1') { assert_text_parsed_as('-0.1', "-0.1") }
73
+ test('1.10') { assert_text_parsed_as('1.10', "1.10") }
74
+ # string
75
+ test('12e8') { assert_text_parsed_as('12e8', "12e8") }
76
+ test('12.1e7') { assert_text_parsed_as('12.1e7', "12.1e7") }
77
+ test('-12e8') { assert_text_parsed_as('-12e8', "-12e8") }
78
+ test('-12.1e7') { assert_text_parsed_as('-12.1e7', "-12.1e7") }
79
+ test('.0') { assert_text_parsed_as('.0', ".0") }
80
+ test('.1') { assert_text_parsed_as('.1', ".1") }
81
+ test('0.') { assert_text_parsed_as('0.', "0.") }
82
+ test('1.') { assert_text_parsed_as('1.', "1.") }
83
+ test('.0a') { assert_text_parsed_as('.0a', ".0a") }
84
+ test('1.a') { assert_text_parsed_as('1.a', "1.a") }
85
+ test('0@') { assert_text_parsed_as('0@', "0@") }
86
+ end
87
+
88
+ sub_test_case 'float keywords parsing' do
89
+ test('NaN') { assert_text_parsed_as('NaN', "NaN") }
90
+ test('Infinity') { assert_text_parsed_as('Infinity', "Infinity") }
91
+ test('-Infinity') { assert_text_parsed_as('-Infinity', "-Infinity") }
92
+ test('NaNX') { assert_text_parsed_as('NaNX', "NaNX") }
93
+ test('InfinityX') { assert_text_parsed_as('InfinityX', "InfinityX") }
94
+ test('-InfinityX') { assert_text_parsed_as('-InfinityX', "-InfinityX") }
95
+ end
96
+
97
+ sub_test_case 'double quoted string' do
98
+ test('""') { assert_text_parsed_as("", '""') }
99
+ test('"text"') { assert_text_parsed_as("text", '"text"') }
100
+ test('"\\""') { assert_text_parsed_as("\"", '"\\""') }
101
+ test('"\\t"') { assert_text_parsed_as("\t", '"\\t"') }
102
+ test('"\\n"') { assert_text_parsed_as("\n", '"\\n"') }
103
+ test('"\\r\\n"') { assert_text_parsed_as("\r\n", '"\\r\\n"') }
104
+ test('"\\f\\b"') { assert_text_parsed_as("\f\b", '"\\f\\b"') }
105
+ test('"\\.t"') { assert_text_parsed_as(".t", '"\\.t"') }
106
+ test('"\\$t"') { assert_text_parsed_as("$t", '"\\$t"') }
107
+ test('"\\"') { assert_text_parsed_as("#t", '"\\#t"') }
108
+ test('"\\z"') { assert_parse_error('"\\z"') } # unknown escaped character
109
+ test('"\\0"') { assert_parse_error('"\\0"') } # unknown escaped character
110
+ test('"\\1"') { assert_parse_error('"\\1"') } # unknown escaped character
111
+ test('"t') { assert_parse_error('"t') } # non-terminated quoted character
112
+ test("\"t\nt\"") { assert_text_parsed_as("t\nt", "\"t\nt\"" ) } # multiline string
113
+ test("\"t\\\nt\"") { assert_text_parsed_as("tt", "\"t\\\nt\"" ) } # multiline string
114
+ test('t"') { assert_text_parsed_as('t"', 't"') }
115
+ test('"."') { assert_text_parsed_as('.', '"."') }
116
+ test('"*"') { assert_text_parsed_as('*', '"*"') }
117
+ test('"@"') { assert_text_parsed_as('@', '"@"') }
118
+ test('"\\#{test}"') { assert_text_parsed_as("\#{test}", '"\\#{test}"') }
119
+ test('"$"') { assert_text_parsed_as('$', '"$"') }
120
+ test('"$t"') { assert_text_parsed_as('$t', '"$t"') }
121
+ test('"$}"') { assert_text_parsed_as('$}', '"$}"') }
122
+ test('"\\\\"') { assert_text_parsed_as("\\", '"\\\\"') }
123
+ test('"\\["') { assert_text_parsed_as("[", '"\\["') }
124
+ end
125
+
126
+ sub_test_case 'single quoted string' do
127
+ test("''") { assert_text_parsed_as("", "''") }
128
+ test("'text'") { assert_text_parsed_as("text", "'text'") }
129
+ test("'\\''") { assert_text_parsed_as('\'', "'\\''") }
130
+ test("'\\t'") { assert_text_parsed_as('\t', "'\\t'") }
131
+ test("'\\n'") { assert_text_parsed_as('\n', "'\\n'") }
132
+ test("'\\r\\n'") { assert_text_parsed_as('\r\n', "'\\r\\n'") }
133
+ test("'\\f\\b'") { assert_text_parsed_as('\f\b', "'\\f\\b'") }
134
+ test("'\\.t'") { assert_text_parsed_as('\.t', "'\\.t'") }
135
+ test("'\\$t'") { assert_text_parsed_as('\$t', "'\\$t'") }
136
+ test("'\\#t'") { assert_text_parsed_as('\#t', "'\\#t'") }
137
+ test("'\\z'") { assert_text_parsed_as('\z', "'\\z'") }
138
+ test("'\\0'") { assert_text_parsed_as('\0', "'\\0'") }
139
+ test("'\\1'") { assert_text_parsed_as('\1', "'\\1'") }
140
+ test("'t") { assert_parse_error("'t") } # non-terminated quoted character
141
+ test("t'") { assert_text_parsed_as("t'", "t'") }
142
+ test("'.'") { assert_text_parsed_as('.', "'.'") }
143
+ test("'*'") { assert_text_parsed_as('*', "'*'") }
144
+ test("'@'") { assert_text_parsed_as('@', "'@'") }
145
+ test(%q['#{test}']) { assert_text_parsed_as('#{test}', %q['#{test}']) }
146
+ test("'$'") { assert_text_parsed_as('$', "'$'") }
147
+ test("'$t'") { assert_text_parsed_as('$t', "'$t'") }
148
+ test("'$}'") { assert_text_parsed_as('$}', "'$}'") }
149
+ test("'\\\\'") { assert_text_parsed_as('\\', "'\\\\'") }
150
+ test("'\\['") { assert_text_parsed_as('\[', "'\\['") }
151
+ end
152
+
153
+ sub_test_case 'nonquoted string parsing' do
154
+ test("''") { assert_text_parsed_as(nil, '') }
155
+ test('text') { assert_text_parsed_as('text', 'text') }
156
+ test('\"') { assert_text_parsed_as('\"', '\"') }
157
+ test('\t') { assert_text_parsed_as('\t', '\t') }
158
+ test('\n') { assert_text_parsed_as('\n', '\n') }
159
+ test('\r\n') { assert_text_parsed_as('\r\n', '\r\n') }
160
+ test('\f\b') { assert_text_parsed_as('\f\b', '\f\b') }
161
+ test('\.t') { assert_text_parsed_as('\.t', '\.t') }
162
+ test('\$t') { assert_text_parsed_as('\$t', '\$t') }
163
+ test('\#t') { assert_text_parsed_as('\#t', '\#t') }
164
+ test('\z') { assert_text_parsed_as('\z', '\z') }
165
+ test('\0') { assert_text_parsed_as('\0', '\0') }
166
+ test('\1') { assert_text_parsed_as('\1', '\1') }
167
+ test('.') { assert_text_parsed_as('.', '.') }
168
+ test('*') { assert_text_parsed_as('*', '*') }
169
+ test('@') { assert_text_parsed_as('@', '@') }
170
+ test('#{test}') { assert_text_parsed_as('#{test}', '#{test}') }
171
+ test('$') { assert_text_parsed_as('$', '$') }
172
+ test('$t') { assert_text_parsed_as('$t', '$t') }
173
+ test('$}') { assert_text_parsed_as('$}', '$}') }
174
+ test('\\\\') { assert_text_parsed_as('\\\\', '\\\\') }
175
+ test('\[') { assert_text_parsed_as('\[', '\[') }
176
+ test('#foo') { assert_text_parsed_as('#foo', '#foo') } # not comment out
177
+ test('foo#bar') { assert_text_parsed_as('foo#bar', 'foo#bar') } # not comment out
178
+ test(' text') { assert_text_parsed_as('text', ' text') } # remove starting spaces
179
+ test(' #foo') { assert_text_parsed_as('#foo', ' #foo') } # remove starting spaces
180
+ test('foo #bar') { assert_text_parsed_as('foo', 'foo #bar') } # comment out
181
+ test('foo\t#bar') { assert_text_parsed_as('foo', "foo\t#bar") } # comment out
182
+
183
+ test('t') { assert_text_parsed_as('t', 't') }
184
+ test('T') { assert_text_parsed_as('T', 'T') }
185
+ test('_') { assert_text_parsed_as('_', '_') }
186
+ test('T1') { assert_text_parsed_as('T1', 'T1') }
187
+ test('_2') { assert_text_parsed_as('_2', '_2') }
188
+ test('t0') { assert_text_parsed_as('t0', 't0') }
189
+ test('t@') { assert_text_parsed_as('t@', 't@') }
190
+ test('t-') { assert_text_parsed_as('t-', 't-') }
191
+ test('t.') { assert_text_parsed_as('t.', 't.') }
192
+ test('t+') { assert_text_parsed_as('t+', 't+') }
193
+ test('t/') { assert_text_parsed_as('t/', 't/') }
194
+ test('t=') { assert_text_parsed_as('t=', 't=') }
195
+ test('t,') { assert_text_parsed_as('t,', 't,') }
196
+ test('0t') { assert_text_parsed_as('0t', "0t") }
197
+ test('@1t') { assert_text_parsed_as('@1t', '@1t') }
198
+ test('-1t') { assert_text_parsed_as('-1t', '-1t') }
199
+ test('.1t') { assert_text_parsed_as('.1t', '.1t') }
200
+ test(',1t') { assert_text_parsed_as(',1t', ',1t') }
201
+ test('.t') { assert_text_parsed_as('.t', '.t') }
202
+ test('*t') { assert_text_parsed_as('*t', '*t') }
203
+ test('@t') { assert_text_parsed_as('@t', '@t') }
204
+ test('{t') { assert_parse_error('{t') } # '{' begins map
205
+ test('t{') { assert_text_parsed_as('t{', 't{') }
206
+ test('}t') { assert_text_parsed_as('}t', '}t') }
207
+ test('[t') { assert_parse_error('[t') } # '[' begins array
208
+ test('t[') { assert_text_parsed_as('t[', 't[') }
209
+ test(']t') { assert_text_parsed_as(']t', ']t') }
210
+ test('t:') { assert_text_parsed_as('t:', 't:') }
211
+ test('t;') { assert_text_parsed_as('t;', 't;') }
212
+ test('t?') { assert_text_parsed_as('t?', 't?') }
213
+ test('t^') { assert_text_parsed_as('t^', 't^') }
214
+ test('t`') { assert_text_parsed_as('t`', 't`') }
215
+ test('t~') { assert_text_parsed_as('t~', 't~') }
216
+ test('t|') { assert_text_parsed_as('t|', 't|') }
217
+ test('t>') { assert_text_parsed_as('t>', 't>') }
218
+ test('t<') { assert_text_parsed_as('t<', 't<') }
219
+ test('t(') { assert_text_parsed_as('t(', 't(') }
220
+ end
221
+
222
+ sub_test_case 'embedded ruby code parsing' do
223
+ test('"#{v1}"') { assert_text_parsed_as("#{v1}", '"#{v1}"') }
224
+ test('"#{v2}"') { assert_text_parsed_as("#{v2}", '"#{v2}"') }
225
+ test('"#{v3}"') { assert_text_parsed_as("#{v3}", '"#{v3}"') }
226
+ test('"#{1+1}"') { assert_text_parsed_as("2", '"#{1+1}"') }
227
+ test('"#{}"') { assert_text_parsed_as("", '"#{}"') }
228
+ test('"t#{v1}"') { assert_text_parsed_as("t#{v1}", '"t#{v1}"') }
229
+ test('"t#{v1}t"') { assert_text_parsed_as("t#{v1}t", '"t#{v1}t"') }
230
+ test('"#{"}"}"') { assert_text_parsed_as("}", '"#{"}"}"') }
231
+ test('"#{#}"') { assert_parse_error('"#{#}"') } # error in embedded ruby code
232
+ test("\"\#{\n=begin\n}\"") { assert_parse_error("\"\#{\n=begin\n}\"") } # error in embedded ruby code
233
+ test('"#{v1}foo#{v2}"') { assert_text_parsed_as("#{v1}foo#{v2}", '"#{v1}foo#{v2}"') }
234
+ test('"#{1+1}foo#{2+2}bar"') { assert_text_parsed_as("#{1+1}foo#{2+2}bar", '"#{1+1}foo#{2+2}bar"') }
235
+ end
236
+
237
+ sub_test_case 'array parsing' do
238
+ test('[]') { assert_text_parsed_as_json([], '[]') }
239
+ test('[1]') { assert_text_parsed_as_json([1], '[1]') }
240
+ test('[1,2]') { assert_text_parsed_as_json([1,2], '[1,2]') }
241
+ test('[1, 2]') { assert_text_parsed_as_json([1,2], '[1, 2]') }
242
+ test('[ 1 , 2 ]') { assert_text_parsed_as_json([1,2], '[ 1 , 2 ]') }
243
+ test('[1,2,]') { assert_parse_error('[1,2,]') } # TODO: Need trailing commas support?
244
+ test("[\n1\n,\n2\n]") { assert_text_parsed_as_json([1,2], "[\n1\n,\n2\n]") }
245
+ test('["a"]') { assert_text_parsed_as_json(["a"], '["a"]') }
246
+ test('["a","b"]') { assert_text_parsed_as_json(["a","b"], '["a","b"]') }
247
+ test('[ "a" , "b" ]') { assert_text_parsed_as_json(["a","b"], '[ "a" , "b" ]') }
248
+ test("[\n\"a\"\n,\n\"b\"\n]") { assert_text_parsed_as_json(["a","b"], "[\n\"a\"\n,\n\"b\"\n]") }
249
+ test('["ab","cd"]') { assert_text_parsed_as_json(["ab","cd"], '["ab","cd"]') }
250
+ json_array_with_js_comment = <<EOA
251
+ [
252
+ "a", // this is a
253
+ "b", // this is b
254
+ "c" // this is c
255
+ ]
256
+ EOA
257
+ test(json_array_with_js_comment) { assert_text_parsed_as_json(["a","b","c"], json_array_with_js_comment) }
258
+ json_array_with_comment = <<EOA
259
+ [
260
+ "a", # this is a
261
+ "b", # this is b
262
+ "c" # this is c
263
+ ]
264
+ EOA
265
+ test(json_array_with_comment) { assert_text_parsed_as_json(["a","b","c"], json_array_with_comment) }
266
+ json_array_with_tailing_comma = <<EOA
267
+ [
268
+ "a", # this is a
269
+ "b", # this is b
270
+ "c", # this is c
271
+ ]
272
+ EOA
273
+ test(json_array_with_tailing_comma) { assert_parse_error(json_array_with_tailing_comma) }
274
+ end
275
+
276
+ sub_test_case 'map parsing' do
277
+ test('{}') { assert_text_parsed_as_json({}, '{}') }
278
+ test('{"a":1}') { assert_text_parsed_as_json({"a"=>1}, '{"a":1}') }
279
+ test('{"a":1,"b":2}') { assert_text_parsed_as_json({"a"=>1,"b"=>2}, '{"a":1,"b":2}') }
280
+ test('{ "a" : 1 , "b" : 2 }') { assert_text_parsed_as_json({"a"=>1,"b"=>2}, '{ "a" : 1 , "b" : 2 }') }
281
+ test('{"a":1,"b":2,}') { assert_parse_error('{"a":1,"b":2,}') } # TODO: Need trailing commas support?
282
+ test('{\n\"a\"\n:\n1\n,\n\"b\"\n:\n2\n}') { assert_text_parsed_as_json({"a"=>1,"b"=>2}, "{\n\"a\"\n:\n1\n,\n\"b\"\n:\n2\n}") }
283
+ test('{"a":"b"}') { assert_text_parsed_as_json({"a"=>"b"}, '{"a":"b"}') }
284
+ test('{"a":"b","c":"d"}') { assert_text_parsed_as_json({"a"=>"b","c"=>"d"}, '{"a":"b","c":"d"}') }
285
+ test('{ "a" : "b" , "c" : "d" }') { assert_text_parsed_as_json({"a"=>"b","c"=>"d"}, '{ "a" : "b" , "c" : "d" }') }
286
+ test('{\n\"a\"\n:\n\"b\"\n,\n\"c\"\n:\n\"d\"\n}') { assert_text_parsed_as_json({"a"=>"b","c"=>"d"}, "{\n\"a\"\n:\n\"b\"\n,\n\"c\"\n:\n\"d\"\n}") }
287
+ json_hash_with_comment = <<EOH
288
+ {
289
+ "a": 1, # this is a
290
+ "b": 2, # this is b
291
+ "c": 3 # this is c
292
+ }
293
+ EOH
294
+ test(json_hash_with_comment) { assert_text_parsed_as_json({"a"=>1,"b"=>2,"c"=>3}, json_hash_with_comment) }
295
+ end
296
+ end
297
+ end