benhamill-gherkin 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +2 -0
- data/.gitignore +11 -0
- data/.mailmap +2 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +7 -0
- data/History.txt +363 -0
- data/LICENSE +20 -0
- data/README.rdoc +149 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/build_native_gems.sh +8 -0
- data/cucumber.yml +3 -0
- data/features/escaped_pipes.feature +8 -0
- data/features/feature_parser.feature +237 -0
- data/features/json_formatter.feature +377 -0
- data/features/json_parser.feature +318 -0
- data/features/native_lexer.feature +19 -0
- data/features/parser_with_native_lexer.feature +205 -0
- data/features/pretty_formatter.feature +15 -0
- data/features/step_definitions/eyeball_steps.rb +3 -0
- data/features/step_definitions/gherkin_steps.rb +29 -0
- data/features/step_definitions/json_formatter_steps.rb +28 -0
- data/features/step_definitions/json_parser_steps.rb +20 -0
- data/features/step_definitions/pretty_formatter_steps.rb +84 -0
- data/features/steps_parser.feature +46 -0
- data/features/support/env.rb +38 -0
- data/gherkin.gemspec +61 -0
- data/ikvm/.gitignore +3 -0
- data/java/.gitignore +5 -0
- data/java/src/main/java/gherkin/lexer/i18n/.gitignore +1 -0
- data/java/src/main/resources/gherkin/.gitignore +1 -0
- data/js/lib/gherkin/lexer/i18n/ar.js +1094 -0
- data/js/lib/gherkin/lexer/i18n/bg.js +1308 -0
- data/js/lib/gherkin/lexer/i18n/ca.js +1236 -0
- data/js/lib/gherkin/lexer/i18n/cs.js +1090 -0
- data/js/lib/gherkin/lexer/i18n/cy_gb.js +958 -0
- data/js/lib/gherkin/lexer/i18n/da.js +974 -0
- data/js/lib/gherkin/lexer/i18n/de.js +1082 -0
- data/js/lib/gherkin/lexer/i18n/en.js +965 -0
- data/js/lib/gherkin/lexer/i18n/en_au.js +902 -0
- data/js/lib/gherkin/lexer/i18n/en_lol.js +859 -0
- data/js/lib/gherkin/lexer/i18n/en_pirate.js +1136 -0
- data/js/lib/gherkin/lexer/i18n/en_scouse.js +1289 -0
- data/js/lib/gherkin/lexer/i18n/en_tx.js +942 -0
- data/js/lib/gherkin/lexer/i18n/eo.js +916 -0
- data/js/lib/gherkin/lexer/i18n/es.js +1049 -0
- data/js/lib/gherkin/lexer/i18n/et.js +915 -0
- data/js/lib/gherkin/lexer/i18n/fi.js +894 -0
- data/js/lib/gherkin/lexer/i18n/fr.js +1116 -0
- data/js/lib/gherkin/lexer/i18n/he.js +1044 -0
- data/js/lib/gherkin/lexer/i18n/hr.js +994 -0
- data/js/lib/gherkin/lexer/i18n/hu.js +1043 -0
- data/js/lib/gherkin/lexer/i18n/id.js +884 -0
- data/js/lib/gherkin/lexer/i18n/it.js +1007 -0
- data/js/lib/gherkin/lexer/i18n/ja.js +1344 -0
- data/js/lib/gherkin/lexer/i18n/ko.js +1028 -0
- data/js/lib/gherkin/lexer/i18n/lt.js +972 -0
- data/js/lib/gherkin/lexer/i18n/lu.js +1057 -0
- data/js/lib/gherkin/lexer/i18n/lv.js +1092 -0
- data/js/lib/gherkin/lexer/i18n/nl.js +1036 -0
- data/js/lib/gherkin/lexer/i18n/no.js +986 -0
- data/js/lib/gherkin/lexer/i18n/pl.js +1140 -0
- data/js/lib/gherkin/lexer/i18n/pt.js +1000 -0
- data/js/lib/gherkin/lexer/i18n/ro.js +1089 -0
- data/js/lib/gherkin/lexer/i18n/ru.js +1560 -0
- data/js/lib/gherkin/lexer/i18n/sk.js +972 -0
- data/js/lib/gherkin/lexer/i18n/sr_cyrl.js +1728 -0
- data/js/lib/gherkin/lexer/i18n/sr_latn.js +1220 -0
- data/js/lib/gherkin/lexer/i18n/sv.js +997 -0
- data/js/lib/gherkin/lexer/i18n/tr.js +1014 -0
- data/js/lib/gherkin/lexer/i18n/uk.js +1572 -0
- data/js/lib/gherkin/lexer/i18n/uz.js +1302 -0
- data/js/lib/gherkin/lexer/i18n/vi.js +1124 -0
- data/js/lib/gherkin/lexer/i18n/zh_cn.js +902 -0
- data/js/lib/gherkin/lexer/i18n/zh_tw.js +940 -0
- data/lib/.gitignore +4 -0
- data/lib/gherkin.rb +2 -0
- data/lib/gherkin/c_lexer.rb +17 -0
- data/lib/gherkin/formatter/ansi_escapes.rb +95 -0
- data/lib/gherkin/formatter/argument.rb +16 -0
- data/lib/gherkin/formatter/escaping.rb +15 -0
- data/lib/gherkin/formatter/filter_formatter.rb +136 -0
- data/lib/gherkin/formatter/hashable.rb +19 -0
- data/lib/gherkin/formatter/json_formatter.rb +102 -0
- data/lib/gherkin/formatter/line_filter.rb +26 -0
- data/lib/gherkin/formatter/model.rb +236 -0
- data/lib/gherkin/formatter/pretty_formatter.rb +243 -0
- data/lib/gherkin/formatter/regexp_filter.rb +21 -0
- data/lib/gherkin/formatter/step_printer.rb +17 -0
- data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
- data/lib/gherkin/formatter/tag_filter.rb +19 -0
- data/lib/gherkin/i18n.rb +175 -0
- data/lib/gherkin/i18n.yml +588 -0
- data/lib/gherkin/json_parser.rb +137 -0
- data/lib/gherkin/lexer/i18n_lexer.rb +47 -0
- data/lib/gherkin/listener/event.rb +45 -0
- data/lib/gherkin/listener/formatter_listener.rb +113 -0
- data/lib/gherkin/native.rb +7 -0
- data/lib/gherkin/native/ikvm.rb +55 -0
- data/lib/gherkin/native/java.rb +55 -0
- data/lib/gherkin/native/null.rb +9 -0
- data/lib/gherkin/parser/meta.txt +5 -0
- data/lib/gherkin/parser/parser.rb +164 -0
- data/lib/gherkin/parser/root.txt +11 -0
- data/lib/gherkin/parser/steps.txt +4 -0
- data/lib/gherkin/rb_lexer.rb +8 -0
- data/lib/gherkin/rb_lexer/.gitignore +1 -0
- data/lib/gherkin/rb_lexer/README.rdoc +8 -0
- data/lib/gherkin/rubify.rb +24 -0
- data/lib/gherkin/tag_expression.rb +62 -0
- data/lib/gherkin/version.rb +3 -0
- data/ragel/i18n/.gitignore +1 -0
- data/ragel/lexer.c.rl.erb +439 -0
- data/ragel/lexer.java.rl.erb +208 -0
- data/ragel/lexer.rb.rl.erb +167 -0
- data/ragel/lexer_common.rl.erb +50 -0
- data/spec/gherkin/c_lexer_spec.rb +21 -0
- data/spec/gherkin/fixtures/1.feature +8 -0
- data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
- data/spec/gherkin/fixtures/complex.feature +45 -0
- data/spec/gherkin/fixtures/complex.json +143 -0
- data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
- data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
- data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
- data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
- data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
- data/spec/gherkin/fixtures/i18n_no.feature +7 -0
- data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
- data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
- data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
- data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
- data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
- data/spec/gherkin/fixtures/with_bom.feature +3 -0
- data/spec/gherkin/formatter/ansi_escapes_spec.rb +19 -0
- data/spec/gherkin/formatter/filter_formatter_spec.rb +165 -0
- data/spec/gherkin/formatter/model_spec.rb +28 -0
- data/spec/gherkin/formatter/pretty_formatter_spec.rb +158 -0
- data/spec/gherkin/formatter/spaces.feature +9 -0
- data/spec/gherkin/formatter/step_printer_spec.rb +55 -0
- data/spec/gherkin/formatter/tabs.feature +9 -0
- data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
- data/spec/gherkin/i18n_spec.rb +152 -0
- data/spec/gherkin/java_lexer_spec.rb +20 -0
- data/spec/gherkin/java_libs.rb +20 -0
- data/spec/gherkin/json_parser_spec.rb +113 -0
- data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
- data/spec/gherkin/output_stream_string_io.rb +20 -0
- data/spec/gherkin/parser/parser_spec.rb +16 -0
- data/spec/gherkin/rb_lexer_spec.rb +19 -0
- data/spec/gherkin/sexp_recorder.rb +56 -0
- data/spec/gherkin/shared/lexer_group.rb +593 -0
- data/spec/gherkin/shared/py_string_group.rb +153 -0
- data/spec/gherkin/shared/row_group.rb +125 -0
- data/spec/gherkin/shared/tags_group.rb +54 -0
- data/spec/gherkin/tag_expression_spec.rb +137 -0
- data/spec/spec_helper.rb +69 -0
- data/tasks/bench.rake +184 -0
- data/tasks/bench/feature_builder.rb +49 -0
- data/tasks/bench/generated/.gitignore +1 -0
- data/tasks/bench/null_listener.rb +4 -0
- data/tasks/compile.rake +102 -0
- data/tasks/cucumber.rake +20 -0
- data/tasks/gems.rake +35 -0
- data/tasks/ikvm.rake +79 -0
- data/tasks/ragel_task.rb +70 -0
- data/tasks/rdoc.rake +9 -0
- data/tasks/release.rake +30 -0
- data/tasks/rspec.rake +8 -0
- metadata +609 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'gherkin/formatter/model'
|
3
|
+
require 'gherkin/formatter/argument'
|
4
|
+
require 'gherkin/native'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module Gherkin
|
8
|
+
class JSONParser
|
9
|
+
native_impl('gherkin')
|
10
|
+
|
11
|
+
include Base64
|
12
|
+
|
13
|
+
def initialize(formatter)
|
14
|
+
@formatter = formatter
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parse a gherkin object +o+, which can either be a JSON String,
|
18
|
+
# or a Hash (from a parsed JSON String).
|
19
|
+
def parse(o, feature_uri='unknown.json', line_offset=0)
|
20
|
+
o = JSON.parse(o) if String === o
|
21
|
+
@formatter.uri(feature_uri)
|
22
|
+
|
23
|
+
Formatter::Model::Feature.new(comments(o), tags(o), keyword(o), name(o), description(o), line(o)).replay(@formatter)
|
24
|
+
(o["elements"] || []).each do |feature_element|
|
25
|
+
feature_element(feature_element).replay(@formatter)
|
26
|
+
(feature_element["steps"] || []).each do |step|
|
27
|
+
step(step).replay(@formatter)
|
28
|
+
match(step)
|
29
|
+
result(step)
|
30
|
+
embeddings(step)
|
31
|
+
end
|
32
|
+
(feature_element["examples"] || []).each do |eo|
|
33
|
+
Formatter::Model::Examples.new(comments(eo), tags(eo), keyword(eo), name(eo), description(eo), line(eo), rows(eo['rows'])).replay(@formatter)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@formatter.eof
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def feature_element(o)
|
43
|
+
case o['type']
|
44
|
+
when 'background'
|
45
|
+
Formatter::Model::Background.new(comments(o), keyword(o), name(o), description(o), line(o))
|
46
|
+
when 'scenario'
|
47
|
+
Formatter::Model::Scenario.new(comments(o), tags(o), keyword(o), name(o), description(o), line(o))
|
48
|
+
when 'scenario_outline'
|
49
|
+
Formatter::Model::ScenarioOutline.new(comments(o), tags(o), keyword(o), name(o), description(o), line(o))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def step(o)
|
54
|
+
step = Formatter::Model::Step.new(comments(o), keyword(o), name(o), line(o))
|
55
|
+
|
56
|
+
if(ma = o['multiline_arg'])
|
57
|
+
if(ma['type'] == 'table')
|
58
|
+
step.multiline_arg = rows(ma['value'])
|
59
|
+
else
|
60
|
+
step.multiline_arg = Formatter::Model::PyString.new(ma['value'], ma['line'])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
step
|
65
|
+
end
|
66
|
+
|
67
|
+
def match(o)
|
68
|
+
if(m = o['match'])
|
69
|
+
Formatter::Model::Match.new(arguments(m), location(m)).replay(@formatter)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def result(o)
|
74
|
+
if(r = o['result'])
|
75
|
+
Formatter::Model::Result.new(status(r), duration(r), error_message(r)).replay(@formatter)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def embeddings(o)
|
80
|
+
(o['embeddings'] || []).each do |embedding|
|
81
|
+
@formatter.embedding(embedding['mime_type'], Base64::decode64(embedding['data']))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def rows(o)
|
86
|
+
o.map{|row| Formatter::Model::Row.new(comments(row), row['cells'], row['line'])}
|
87
|
+
end
|
88
|
+
|
89
|
+
def comments(o)
|
90
|
+
(o['comments'] || []).map do |comment|
|
91
|
+
Formatter::Model::Comment.new(comment['value'], comment['line'])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def tags(o)
|
96
|
+
(o['tags'] || []).map do |tag|
|
97
|
+
Formatter::Model::Tag.new(tag['name'], tag['line'])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def keyword(o)
|
102
|
+
o['keyword']
|
103
|
+
end
|
104
|
+
|
105
|
+
def name(o)
|
106
|
+
o['name']
|
107
|
+
end
|
108
|
+
|
109
|
+
def description(o)
|
110
|
+
o['description']
|
111
|
+
end
|
112
|
+
|
113
|
+
def line(o)
|
114
|
+
o['line']
|
115
|
+
end
|
116
|
+
|
117
|
+
def arguments(m)
|
118
|
+
m['arguments'].map{|a| Formatter::Argument.new(a['offset'], a['val'])}
|
119
|
+
end
|
120
|
+
|
121
|
+
def location(m)
|
122
|
+
m['location']
|
123
|
+
end
|
124
|
+
|
125
|
+
def status(r)
|
126
|
+
r['status']
|
127
|
+
end
|
128
|
+
|
129
|
+
def duration(r)
|
130
|
+
r['duration']
|
131
|
+
end
|
132
|
+
|
133
|
+
def error_message(r)
|
134
|
+
r['error_message']
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'gherkin/i18n'
|
2
|
+
require 'gherkin/native'
|
3
|
+
|
4
|
+
module Gherkin
|
5
|
+
module Lexer
|
6
|
+
I18nLexerNotFound = Class.new(LoadError)
|
7
|
+
LexingError = Class.new(StandardError)
|
8
|
+
|
9
|
+
# The main entry point to lexing Gherkin source.
|
10
|
+
class I18nLexer
|
11
|
+
native_impl('gherkin')
|
12
|
+
|
13
|
+
COMMENT_OR_EMPTY_LINE_PATTERN = /^\s*#|^\s*$/
|
14
|
+
LANGUAGE_PATTERN = /^\s*#\s*language\s*:\s*([a-zA-Z\-]+)/ #:nodoc:
|
15
|
+
attr_reader :i18n_language
|
16
|
+
|
17
|
+
def initialize(listener, force_ruby=false)
|
18
|
+
@listener = listener
|
19
|
+
@force_ruby = force_ruby
|
20
|
+
end
|
21
|
+
|
22
|
+
def scan(source)
|
23
|
+
create_delegate(source).scan(source)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create_delegate(source)
|
29
|
+
@i18n_language = lang(source)
|
30
|
+
@i18n_language.lexer(@listener, @force_ruby)
|
31
|
+
end
|
32
|
+
|
33
|
+
def lang(source)
|
34
|
+
key = 'en'
|
35
|
+
source.each_line do |line|
|
36
|
+
break unless COMMENT_OR_EMPTY_LINE_PATTERN =~ line
|
37
|
+
if LANGUAGE_PATTERN =~ line
|
38
|
+
key = $1
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
I18n.get(key)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Gherkin
|
2
|
+
module Listener
|
3
|
+
class Event < Array
|
4
|
+
def event
|
5
|
+
self[0]
|
6
|
+
end
|
7
|
+
|
8
|
+
def keyword
|
9
|
+
self[1]
|
10
|
+
end
|
11
|
+
|
12
|
+
def line_match?(lines)
|
13
|
+
lines.include?(line)
|
14
|
+
end
|
15
|
+
|
16
|
+
def name_match?(name_regexen)
|
17
|
+
return false unless [:feature, :background, :scenario, :scenario_outline, :examples].include?(event)
|
18
|
+
name_regexen.detect{|name_regex| name =~ name_regex}
|
19
|
+
end
|
20
|
+
|
21
|
+
def replay(listener)
|
22
|
+
begin
|
23
|
+
listener.__send__(event, *args)
|
24
|
+
rescue ArgumentError => e
|
25
|
+
e.message << "\nListener: #{listener.class}, args: #{args.inspect}"
|
26
|
+
raise e
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def name
|
33
|
+
self[2]
|
34
|
+
end
|
35
|
+
|
36
|
+
def line
|
37
|
+
self[-1]
|
38
|
+
end
|
39
|
+
|
40
|
+
def args
|
41
|
+
self[1..-1]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'gherkin/native'
|
2
|
+
require 'gherkin/formatter/model'
|
3
|
+
|
4
|
+
module Gherkin
|
5
|
+
module Listener
|
6
|
+
# Adapter from the "raw" Gherkin <tt>Listener</tt> API
|
7
|
+
# to the slightly more high-level <tt>Formatter</tt> API,
|
8
|
+
# which is easier to implement (less state to keep track of).
|
9
|
+
class FormatterListener
|
10
|
+
native_impl('gherkin')
|
11
|
+
|
12
|
+
def initialize(formatter)
|
13
|
+
@formatter = formatter
|
14
|
+
@comments = []
|
15
|
+
@tags = []
|
16
|
+
@table = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def comment(value, line)
|
20
|
+
@comments << Formatter::Model::Comment.new(value, line)
|
21
|
+
end
|
22
|
+
|
23
|
+
def tag(name, line)
|
24
|
+
@tags << Formatter::Model::Tag.new(name, line)
|
25
|
+
end
|
26
|
+
|
27
|
+
def feature(keyword, name, description, line)
|
28
|
+
@formatter.feature(Formatter::Model::Feature.new(grab_comments!, grab_tags!, keyword, name, description, line))
|
29
|
+
end
|
30
|
+
|
31
|
+
def background(keyword, name, description, line)
|
32
|
+
@formatter.background(Formatter::Model::Background.new(grab_comments!, keyword, name, description, line))
|
33
|
+
end
|
34
|
+
|
35
|
+
def scenario(keyword, name, description, line)
|
36
|
+
replay_step_or_examples
|
37
|
+
@formatter.scenario(Formatter::Model::Scenario.new(grab_comments!, grab_tags!, keyword, name, description, line))
|
38
|
+
end
|
39
|
+
|
40
|
+
def scenario_outline(keyword, name, description, line)
|
41
|
+
replay_step_or_examples
|
42
|
+
@formatter.scenario_outline(Formatter::Model::ScenarioOutline.new(grab_comments!, grab_tags!, keyword, name, description, line))
|
43
|
+
end
|
44
|
+
|
45
|
+
def examples(keyword, name, description, line)
|
46
|
+
replay_step_or_examples
|
47
|
+
@examples_statement = Formatter::Model::Examples.new(grab_comments!, grab_tags!, keyword, name, description, line)
|
48
|
+
end
|
49
|
+
|
50
|
+
def step(keyword, name, line)
|
51
|
+
replay_step_or_examples
|
52
|
+
@step_statement = Formatter::Model::Step.new(grab_comments!, keyword, name, line)
|
53
|
+
end
|
54
|
+
|
55
|
+
def row(cells, line)
|
56
|
+
@table ||= []
|
57
|
+
@table << Formatter::Model::Row.new(grab_comments!, cells, line)
|
58
|
+
end
|
59
|
+
|
60
|
+
def py_string(string, line)
|
61
|
+
@py_string = Formatter::Model::PyString.new(string, line)
|
62
|
+
end
|
63
|
+
|
64
|
+
def eof
|
65
|
+
replay_step_or_examples
|
66
|
+
@formatter.eof
|
67
|
+
end
|
68
|
+
|
69
|
+
def syntax_error(state, ev, legal_events, uri, line)
|
70
|
+
@formatter.syntax_error(state, ev, legal_events, uri, line)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def grab_comments!
|
76
|
+
comments = @comments
|
77
|
+
@comments = []
|
78
|
+
comments
|
79
|
+
end
|
80
|
+
|
81
|
+
def grab_tags!
|
82
|
+
tags = @tags
|
83
|
+
@tags = []
|
84
|
+
tags
|
85
|
+
end
|
86
|
+
|
87
|
+
def grab_rows!
|
88
|
+
table = @table
|
89
|
+
@table = nil
|
90
|
+
table
|
91
|
+
end
|
92
|
+
|
93
|
+
def grab_py_string!
|
94
|
+
py_string = @py_string
|
95
|
+
@py_string = nil
|
96
|
+
py_string
|
97
|
+
end
|
98
|
+
|
99
|
+
def replay_step_or_examples
|
100
|
+
if(@step_statement)
|
101
|
+
@step_statement.multiline_arg = grab_py_string! || grab_rows!
|
102
|
+
@formatter.step(@step_statement)
|
103
|
+
@step_statement = nil
|
104
|
+
end
|
105
|
+
if(@examples_statement)
|
106
|
+
@examples_statement.rows = grab_rows!
|
107
|
+
@formatter.examples(@examples_statement)
|
108
|
+
@examples_statement = nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Class
|
2
|
+
|
3
|
+
def implements(java_class_name)
|
4
|
+
m = java_class_name.split('.').inject(Object) do |mod, name|
|
5
|
+
mod = mod.const_get(name)
|
6
|
+
end
|
7
|
+
include m
|
8
|
+
end
|
9
|
+
|
10
|
+
# Causes a .NET class to be instantiated instead of the Ruby class when
|
11
|
+
# running on IronRuby. This is used to test both pure .NET and pure Ruby classes
|
12
|
+
# from the same Ruby based test suite. The .NET Class must have a package name
|
13
|
+
# that corresponds with the Ruby class.
|
14
|
+
def native_impl(lib)
|
15
|
+
begin
|
16
|
+
load_assembly(lib)
|
17
|
+
rescue LoadError => e
|
18
|
+
e.message << "\nTry this: SET MONO_PATH=#{File.expand_path(File.dirname(__FILE__) + '/../..')} (or export MONO_PATH=...)"
|
19
|
+
raise e
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def ikvmify(arg)
|
24
|
+
if Array === arg
|
25
|
+
arg.map{|a| ikvmify(a)}
|
26
|
+
else
|
27
|
+
case(arg)
|
28
|
+
when Regexp
|
29
|
+
Object.const_get('java').const_get('util').const_get('regex').const_get('Pattern').compile(arg.source)
|
30
|
+
else
|
31
|
+
arg
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def new(*args)
|
37
|
+
ikvm_class.new(*ikvmify(args))
|
38
|
+
end
|
39
|
+
|
40
|
+
def ===(object)
|
41
|
+
super || object.java_kind_of?(java_class)
|
42
|
+
end
|
43
|
+
|
44
|
+
def ikvm_class
|
45
|
+
names = self.name.split('::')
|
46
|
+
namespace = Object
|
47
|
+
names[0..-2].each do |module_name|
|
48
|
+
namespace = namespace.const_get(module_name.downcase)
|
49
|
+
end
|
50
|
+
|
51
|
+
namespace.const_get(names[-1])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Class
|
2
|
+
|
3
|
+
def implements(java_class_name)
|
4
|
+
# no-op
|
5
|
+
end
|
6
|
+
|
7
|
+
# Causes a Java class to be instantiated instead of the Ruby class when
|
8
|
+
# running on JRuby. This is used to test both pure Java and pure Ruby classes
|
9
|
+
# from the same Ruby based test suite. The Java Class must have a package name
|
10
|
+
# that corresponds with the Ruby class.
|
11
|
+
def native_impl(lib)
|
12
|
+
require "#{lib}.jar"
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def javaify(arg)
|
16
|
+
if Array === arg
|
17
|
+
arg.map{|a| javaify(a)}
|
18
|
+
else
|
19
|
+
case(arg)
|
20
|
+
when Regexp
|
21
|
+
java.util.regex.Pattern.compile(arg.source)
|
22
|
+
else
|
23
|
+
arg
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def new(*args)
|
29
|
+
begin
|
30
|
+
java_class.new(*javaify(args))
|
31
|
+
rescue ArgumentError => e
|
32
|
+
e.message << "\n#{java_class.name}"
|
33
|
+
raise e
|
34
|
+
rescue NameError => e
|
35
|
+
e.message << "\n args: #{args.inspect}"
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def ===(object)
|
41
|
+
super || object.java_kind_of?(java_class)
|
42
|
+
end
|
43
|
+
|
44
|
+
def java_class
|
45
|
+
names = self.name.split('::')
|
46
|
+
package = Java
|
47
|
+
names[0..-2].each do |module_name|
|
48
|
+
package = package.__send__(module_name.downcase)
|
49
|
+
end
|
50
|
+
|
51
|
+
package.__send__(names[-1])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|