gherkin 1.0.3 → 1.0.4

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 (58) hide show
  1. data/History.txt +15 -6
  2. data/README.rdoc +23 -0
  3. data/Rakefile +1 -0
  4. data/VERSION.yml +1 -1
  5. data/features/step_definitions/gherkin_steps.rb +1 -1
  6. data/features/step_definitions/{pretty_printer_steps.rb → pretty_listener_step.rb} +2 -2
  7. data/gherkin.gemspec +24 -35
  8. data/java/Gherkin.iml +8 -14
  9. data/java/src/{gherkin → main/java/gherkin}/lexer/.gitignore +0 -0
  10. data/lib/gherkin.rb +1 -1
  11. data/lib/gherkin/c_lexer.rb +2 -2
  12. data/lib/gherkin/{format → formatter}/argument.rb +1 -1
  13. data/lib/gherkin/{tools → formatter}/colors.rb +1 -1
  14. data/lib/gherkin/{format → formatter}/monochrome_format.rb +1 -1
  15. data/lib/gherkin/{tools → formatter}/pretty_listener.rb +8 -9
  16. data/lib/gherkin/i18n.rb +27 -5
  17. data/lib/gherkin/i18n_lexer.rb +18 -44
  18. data/lib/gherkin/parser/filter_listener.rb +191 -0
  19. data/lib/gherkin/parser/parser.rb +142 -0
  20. data/lib/gherkin/parser/sexp.rb +45 -0
  21. data/lib/gherkin/parser/tag_expression.rb +46 -0
  22. data/lib/gherkin/rb_lexer.rb +2 -2
  23. data/ragel/lexer_common.rl.erb +1 -1
  24. data/spec/gherkin/{format → formatter}/argument_spec.rb +2 -2
  25. data/spec/gherkin/{tools → formatter}/colors_spec.rb +2 -2
  26. data/spec/gherkin/{tools → formatter}/pretty_listener_spec.rb +5 -5
  27. data/spec/gherkin/i18n_lexer_spec.rb +3 -3
  28. data/spec/gherkin/parser/filter_listener_spec.rb +363 -0
  29. data/spec/gherkin/parser/parser_spec.rb +35 -0
  30. data/spec/gherkin/parser/tag_expression_spec.rb +120 -0
  31. data/spec/gherkin/rb_lexer_spec.rb +0 -1
  32. data/spec/gherkin/sexp_recorder.rb +3 -3
  33. data/spec/gherkin/shared/lexer_spec.rb +19 -19
  34. data/spec/gherkin/shared/tags_spec.rb +4 -4
  35. data/tasks/bench.rake +2 -2
  36. data/tasks/compile.rake +1 -1
  37. data/tasks/ragel_task.rb +1 -1
  38. metadata +25 -36
  39. data/java/build.xml +0 -16
  40. data/java/src/gherkin/FixJava.java +0 -37
  41. data/java/src/gherkin/I18nLexer.java +0 -48
  42. data/java/src/gherkin/Lexer.java +0 -5
  43. data/java/src/gherkin/LexingError.java +0 -7
  44. data/java/src/gherkin/Listener.java +0 -29
  45. data/java/src/gherkin/Main.java +0 -17
  46. data/java/src/gherkin/ParseError.java +0 -22
  47. data/java/src/gherkin/Parser.java +0 -191
  48. data/java/src/gherkin/formatter/Argument.java +0 -39
  49. data/java/src/gherkin/formatter/ArgumentFormat.java +0 -17
  50. data/java/src/gherkin/formatter/Colors.java +0 -7
  51. data/java/src/gherkin/formatter/Formatter.java +0 -15
  52. data/java/src/gherkin/formatter/PrettyFormatter.java +0 -219
  53. data/java/src/gherkin/parser/StateMachineReader.java +0 -67
  54. data/java/test/gherkin/formatter/ArgumentTest.java +0 -17
  55. data/lib/gherkin/lexer.rb +0 -35
  56. data/lib/gherkin/parser.rb +0 -19
  57. data/lib/gherkin/rb_parser.rb +0 -125
  58. data/spec/gherkin/parser_spec.rb +0 -33
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ require 'gherkin/parser/tag_expression'
3
+
4
+ module Gherkin
5
+ module Parser
6
+ describe TagExpression do
7
+ context "no tags" do
8
+ before(:each) do
9
+ @e = TagExpression.new
10
+ end
11
+
12
+ it "should match @foo" do
13
+ @e.eval('@foo').should == true
14
+ end
15
+
16
+ it "should match empty tags" do
17
+ @e.eval().should == true
18
+ end
19
+ end
20
+
21
+ context "@foo" do
22
+ before(:each) do
23
+ @e = TagExpression.new('@foo')
24
+ end
25
+
26
+ it "should match @foo" do
27
+ @e.eval('@foo').should == true
28
+ end
29
+
30
+ it "should not match @bar" do
31
+ @e.eval('@bar').should == false
32
+ end
33
+ end
34
+
35
+ context "!@foo" do
36
+ before(:each) do
37
+ @e = TagExpression.new('~@foo')
38
+ end
39
+
40
+ it "should match @bar" do
41
+ @e.eval('@bar').should == true
42
+ end
43
+
44
+ it "should not match @foo" do
45
+ @e.eval('@foo').should == false
46
+ end
47
+ end
48
+
49
+ context "@foo || @bar" do
50
+ before(:each) do
51
+ @e = TagExpression.new('@foo,@bar')
52
+ end
53
+
54
+ it "should match @foo" do
55
+ @e.eval('@foo').should == true
56
+ end
57
+
58
+ it "should match @bar" do
59
+ @e.eval('@bar').should == true
60
+ end
61
+
62
+ it "should not match @zap" do
63
+ @e.eval('@zap').should == false
64
+ end
65
+ end
66
+
67
+ context "(@foo || @bar) && !@zap" do
68
+ before(:each) do
69
+ @e = TagExpression.new('@foo,@bar', '~@zap')
70
+ end
71
+
72
+ it "should match @foo" do
73
+ @e.eval('@foo').should == true
74
+ end
75
+
76
+ it "should not match @foo @zap" do
77
+ @e.eval('@foo', '@zap').should == false
78
+ end
79
+ end
80
+
81
+ context "(@foo:3 || !@bar:4) && @zap:5" do
82
+ before(:each) do
83
+ @e = TagExpression.new('@foo:3,~@bar','@zap:5')
84
+ end
85
+
86
+ it "should count tags for positive tags" do
87
+ @e.limits.should == {'@foo' => 3, '@zap' => 5}
88
+ end
89
+
90
+ it "should match @foo @zap" do
91
+ @e.eval('@foo', '@zap').should == true
92
+ end
93
+ end
94
+
95
+ context "Parsing '@foo:3,~@bar', '@zap:5'" do
96
+ before(:each) do
97
+ @e = TagExpression.new(' @foo:3 , ~@bar ', ' @zap:5 ')
98
+ end
99
+
100
+ it "should split and trim" do
101
+ @e.__send__(:ruby_expression).should == "(!vars['@bar']||vars['@foo'])&&(vars['@zap'])"
102
+ end
103
+
104
+ it "should have limits" do
105
+ @e.limits.should == {"@zap"=>5, "@foo"=>3}
106
+ end
107
+ end
108
+
109
+ context "Parsing ''" do
110
+ before(:each) do
111
+ @e = TagExpression.new('')
112
+ end
113
+
114
+ it "should ignore empty tags" do
115
+ @e.eval("@foo").should == true
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -1,6 +1,5 @@
1
1
  #encoding: utf-8
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
- require 'gherkin/rb_lexer'
4
3
  require 'gherkin/rb_lexer/en'
5
4
 
6
5
  module Gherkin
@@ -4,9 +4,9 @@ module Gherkin
4
4
  @sexps = []
5
5
  end
6
6
 
7
- def method_missing(m, *args)
8
- args[0] = args[0].map{|cell| cell} if m == :row
9
- @sexps << [m] + args
7
+ def method_missing(event, *args)
8
+ args[0] = args[0].to_a if event == :row # Special JRuby handling
9
+ @sexps << [event] + args
10
10
  end
11
11
 
12
12
  def to_sexp
@@ -56,7 +56,7 @@ module Gherkin
56
56
  @listener.to_sexp.should == [
57
57
  [:feature, "Feature", "hi", 1],
58
58
  [:scenario, "Scenario", "test", 2],
59
- [:tag, "hello", 4],
59
+ [:tag, "@hello", 4],
60
60
  [:scenario, "Scenario", "another", 5],
61
61
  [:eof]
62
62
  ]
@@ -404,16 +404,16 @@ Given I am a step
404
404
  scan_file("simple_with_tags.feature")
405
405
  @listener.to_sexp.should == [
406
406
  [:comment, "# FC", 1],
407
- [:tag, "ft",2],
407
+ [:tag, "@ft",2],
408
408
  [:feature, "Feature", "hi", 3],
409
- [:tag, "st1", 5],
410
- [:tag, "st2", 5],
409
+ [:tag, "@st1", 5],
410
+ [:tag, "@st2", 5],
411
411
  [:scenario, "Scenario", "First", 6],
412
412
  [:step, "Given ", "Pepper", 7],
413
- [:tag, "st3", 9],
414
- [:tag, "st4", 10],
415
- [:tag, "ST5", 10],
416
- [:tag, "#^%&ST6**!", 10],
413
+ [:tag, "@st3", 9],
414
+ [:tag, "@st4", 10],
415
+ [:tag, "@ST5", 10],
416
+ [:tag, "@#^%&ST6**!", 10],
417
417
  [:scenario, "Scenario", "Second", 11],
418
418
  [:eof]
419
419
  ]
@@ -427,7 +427,7 @@ Given I am a step
427
427
  [:feature, "Feature", "Logging in\nSo that I can be myself", 1],
428
428
  [:comment, "# Comment", 3],
429
429
  [:scenario, "Scenario", "Anonymous user can get a login form.\nScenery here", 4],
430
- [:tag, "tag", 7],
430
+ [:tag, "@tag", 7],
431
431
  [:scenario, "Scenario", "Another one", 8],
432
432
  [:eof]
433
433
  ]
@@ -440,20 +440,20 @@ Given I am a step
440
440
  @listener.to_sexp.should == [
441
441
  [:comment, "#Comment on line 1", 1],
442
442
  [:comment, "#Comment on line 2", 2],
443
- [:tag, "tag1", 3],
444
- [:tag, "tag2", 3],
443
+ [:tag, "@tag1", 3],
444
+ [:tag, "@tag2", 3],
445
445
  [:feature, "Feature", "Feature Text\nIn order to test multiline forms\nAs a ragel writer\nI need to check for complex combinations", 4],
446
446
  [:comment, "#Comment on line 9", 9],
447
447
  [:comment, "#Comment on line 11", 11],
448
448
  [:background, "Background", "", 13],
449
449
  [:step, "Given ", "this is a background step", 14],
450
450
  [:step, "And ", "this is another one", 15],
451
- [:tag, "tag3", 17],
452
- [:tag, "tag4", 17],
451
+ [:tag, "@tag3", 17],
452
+ [:tag, "@tag4", 17],
453
453
  [:scenario, "Scenario", "Reading a Scenario", 18],
454
454
  [:step, "Given ", "there is a step", 19],
455
455
  [:step, "But ", "not another step", 20],
456
- [:tag, "tag3", 22],
456
+ [:tag, "@tag3", 22],
457
457
  [:scenario, "Scenario", "Reading a second scenario\nWith two lines of text", 23],
458
458
  [:comment, "#Comment on line 24", 25],
459
459
  [:step, "Given ", "a third step with a table", 26],
@@ -484,20 +484,20 @@ Given I am a step
484
484
  @listener.to_sexp.should == [
485
485
  [:comment, "#Comment on line 1", 1],
486
486
  [:comment, "#Comment on line 2", 2],
487
- [:tag, "tag1", 3],
488
- [:tag, "tag2", 3],
487
+ [:tag, "@tag1", 3],
488
+ [:tag, "@tag2", 3],
489
489
  [:feature, "Feature", "Feature Text\r\nIn order to test multiline forms\r\nAs a ragel writer\r\nI need to check for complex combinations", 4],
490
490
  [:comment, "#Comment on line 9", 9],
491
491
  [:comment, "#Comment on line 11", 11],
492
492
  [:background, "Background", "", 13],
493
493
  [:step, "Given ", "this is a background step", 14],
494
494
  [:step, "And ", "this is another one", 15],
495
- [:tag, "tag3", 17],
496
- [:tag, "tag4", 17],
495
+ [:tag, "@tag3", 17],
496
+ [:tag, "@tag4", 17],
497
497
  [:scenario, "Scenario", "Reading a Scenario", 18],
498
498
  [:step, "Given ", "there is a step", 19],
499
499
  [:step, "But ", "not another step", 20],
500
- [:tag, "tag3", 22],
500
+ [:tag, "@tag3", 22],
501
501
  [:scenario, "Scenario", "Reading a second scenario\r\nWith two lines of text", 23],
502
502
  [:comment, "#Comment on line 24", 25],
503
503
  [:step, "Given ", "a third step with a table", 26],
@@ -5,7 +5,7 @@ module Gherkin
5
5
  module Lexer
6
6
  shared_examples_for "a Gherkin lexer lexing tags" do
7
7
  it "should lex a single tag" do
8
- @listener.should_receive(:tag).with("dog", 1)
8
+ @listener.should_receive(:tag).with("@dog", 1)
9
9
  @lexer.scan("@dog\n")
10
10
  end
11
11
 
@@ -15,13 +15,13 @@ module Gherkin
15
15
  end
16
16
 
17
17
  it "should lex UTF-8 tags" do
18
- @listener.should_receive(:tag).with("シナリオテンプレート", 1)
18
+ @listener.should_receive(:tag).with("@シナリオテンプレート", 1)
19
19
  @lexer.scan("@シナリオテンプレート\n")
20
20
  end
21
21
 
22
22
  it "should lex mixed tags" do
23
- @listener.should_receive(:tag).with("wip", 1).ordered
24
- @listener.should_receive(:tag).with("Значения", 1).ordered
23
+ @listener.should_receive(:tag).with("@wip", 1).ordered
24
+ @listener.should_receive(:tag).with("@Значения", 1).ordered
25
25
  @lexer.scan("@wip @Значения\n")
26
26
  end
27
27
 
@@ -106,11 +106,11 @@ class Benchmarker
106
106
 
107
107
  def run_rb_gherkin
108
108
  require 'gherkin'
109
- require 'gherkin/rb_lexer'
109
+ require 'gherkin/rb_lexer/en'
110
110
  require 'null_listener'
111
111
  @features.each do |feature|
112
112
  parser = Gherkin::Parser.new(NullListener.new, true, "root")
113
- lexer = Gherkin::RbLexer['en'].new(parser)
113
+ lexer = Gherkin::RbLexer::En.new(parser)
114
114
  lexer.scan(File.read(feature))
115
115
  end
116
116
  end
@@ -16,7 +16,7 @@ CLEAN.include [
16
16
 
17
17
  desc "Compile the Java extensions"
18
18
  task :jar do
19
- sh("ant -f java/build.xml")
19
+ sh("mvn -f java/pom.xml package")
20
20
  end
21
21
 
22
22
  namespace :dotnet do
@@ -28,7 +28,7 @@ class RagelTask
28
28
  def target
29
29
  {
30
30
  'c' => "ext/gherkin_lexer_#{@i18n.sanitized_key}/gherkin_lexer_#{@i18n.sanitized_key}.c",
31
- 'java' => "java/src/gherkin/lexer/#{@i18n.sanitized_key.capitalize}.java",
31
+ 'java' => "java/src/main/java/gherkin/lexer/#{@i18n.sanitized_key.capitalize}.java",
32
32
  'rb' => "lib/gherkin/rb_lexer/#{@i18n.sanitized_key}.rb",
33
33
  'csharp' => "tmp/#{@i18n.sanitized_key}.cs"
34
34
  }[@lang]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 3
9
- version: 1.0.3
8
+ - 4
9
+ version: 1.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mike Sassak
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-03-30 00:00:00 +02:00
19
+ date: 2010-04-07 00:00:00 +02:00
20
20
  default_executable: gherkin
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -195,45 +195,33 @@ files:
195
195
  - features/parser_with_native_lexer.feature
196
196
  - features/pretty_printer.feature
197
197
  - features/step_definitions/gherkin_steps.rb
198
- - features/step_definitions/pretty_printer_steps.rb
198
+ - features/step_definitions/pretty_listener_step.rb
199
199
  - features/steps_parser.feature
200
200
  - features/support/env.rb
201
201
  - gherkin.gemspec
202
202
  - java/.gitignore
203
203
  - java/Gherkin.iml
204
- - java/build.xml
205
- - java/src/gherkin/FixJava.java
206
- - java/src/gherkin/I18nLexer.java
207
- - java/src/gherkin/Lexer.java
208
- - java/src/gherkin/LexingError.java
209
- - java/src/gherkin/Listener.java
210
- - java/src/gherkin/Main.java
211
- - java/src/gherkin/ParseError.java
212
- - java/src/gherkin/Parser.java
213
- - java/src/gherkin/formatter/Argument.java
214
- - java/src/gherkin/formatter/ArgumentFormat.java
215
- - java/src/gherkin/formatter/Colors.java
216
- - java/src/gherkin/formatter/Formatter.java
217
- - java/src/gherkin/formatter/PrettyFormatter.java
218
- - java/src/gherkin/lexer/.gitignore
219
- - java/src/gherkin/parser/StateMachineReader.java
220
- - java/test/gherkin/formatter/ArgumentTest.java
204
+ - java/src/main/java/gherkin/lexer/.gitignore
221
205
  - lib/.gitignore
222
206
  - lib/gherkin.rb
223
207
  - lib/gherkin/c_lexer.rb
224
208
  - lib/gherkin/cli/main.rb
225
209
  - lib/gherkin/core_ext/array.rb
226
210
  - lib/gherkin/csharp_lexer.rb
227
- - lib/gherkin/format/argument.rb
228
- - lib/gherkin/format/monochrome_format.rb
211
+ - lib/gherkin/formatter/argument.rb
212
+ - lib/gherkin/formatter/colors.rb
213
+ - lib/gherkin/formatter/monochrome_format.rb
214
+ - lib/gherkin/formatter/pretty_listener.rb
229
215
  - lib/gherkin/i18n.rb
230
216
  - lib/gherkin/i18n.yml
231
217
  - lib/gherkin/i18n_lexer.rb
232
- - lib/gherkin/lexer.rb
233
- - lib/gherkin/parser.rb
218
+ - lib/gherkin/parser/filter_listener.rb
234
219
  - lib/gherkin/parser/meta.txt
220
+ - lib/gherkin/parser/parser.rb
235
221
  - lib/gherkin/parser/root.txt
222
+ - lib/gherkin/parser/sexp.rb
236
223
  - lib/gherkin/parser/steps.txt
224
+ - lib/gherkin/parser/tag_expression.rb
237
225
  - lib/gherkin/rb_lexer.rb
238
226
  - lib/gherkin/rb_lexer/.gitignore
239
227
  - lib/gherkin/rb_lexer/README.rdoc
@@ -278,11 +266,8 @@ files:
278
266
  - lib/gherkin/rb_lexer/vi.rb
279
267
  - lib/gherkin/rb_lexer/zhCN.rb
280
268
  - lib/gherkin/rb_lexer/zhTW.rb
281
- - lib/gherkin/rb_parser.rb
282
269
  - lib/gherkin/tools.rb
283
- - lib/gherkin/tools/colors.rb
284
270
  - lib/gherkin/tools/files.rb
285
- - lib/gherkin/tools/pretty_listener.rb
286
271
  - lib/gherkin/tools/reformat.rb
287
272
  - lib/gherkin/tools/stats.rb
288
273
  - lib/gherkin/tools/stats_listener.rb
@@ -305,19 +290,21 @@ files:
305
290
  - spec/gherkin/fixtures/simple.feature
306
291
  - spec/gherkin/fixtures/simple_with_comments.feature
307
292
  - spec/gherkin/fixtures/simple_with_tags.feature
308
- - spec/gherkin/format/argument_spec.rb
293
+ - spec/gherkin/formatter/argument_spec.rb
294
+ - spec/gherkin/formatter/colors_spec.rb
295
+ - spec/gherkin/formatter/pretty_listener_spec.rb
309
296
  - spec/gherkin/i18n_lexer_spec.rb
310
297
  - spec/gherkin/i18n_spec.rb
311
298
  - spec/gherkin/java_lexer_spec.rb
312
- - spec/gherkin/parser_spec.rb
299
+ - spec/gherkin/parser/filter_listener_spec.rb
300
+ - spec/gherkin/parser/parser_spec.rb
301
+ - spec/gherkin/parser/tag_expression_spec.rb
313
302
  - spec/gherkin/rb_lexer_spec.rb
314
303
  - spec/gherkin/sexp_recorder.rb
315
304
  - spec/gherkin/shared/lexer_spec.rb
316
305
  - spec/gherkin/shared/py_string_spec.rb
317
306
  - spec/gherkin/shared/row_spec.rb
318
307
  - spec/gherkin/shared/tags_spec.rb
319
- - spec/gherkin/tools/colors_spec.rb
320
- - spec/gherkin/tools/pretty_listener_spec.rb
321
308
  - spec/spec_helper.rb
322
309
  - tasks/bench.rake
323
310
  - tasks/bench/feature_builder.rb
@@ -361,17 +348,19 @@ summary: Fast Gherkin lexer/parser
361
348
  test_files:
362
349
  - spec/gherkin/c_lexer_spec.rb
363
350
  - spec/gherkin/csharp_lexer_spec.rb
364
- - spec/gherkin/format/argument_spec.rb
351
+ - spec/gherkin/formatter/argument_spec.rb
352
+ - spec/gherkin/formatter/colors_spec.rb
353
+ - spec/gherkin/formatter/pretty_listener_spec.rb
365
354
  - spec/gherkin/i18n_lexer_spec.rb
366
355
  - spec/gherkin/i18n_spec.rb
367
356
  - spec/gherkin/java_lexer_spec.rb
368
- - spec/gherkin/parser_spec.rb
357
+ - spec/gherkin/parser/filter_listener_spec.rb
358
+ - spec/gherkin/parser/parser_spec.rb
359
+ - spec/gherkin/parser/tag_expression_spec.rb
369
360
  - spec/gherkin/rb_lexer_spec.rb
370
361
  - spec/gherkin/sexp_recorder.rb
371
362
  - spec/gherkin/shared/lexer_spec.rb
372
363
  - spec/gherkin/shared/py_string_spec.rb
373
364
  - spec/gherkin/shared/row_spec.rb
374
365
  - spec/gherkin/shared/tags_spec.rb
375
- - spec/gherkin/tools/colors_spec.rb
376
- - spec/gherkin/tools/pretty_listener_spec.rb
377
366
  - spec/spec_helper.rb
@@ -1,16 +0,0 @@
1
- <project name="Gherkin" default="jar" basedir=".">
2
- <target name="compile" description="Compile">
3
- <mkdir dir="${basedir}/target/classes"/>
4
- <javac srcdir="src" destdir="target/classes" debug="on"/>
5
- </target>
6
-
7
- <target name="jar" description="Jar" depends="compile">
8
- <jar destfile="${basedir}/../lib/gherkin.jar">
9
- <fileset dir="${basedir}/target/classes" />
10
- <fileset dir="${basedir}/../lib" includes="gherkin/parser/*.txt" />
11
- <manifest>
12
- <attribute name="Main-Class" value="gherkin.Main" />
13
- </manifest>
14
- </jar>
15
- </target>
16
- </project>
@@ -1,37 +0,0 @@
1
- package gherkin;
2
-
3
- import java.io.IOException;
4
- import java.io.InputStreamReader;
5
- import java.io.Reader;
6
- import java.util.List;
7
-
8
- public class FixJava {
9
- public static String join(List<String> strings, String separator) {
10
- StringBuilder sb = new StringBuilder();
11
- int i = 0;
12
- for (String s : strings) {
13
- if (i != 0) sb.append(separator);
14
- sb.append(s);
15
- i++;
16
- }
17
- return sb.toString();
18
- }
19
-
20
- public static String readResource(String filePath) throws IOException {
21
- Reader reader = new InputStreamReader(FixJava.class.getResourceAsStream(filePath));
22
- return readReader(reader);
23
- }
24
-
25
- public static String readReader(Reader reader) throws IOException {
26
- final char[] buffer = new char[0x10000];
27
- StringBuilder sb = new StringBuilder();
28
- int read;
29
- do {
30
- read = reader.read(buffer, 0, buffer.length);
31
- if (read > 0) {
32
- sb.append(buffer, 0, read);
33
- }
34
- } while (read >= 0);
35
- return sb.toString();
36
- }
37
- }