i18n_flow 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +13 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +45 -0
  8. data/LICENSE +22 -0
  9. data/README.md +103 -0
  10. data/Rakefile +2 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/doc/rules.md +316 -0
  14. data/doc/tags.md +488 -0
  15. data/example/example.en.yml +14 -0
  16. data/example/example.ja.yml +9 -0
  17. data/exe/i18n_flow +11 -0
  18. data/i18n_flow.gemspec +28 -0
  19. data/i18n_flow.yml +8 -0
  20. data/lib/i18n_flow/cli/color.rb +18 -0
  21. data/lib/i18n_flow/cli/command_base.rb +33 -0
  22. data/lib/i18n_flow/cli/copy_command.rb +69 -0
  23. data/lib/i18n_flow/cli/help_command.rb +29 -0
  24. data/lib/i18n_flow/cli/lint_command/ascii.erb +45 -0
  25. data/lib/i18n_flow/cli/lint_command/ascii_renderer.rb +58 -0
  26. data/lib/i18n_flow/cli/lint_command/markdown.erb +49 -0
  27. data/lib/i18n_flow/cli/lint_command/markdown_renderer.rb +55 -0
  28. data/lib/i18n_flow/cli/lint_command.rb +55 -0
  29. data/lib/i18n_flow/cli/read_config_command.rb +20 -0
  30. data/lib/i18n_flow/cli/search_command/default.erb +11 -0
  31. data/lib/i18n_flow/cli/search_command/default_renderer.rb +67 -0
  32. data/lib/i18n_flow/cli/search_command/oneline.erb +5 -0
  33. data/lib/i18n_flow/cli/search_command/oneline_renderer.rb +39 -0
  34. data/lib/i18n_flow/cli/search_command.rb +59 -0
  35. data/lib/i18n_flow/cli/split_command.rb +20 -0
  36. data/lib/i18n_flow/cli/version_command.rb +9 -0
  37. data/lib/i18n_flow/cli.rb +42 -0
  38. data/lib/i18n_flow/configuration.rb +205 -0
  39. data/lib/i18n_flow/parser.rb +34 -0
  40. data/lib/i18n_flow/repository.rb +39 -0
  41. data/lib/i18n_flow/search.rb +176 -0
  42. data/lib/i18n_flow/splitter/merger.rb +60 -0
  43. data/lib/i18n_flow/splitter/strategy.rb +66 -0
  44. data/lib/i18n_flow/splitter.rb +5 -0
  45. data/lib/i18n_flow/util.rb +57 -0
  46. data/lib/i18n_flow/validator/errors.rb +99 -0
  47. data/lib/i18n_flow/validator/file_scope.rb +58 -0
  48. data/lib/i18n_flow/validator/multiplexer.rb +58 -0
  49. data/lib/i18n_flow/validator/symmetry.rb +154 -0
  50. data/lib/i18n_flow/validator.rb +4 -0
  51. data/lib/i18n_flow/version.rb +7 -0
  52. data/lib/i18n_flow/yaml_ast_proxy/mapping.rb +72 -0
  53. data/lib/i18n_flow/yaml_ast_proxy/node.rb +128 -0
  54. data/lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb +86 -0
  55. data/lib/i18n_flow/yaml_ast_proxy/sequence.rb +29 -0
  56. data/lib/i18n_flow/yaml_ast_proxy.rb +57 -0
  57. data/lib/i18n_flow.rb +15 -0
  58. data/spec/lib/i18n_flow/cli/command_base_spec.rb +46 -0
  59. data/spec/lib/i18n_flow/cli/help_command_spec.rb +13 -0
  60. data/spec/lib/i18n_flow/cli/version_command_spec.rb +13 -0
  61. data/spec/lib/i18n_flow/configuration_spec.rb +334 -0
  62. data/spec/lib/i18n_flow/repository_spec.rb +40 -0
  63. data/spec/lib/i18n_flow/splitter/merger_spec.rb +149 -0
  64. data/spec/lib/i18n_flow/util_spec.rb +194 -0
  65. data/spec/lib/i18n_flow/validator/file_scope_spec.rb +74 -0
  66. data/spec/lib/i18n_flow/validator/multiplexer_spec.rb +68 -0
  67. data/spec/lib/i18n_flow/validator/symmetry_spec.rb +511 -0
  68. data/spec/lib/i18n_flow/yaml_ast_proxy/node_spec.rb +151 -0
  69. data/spec/lib/i18n_flow_spec.rb +21 -0
  70. data/spec/spec_helper.rb +16 -0
  71. data/spec/support/repository_examples.rb +60 -0
  72. data/spec/support/util_macro.rb +14 -0
  73. metadata +214 -0
@@ -0,0 +1,511 @@
1
+ require 'i18n_flow/validator/symmetry'
2
+ require 'i18n_flow/validator/errors'
3
+
4
+ describe I18nFlow::Validator::Symmetry do
5
+ let(:validator) { I18nFlow::Validator::Symmetry.new(nil, nil) }
6
+
7
+ describe '#validate' do
8
+ it 'should pass if the given trees are completely the same' do
9
+ ast_1 = parse_yaml(<<-YAML)['en']
10
+ en:
11
+ key_1: text_1
12
+ foo:
13
+ key_2: text_2
14
+ YAML
15
+ ast_2 = parse_yaml(<<-YAML)['ja']
16
+ ja:
17
+ key_1: text_1
18
+ foo:
19
+ key_2: text_2
20
+ YAML
21
+
22
+ allow(validator).to receive(:ast_1).and_return(ast_1)
23
+ allow(validator).to receive(:ast_2).and_return(ast_2)
24
+ validator.validate!
25
+
26
+ expect(validator.errors).to eq([])
27
+ end
28
+
29
+ context 'asymmetric key' do
30
+ it 'should detect' do
31
+ ast_1 = parse_yaml(<<-YAML)['en']
32
+ en:
33
+ key_1: text_1
34
+ key_2: text_2
35
+ YAML
36
+ ast_2 = parse_yaml(<<-YAML)['ja']
37
+ ja:
38
+ key_1: text_1
39
+ key_3: text_3
40
+ YAML
41
+
42
+ allow(validator).to receive(:ast_1).and_return(ast_1)
43
+ allow(validator).to receive(:ast_2).and_return(ast_2)
44
+ validator.validate!
45
+
46
+ expect(validator.errors).to eq([
47
+ I18nFlow::Validator::MissingKeyError.new('ja.key_2'),
48
+ I18nFlow::Validator::ExtraKeyError.new('ja.key_3'),
49
+ ])
50
+ end
51
+
52
+ it 'should detect on nested node' do
53
+ ast_1 = parse_yaml(<<-YAML)['en']
54
+ en:
55
+ key_1: text_1
56
+ foo:
57
+ key_2: text_2
58
+ YAML
59
+ ast_2 = parse_yaml(<<-YAML)['ja']
60
+ ja:
61
+ key_1: text_1
62
+ foo:
63
+ key_3: text_3
64
+ YAML
65
+
66
+ allow(validator).to receive(:ast_1).and_return(ast_1)
67
+ allow(validator).to receive(:ast_2).and_return(ast_2)
68
+ validator.validate!
69
+
70
+ expect(validator.errors).to eq([
71
+ I18nFlow::Validator::MissingKeyError.new('ja.foo.key_2'),
72
+ I18nFlow::Validator::ExtraKeyError.new('ja.foo.key_3'),
73
+ ])
74
+ end
75
+
76
+ it 'should suppress an error on the ignored node (value)' do
77
+ ast_1 = parse_yaml(<<-YAML)['en']
78
+ en:
79
+ key_1: text_1
80
+ key_2: text_2
81
+ YAML
82
+ ast_2 = parse_yaml(<<-YAML)['ja']
83
+ ja:
84
+ key_1: text_1
85
+ key_3: !ignore:key text_3
86
+ YAML
87
+
88
+ allow(validator).to receive(:ast_1).and_return(ast_1)
89
+ allow(validator).to receive(:ast_2).and_return(ast_2)
90
+ validator.validate!
91
+
92
+ expect(validator.errors).to eq([
93
+ I18nFlow::Validator::MissingKeyError.new('ja.key_2'),
94
+ ])
95
+ end
96
+
97
+ it 'should suppress an error on the ignored node (map)' do
98
+ ast_1 = parse_yaml(<<-YAML)['en']
99
+ en:
100
+ key_1: text_1
101
+ foo:
102
+ key_2: text_2
103
+ YAML
104
+ ast_2 = parse_yaml(<<-YAML)['ja']
105
+ ja:
106
+ key_1: text_1
107
+ foo: !ignore:key
108
+ key_3: text_3
109
+ YAML
110
+
111
+ allow(validator).to receive(:ast_1).and_return(ast_1)
112
+ allow(validator).to receive(:ast_2).and_return(ast_2)
113
+ validator.validate!
114
+
115
+ expect(validator.errors).to eq([])
116
+ end
117
+ end
118
+
119
+ context 'type mismatch' do
120
+ it 'should detect' do
121
+ ast_1 = parse_yaml(<<-YAML)['en']
122
+ en:
123
+ key_1: text_1
124
+ key_2: text_2
125
+ YAML
126
+ ast_2 = parse_yaml(<<-YAML)['ja']
127
+ ja:
128
+ key_1: text_1
129
+ key_2:
130
+ one: text_2
131
+ YAML
132
+
133
+ allow(validator).to receive(:ast_1).and_return(ast_1)
134
+ allow(validator).to receive(:ast_2).and_return(ast_2)
135
+ validator.validate!
136
+
137
+ expect(validator.errors).to eq([
138
+ I18nFlow::Validator::InvalidTypeError.new('ja.key_2'),
139
+ ])
140
+ end
141
+
142
+ it 'should detect on nested node' do
143
+ ast_1 = parse_yaml(<<-YAML)['en']
144
+ en:
145
+ key_1: text_1
146
+ foo:
147
+ key_2: text_2
148
+ YAML
149
+ ast_2 = parse_yaml(<<-YAML)['ja']
150
+ ja:
151
+ key_1: text_1
152
+ foo:
153
+ key_2:
154
+ one: text_2
155
+ YAML
156
+
157
+ allow(validator).to receive(:ast_1).and_return(ast_1)
158
+ allow(validator).to receive(:ast_2).and_return(ast_2)
159
+ validator.validate!
160
+
161
+ expect(validator.errors).to eq([
162
+ I18nFlow::Validator::InvalidTypeError.new('ja.foo.key_2'),
163
+ ])
164
+ end
165
+
166
+ it 'suppress an error on the ignored node' do
167
+ ast_1 = parse_yaml(<<-YAML)['en']
168
+ en:
169
+ key_1: text_1
170
+ key_2: text_2
171
+ YAML
172
+ ast_2 = parse_yaml(<<-YAML)['ja']
173
+ ja:
174
+ key_1: text_1
175
+ key_2: !ignore:key
176
+ one: text_2
177
+ YAML
178
+
179
+ allow(validator).to receive(:ast_1).and_return(ast_1)
180
+ allow(validator).to receive(:ast_2).and_return(ast_2)
181
+ validator.validate!
182
+
183
+ expect(validator.errors).to eq([])
184
+ end
185
+
186
+ it 'suppress an error on the ignored node (outer map)' do
187
+ ast_1 = parse_yaml(<<-YAML)['en']
188
+ en:
189
+ key_1: text_1
190
+ foo:
191
+ key_2: text_2
192
+ YAML
193
+ ast_2 = parse_yaml(<<-YAML)['ja']
194
+ ja:
195
+ key_1: text_1
196
+ foo: !ignore:key
197
+ key_2:
198
+ one: text_2
199
+ YAML
200
+
201
+ allow(validator).to receive(:ast_1).and_return(ast_1)
202
+ allow(validator).to receive(:ast_2).and_return(ast_2)
203
+ validator.validate!
204
+
205
+ expect(validator.errors).to eq([])
206
+ end
207
+ end
208
+
209
+ context '!only tag' do
210
+ it 'should pass if the asymmetric node is tagged with its locale (value)' do
211
+ ast_1 = parse_yaml(<<-YAML)['en']
212
+ en:
213
+ key_1: text_1
214
+ key_2: text_2
215
+ YAML
216
+ ast_2 = parse_yaml(<<-YAML)['ja']
217
+ ja:
218
+ key_1: text_1
219
+ key_2: text_2
220
+ key_3: !only:ja text_3
221
+ YAML
222
+
223
+ allow(validator).to receive(:ast_1).and_return(ast_1)
224
+ allow(validator).to receive(:ast_2).and_return(ast_2)
225
+ validator.validate!
226
+
227
+ expect(validator.errors).to eq([])
228
+ end
229
+
230
+ it 'should pass if the asymmetric node is tagged with its locale (map)' do
231
+ ast_1 = parse_yaml(<<-YAML)['en']
232
+ en:
233
+ key_1: text_1
234
+ key_2: text_2
235
+ YAML
236
+ ast_2 = parse_yaml(<<-YAML)['ja']
237
+ ja:
238
+ key_1: text_1
239
+ key_2: text_2
240
+ key_3: !only:ja
241
+ one: text_3
242
+ YAML
243
+
244
+ allow(validator).to receive(:ast_1).and_return(ast_1)
245
+ allow(validator).to receive(:ast_2).and_return(ast_2)
246
+ validator.validate!
247
+
248
+ expect(validator.errors).to eq([])
249
+ end
250
+
251
+ it 'should pass if the symmetric node is tagged with both locales' do
252
+ ast_1 = parse_yaml(<<-YAML)['en']
253
+ en:
254
+ key_1: text_1
255
+ key_2: !only:en,ja text_2
256
+ YAML
257
+ ast_2 = parse_yaml(<<-YAML)['ja']
258
+ ja:
259
+ key_1: text_1
260
+ key_2: !only:en,ja text_2
261
+ YAML
262
+
263
+ allow(validator).to receive(:ast_1).and_return(ast_1)
264
+ allow(validator).to receive(:ast_2).and_return(ast_2)
265
+ validator.validate!
266
+
267
+ expect(validator.errors).to eq([])
268
+ end
269
+
270
+ it 'should fail if the symmetric node is tagged with an one-side locale' do
271
+ ast_1 = parse_yaml(<<-YAML)['en']
272
+ en:
273
+ key_1: text_1
274
+ key_2: text_2
275
+ YAML
276
+ ast_2 = parse_yaml(<<-YAML)['ja']
277
+ ja:
278
+ key_1: text_1
279
+ key_2: !only:ja text_2
280
+ YAML
281
+
282
+ allow(validator).to receive(:ast_1).and_return(ast_1)
283
+ allow(validator).to receive(:ast_2).and_return(ast_2)
284
+ validator.validate!
285
+
286
+ expect(validator.errors).to eq([
287
+ I18nFlow::Validator::InvalidLocaleError.new('en.key_2', expect: ['ja'], actual: 'en'),
288
+ ])
289
+ end
290
+
291
+ it 'should fail if the asymmetric node is tagged with a different locale' do
292
+ ast_1 = parse_yaml(<<-YAML)['en']
293
+ en:
294
+ key_1: text_1
295
+ key_2: text_2
296
+ YAML
297
+ ast_2 = parse_yaml(<<-YAML)['ja']
298
+ ja:
299
+ key_1: text_1
300
+ key_2: text_2
301
+ key_3: !only:en
302
+ one: text_3
303
+ YAML
304
+
305
+ allow(validator).to receive(:ast_1).and_return(ast_1)
306
+ allow(validator).to receive(:ast_2).and_return(ast_2)
307
+ validator.validate!
308
+
309
+ expect(validator.errors).to eq([
310
+ I18nFlow::Validator::InvalidLocaleError.new('ja.key_3', expect: ['en'], actual: 'ja'),
311
+ ])
312
+ end
313
+
314
+ it 'should fail if the symmetric node is tagged with a different locale' do
315
+ ast_1 = parse_yaml(<<-YAML)['en']
316
+ en:
317
+ key_1: text_1
318
+ key_2: !only:en text_2
319
+ YAML
320
+ ast_2 = parse_yaml(<<-YAML)['ja']
321
+ ja:
322
+ key_1: text_1
323
+ key_2: text_2
324
+ YAML
325
+
326
+ allow(validator).to receive(:ast_1).and_return(ast_1)
327
+ allow(validator).to receive(:ast_2).and_return(ast_2)
328
+ validator.validate!
329
+
330
+ expect(validator.errors).to eq([
331
+ I18nFlow::Validator::InvalidLocaleError.new('ja.key_2', expect: ['en'], actual: 'ja'),
332
+ ])
333
+ end
334
+ end
335
+
336
+ context '!todo tag' do
337
+ it 'should pass if the value is marked as todo' do
338
+ ast_1 = parse_yaml(<<-YAML)['en']
339
+ en:
340
+ key_1: text_1
341
+ key_2: text_2
342
+ YAML
343
+ ast_2 = parse_yaml(<<-YAML)['ja']
344
+ ja:
345
+ key_1: text_1
346
+ key_2: !todo text_2
347
+ YAML
348
+
349
+ allow(validator).to receive(:ast_1).and_return(ast_1)
350
+ allow(validator).to receive(:ast_2).and_return(ast_2)
351
+ validator.validate!
352
+
353
+ expect(validator.errors).to eq([])
354
+ end
355
+
356
+ it 'should fail if the tag is on a non-value node' do
357
+ ast_1 = parse_yaml(<<-YAML)['en']
358
+ en:
359
+ key_1: text_1
360
+ foo: !todo
361
+ key_2: text_2
362
+ YAML
363
+ ast_2 = parse_yaml(<<-YAML)['ja']
364
+ ja:
365
+ key_1: text_1
366
+ foo: !todo
367
+ key_2: text_2
368
+ YAML
369
+
370
+ allow(validator).to receive(:ast_1).and_return(ast_1)
371
+ allow(validator).to receive(:ast_2).and_return(ast_2)
372
+ validator.validate!
373
+
374
+ expect(validator.errors).to eq([
375
+ # en.foo is ignored,
376
+ I18nFlow::Validator::InvalidTodoError.new('ja.foo'),
377
+ ])
378
+ end
379
+
380
+ it 'should fail if texts are different' do
381
+ ast_1 = parse_yaml(<<-YAML)['en']
382
+ en:
383
+ key_1: text_1
384
+ key_2: text_2
385
+ YAML
386
+ ast_2 = parse_yaml(<<-YAML)['ja']
387
+ ja:
388
+ key_1: text_1
389
+ key_2: !todo text_9
390
+ YAML
391
+
392
+ allow(validator).to receive(:ast_1).and_return(ast_1)
393
+ allow(validator).to receive(:ast_2).and_return(ast_2)
394
+ validator.validate!
395
+
396
+ expect(validator.errors).to eq([
397
+ I18nFlow::Validator::TodoContentError.new('ja.key_2', expect: 'text_2', actual: 'text_9'),
398
+ ])
399
+ end
400
+ end
401
+
402
+ context 'args' do
403
+ it 'should pass if the arguments are exclusive and exhaustive' do
404
+ ast_1 = parse_yaml(<<-YAML)['en']
405
+ en:
406
+ key_1: '%{arg_1} %{arg_2}'
407
+ YAML
408
+ ast_2 = parse_yaml(<<-YAML)['ja']
409
+ ja:
410
+ key_1: '%{arg_1} %{arg_2}'
411
+ YAML
412
+
413
+ allow(validator).to receive(:ast_1).and_return(ast_1)
414
+ allow(validator).to receive(:ast_2).and_return(ast_2)
415
+ validator.validate!
416
+
417
+ expect(validator.errors).to eq([])
418
+ end
419
+
420
+ it 'should be insensitive of the order of arguments' do
421
+ ast_1 = parse_yaml(<<-YAML)['en']
422
+ en:
423
+ key_1: '%{arg_1} %{arg_2}'
424
+ YAML
425
+ ast_2 = parse_yaml(<<-YAML)['ja']
426
+ ja:
427
+ key_1: '%{arg_2} %{arg_1}'
428
+ YAML
429
+
430
+ allow(validator).to receive(:ast_1).and_return(ast_1)
431
+ allow(validator).to receive(:ast_2).and_return(ast_2)
432
+ validator.validate!
433
+
434
+ expect(validator.errors).to eq([])
435
+ end
436
+
437
+ it 'should be insensitive of the duplicate of arguments' do
438
+ ast_1 = parse_yaml(<<-YAML)['en']
439
+ en:
440
+ key_1: '%{arg_1} %{arg_1}'
441
+ YAML
442
+ ast_2 = parse_yaml(<<-YAML)['ja']
443
+ ja:
444
+ key_1: '%{arg_1}'
445
+ YAML
446
+
447
+ allow(validator).to receive(:ast_1).and_return(ast_1)
448
+ allow(validator).to receive(:ast_2).and_return(ast_2)
449
+ validator.validate!
450
+
451
+ expect(validator.errors).to eq([])
452
+ end
453
+
454
+ it 'should ignore confusing args' do
455
+ ast_1 = parse_yaml(<<-YAML)['en']
456
+ en:
457
+ key_1: 'foo %%{arg_1}'
458
+ YAML
459
+ ast_2 = parse_yaml(<<-YAML)['ja']
460
+ ja:
461
+ key_1: 'foo'
462
+ YAML
463
+
464
+ allow(validator).to receive(:ast_1).and_return(ast_1)
465
+ allow(validator).to receive(:ast_2).and_return(ast_2)
466
+ validator.validate!
467
+
468
+ expect(validator.errors).to eq([])
469
+ end
470
+
471
+ it 'should detect unbalanced arguments' do
472
+ ast_1 = parse_yaml(<<-YAML)['en']
473
+ en:
474
+ key_1: 'foo %{arg_1}'
475
+ YAML
476
+ ast_2 = parse_yaml(<<-YAML)['ja']
477
+ ja:
478
+ key_1: 'foo %{arg_2}'
479
+ YAML
480
+
481
+ allow(validator).to receive(:ast_1).and_return(ast_1)
482
+ allow(validator).to receive(:ast_2).and_return(ast_2)
483
+ validator.validate!
484
+
485
+ expect(validator.errors).to eq([
486
+ I18nFlow::Validator::AsymmetricArgsError.new('ja.key_1',
487
+ expect: ['arg_1'],
488
+ actual: ['arg_2'],
489
+ )
490
+ ])
491
+ end
492
+
493
+ it 'should suppress an error on the ignored node' do
494
+ ast_1 = parse_yaml(<<-YAML)['en']
495
+ en:
496
+ key_1: 'foo %{arg_1}'
497
+ YAML
498
+ ast_2 = parse_yaml(<<-YAML)['ja']
499
+ ja:
500
+ key_1: !ignore:args 'foo %{arg_2}'
501
+ YAML
502
+
503
+ allow(validator).to receive(:ast_1).and_return(ast_1)
504
+ allow(validator).to receive(:ast_2).and_return(ast_2)
505
+ validator.validate!
506
+
507
+ expect(validator.errors).to eq([])
508
+ end
509
+ end
510
+ end
511
+ end
@@ -0,0 +1,151 @@
1
+ require 'psych'
2
+ require 'i18n_flow/yaml_ast_proxy'
3
+
4
+ describe I18nFlow::YamlAstProxy::Node do
5
+ describe '#merge!' do
6
+ it 'should merge mappings' do
7
+ ast_1 = parse_yaml(<<-YAML)
8
+ map:
9
+ foo_1: 'foo_1'
10
+ bar: 'bar_1'
11
+ YAML
12
+ ast_2 = parse_yaml(<<-YAML)
13
+ map:
14
+ foo_2: 'foo_2'
15
+ bar: 'bar_2'
16
+ YAML
17
+ result = parse_yaml(<<-YAML)
18
+ map:
19
+ foo_1: 'foo_1'
20
+ bar: 'bar_2'
21
+ foo_2: 'foo_2'
22
+ YAML
23
+
24
+ ast_1['map'].merge!(ast_2['map'])
25
+
26
+ expect(ast_1.to_yaml).to eq(result.to_yaml)
27
+ end
28
+
29
+ it 'should merge sequences' do
30
+ ast_1 = parse_yaml(<<-YAML)
31
+ seq:
32
+ - 'seq_1_1'
33
+ - 'seq_1_2'
34
+ YAML
35
+ ast_2 = parse_yaml(<<-YAML)
36
+ seq:
37
+ - 'seq_2_1'
38
+ - 'seq_2_2'
39
+ YAML
40
+ result = parse_yaml(<<-YAML)
41
+ seq:
42
+ - 'seq_1_1'
43
+ - 'seq_1_2'
44
+ - 'seq_2_1'
45
+ - 'seq_2_2'
46
+ YAML
47
+
48
+ ast_1['seq'].merge!(ast_2['seq'])
49
+
50
+ expect(ast_1.to_yaml).to eq(result.to_yaml)
51
+ end
52
+
53
+ it 'should merge nested mappings' do
54
+ ast_1 = parse_yaml(<<-YAML)
55
+ en:
56
+ map:
57
+ foo_1: 'foo_1'
58
+ bar: 'bar_1'
59
+ YAML
60
+ ast_2 = parse_yaml(<<-YAML)
61
+ en:
62
+ map:
63
+ foo_2: 'foo_2'
64
+ bar: 'bar_2'
65
+ map_2:
66
+ baz_2: 'baz_2'
67
+ YAML
68
+ result = parse_yaml(<<-YAML)
69
+ en:
70
+ map:
71
+ foo_1: 'foo_1'
72
+ bar: 'bar_2'
73
+ foo_2: 'foo_2'
74
+ map_2:
75
+ baz_2: 'baz_2'
76
+ YAML
77
+
78
+ ast_1['en'].merge!(ast_2['en'])
79
+
80
+ expect(ast_1.to_yaml).to eq(result.to_yaml)
81
+ end
82
+
83
+ it 'should merge nested sequences' do
84
+ ast_1 = parse_yaml(<<-YAML)
85
+ en:
86
+ seq:
87
+ - 'foo_1_1'
88
+ - 'foo_1_2'
89
+ YAML
90
+ ast_2 = parse_yaml(<<-YAML)
91
+ en:
92
+ seq:
93
+ - 'foo_2_1'
94
+ - 'foo_2_2'
95
+ YAML
96
+ result = parse_yaml(<<-YAML)
97
+ en:
98
+ seq:
99
+ - 'foo_1_1'
100
+ - 'foo_1_2'
101
+ - 'foo_2_1'
102
+ - 'foo_2_2'
103
+ YAML
104
+
105
+ ast_1['en'].merge!(ast_2['en'])
106
+
107
+ expect(ast_1.to_yaml).to eq(result.to_yaml)
108
+ end
109
+
110
+ it 'should merge root' do
111
+ ast_1 = parse_yaml(<<-YAML)
112
+ en:
113
+ map:
114
+ foo_1: 'foo_1'
115
+ bar: 'bar_1'
116
+ seq:
117
+ - 'foo_1_1'
118
+ - 'foo_1_2'
119
+ YAML
120
+ ast_2 = parse_yaml(<<-YAML)
121
+ en:
122
+ map:
123
+ foo_2: 'foo_2'
124
+ bar: 'bar_2'
125
+ seq:
126
+ - 'foo_2_1'
127
+ - 'foo_2_2'
128
+ map_2:
129
+ baz_2: 'baz_2'
130
+ YAML
131
+ result = parse_yaml(<<-YAML)
132
+ en:
133
+ map:
134
+ foo_1: 'foo_1'
135
+ bar: 'bar_2'
136
+ seq:
137
+ - 'foo_1_1'
138
+ - 'foo_1_2'
139
+ - 'foo_2_1'
140
+ - 'foo_2_2'
141
+ foo_2: 'foo_2'
142
+ map_2:
143
+ baz_2: 'baz_2'
144
+ YAML
145
+
146
+ ast_1.merge!(ast_2)
147
+
148
+ expect(ast_1.to_yaml).to eq(result.to_yaml)
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,21 @@
1
+ require 'i18n_flow/configuration'
2
+
3
+ describe I18nFlow do
4
+ describe '.config' do
5
+ it 'should return an instance of Configuration' do
6
+ expect {
7
+ expect(I18nFlow.config).to be_a(I18nFlow::Configuration)
8
+ }.not_to raise_error
9
+ end
10
+ end
11
+
12
+ describe '.configure' do
13
+ it 'should change option values inside a block' do
14
+ expect {
15
+ I18nFlow.configure do |config|
16
+ expect(config).to be_a(I18nFlow::Configuration)
17
+ end
18
+ }.not_to raise_error
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'i18n_flow'
4
+ require 'rspec'
5
+ require 'fakefs/spec_helpers'
6
+ require 'pry'
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
9
+
10
+ Pry.config.history.should_load = false
11
+ Pry.config.history.should_save = false
12
+
13
+ RSpec.configure do |config|
14
+ config.include FakeFS::SpecHelpers
15
+ config.include UtilMacro
16
+ end