iba 0.0.2 → 0.0.3
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.
- checksums.yaml +7 -0
- data/Rakefile +16 -1
- data/lib/iba.rb +157 -138
- data/test/.rubocop.yml +10 -0
- data/test/analyse_test.rb +13 -14
- data/test/assert_test.rb +13 -20
- data/test/call_test.rb +1 -1
- data/test/display_test.rb +19 -19
- data/test/test_helper.rb +2 -3
- metadata +48 -55
- data/tasks/notes.rake +0 -122
- data/tasks/setup.rb +0 -6
- data/tasks/test.rake +0 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14fbefc240682b4cf95c79cf93598e2e8b12dd70
|
4
|
+
data.tar.gz: c3501eda480f88b302353c718a3a452d470c94d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c13f36b28278479f94947f0c62c3fb600d16c5c3db034825fb580b6d4d76f61e00a7c6110661720a22cd525e3054894d599fd355241c3ac2be03c67adfa56927
|
7
|
+
data.tar.gz: 0a5e9b56dcbde33f6033d32ec7117ce03ff3dc37c158b5cfd2da323d5880508b2dae6ddf585d88b38c6639d286198a3180bfd87166795d58053ddf2f898b0815
|
data/Rakefile
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
-
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = ['lib']
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
t.ruby_opts += ['-w']
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Alias to test:run'
|
16
|
+
task :test => 'test:run'
|
2
17
|
|
3
18
|
task :default => 'test:run'
|
data/lib/iba.rb
CHANGED
@@ -1,186 +1,205 @@
|
|
1
1
|
module Iba
|
2
|
+
class Combinator
|
3
|
+
def initialize &blk
|
4
|
+
@block = blk
|
5
|
+
end
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
@block.call
|
10
|
-
end
|
7
|
+
def call
|
8
|
+
@block.call
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def to_s
|
12
|
+
expression._to_s
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def expression
|
16
|
+
@expression ||= EmptyExpression.new._parse(&@block)
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
19
|
+
def analyse
|
20
|
+
str = "#{self} is #{call.inspect}"
|
21
|
+
if expression.class == MethodCallExpression && expression._method == :==
|
22
|
+
lft = expression._reciever
|
23
|
+
rgt = expression._args.first
|
24
|
+
exprs = [lft, rgt].map { |e| display_subexpression e }.compact
|
25
|
+
str << "\n"
|
26
|
+
str << exprs.join(', ')
|
27
|
+
end
|
28
|
+
str
|
29
|
+
end
|
32
30
|
|
33
|
-
|
31
|
+
private
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
def display_subexpression expr
|
34
|
+
if expr.class == LiteralExpression
|
35
|
+
nil
|
36
|
+
else
|
37
|
+
str = expr._to_s
|
38
|
+
"#{str} is #{eval(str, @block.binding).inspect}"
|
39
|
+
end
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
|
-
|
43
|
+
class EmptyExpression
|
44
|
+
def method_missing method, *args
|
45
|
+
MethodCallExpression.new self, method, args
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def _parse &blk
|
49
|
+
b = blk.binding
|
50
|
+
|
51
|
+
vars = eval 'local_variables', b
|
52
|
+
ivars = eval 'instance_variables', b
|
50
53
|
|
51
|
-
|
52
|
-
b = blk.binding
|
54
|
+
_override_instance_variables ivars
|
53
55
|
|
54
|
-
|
55
|
-
ivars = eval "instance_variables", b
|
56
|
+
_override_local_variables vars, b
|
56
57
|
|
57
|
-
|
58
|
+
result = instance_eval(&blk)
|
59
|
+
unless result.class == MethodCallExpression
|
60
|
+
result = LiteralExpression.new(result)
|
61
|
+
end
|
58
62
|
|
59
|
-
|
63
|
+
_restore_local_variables vars, b
|
60
64
|
|
61
|
-
|
62
|
-
unless result.class == MethodCallExpression
|
63
|
-
result = LiteralExpression.new(result)
|
65
|
+
result
|
64
66
|
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def _override_instance_variables vars
|
69
|
+
vars.each do |v|
|
70
|
+
next if v =~ /^@_/
|
71
|
+
eval "#{v} = Iba::MethodCallExpression.new(Iba::EmptyExpression.new, :#{v}, [])"
|
72
|
+
end
|
73
|
+
end
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
+
def _override_local_variables vars, b
|
76
|
+
vars.each do |v|
|
77
|
+
next if v =~ /^_/
|
78
|
+
eval "_#{v} = #{v}", b
|
79
|
+
eval "#{v} = Iba::MethodCallExpression.new(Iba::EmptyExpression.new, :#{v}, [])", b
|
80
|
+
end
|
75
81
|
end
|
76
|
-
end
|
77
82
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
def _restore_local_variables vars, b
|
84
|
+
vars.each do |v|
|
85
|
+
next if v =~ /^_/
|
86
|
+
eval "#{v} = _#{v}", b
|
87
|
+
end
|
83
88
|
end
|
84
|
-
end
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
next if v =~ /^_/
|
89
|
-
eval "#{v} = _#{v}", b
|
90
|
+
def _to_s
|
91
|
+
''
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
class LiteralExpression
|
99
|
-
def initialize val
|
100
|
-
@value = val
|
101
|
-
end
|
95
|
+
class LiteralExpression
|
96
|
+
def initialize val
|
97
|
+
@value = val
|
98
|
+
end
|
102
99
|
|
103
|
-
|
104
|
-
|
100
|
+
def _to_s
|
101
|
+
@value.inspect
|
102
|
+
end
|
105
103
|
end
|
106
|
-
end
|
107
104
|
|
108
|
-
class MethodCallExpression
|
109
|
-
|
105
|
+
class MethodCallExpression
|
106
|
+
attr_reader :_method, :_reciever, :_args
|
110
107
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
108
|
+
def initialize reciever, methodname, args
|
109
|
+
@_reciever = reciever
|
110
|
+
@_method = methodname
|
111
|
+
@_args = args.map { |a| _wrap(a) }
|
112
|
+
end
|
116
113
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
114
|
+
def _to_s
|
115
|
+
rcv = @_reciever._to_s
|
116
|
+
args = @_args.map { |a| a.respond_to?(:_to_s) ? a._to_s : a.to_s }
|
117
|
+
|
118
|
+
if @_method == :[]
|
119
|
+
"#{rcv}[#{args[0]}]"
|
120
|
+
elsif method_is_operator?
|
121
|
+
case @_args.length
|
122
|
+
when 0
|
123
|
+
"#{@_method.to_s.sub(/@$/, '')}#{rcv}"
|
124
|
+
when 1
|
125
|
+
"(#{rcv} #{@_method} #{args.first})"
|
126
|
+
else
|
127
|
+
raise NotImplementedError
|
128
|
+
end
|
129
129
|
else
|
130
|
-
|
130
|
+
str = rcv == '' ? '' : "#{rcv}."
|
131
|
+
str << @_method.to_s
|
132
|
+
str << "(#{args.join(', ')})" unless @_args.empty?
|
133
|
+
str
|
131
134
|
end
|
132
|
-
else
|
133
|
-
str = rcv == "" ? "" : "#{rcv}."
|
134
|
-
str << @_method.to_s
|
135
|
-
unless @_args.empty?
|
136
|
-
str << "(#{args.join(', ')})"
|
137
|
-
end
|
138
|
-
str
|
139
135
|
end
|
140
|
-
end
|
141
136
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
137
|
+
def method_missing method, *args
|
138
|
+
super if method.to_s =~ /^_/
|
139
|
+
MethodCallExpression.new self, method, args
|
140
|
+
end
|
146
141
|
|
147
|
-
|
148
|
-
|
149
|
-
|
142
|
+
def method_is_operator?
|
143
|
+
@_method.to_s !~ /^[a-z]/
|
144
|
+
end
|
150
145
|
|
151
|
-
|
152
|
-
|
153
|
-
|
146
|
+
def to_s
|
147
|
+
method_missing :to_s
|
148
|
+
end
|
154
149
|
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
def == other
|
151
|
+
method_missing :==, other
|
152
|
+
end
|
158
153
|
|
159
|
-
|
154
|
+
private
|
160
155
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
156
|
+
def _wrap arg
|
157
|
+
if arg.class == MethodCallExpression
|
158
|
+
arg
|
159
|
+
else
|
160
|
+
LiteralExpression.new arg
|
161
|
+
end
|
166
162
|
end
|
167
163
|
end
|
168
|
-
end
|
169
164
|
|
170
|
-
module BlockAssertion
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
165
|
+
module BlockAssertion
|
166
|
+
if RUBY_VERSION < '1.9'
|
167
|
+
|
168
|
+
def assert *args
|
169
|
+
if block_given?
|
170
|
+
if yield
|
171
|
+
assert_block('true') { true }
|
172
|
+
else
|
173
|
+
msg = args.empty? ? '' : args.first
|
174
|
+
ana = Combinator.new(&Proc.new).analyse
|
175
|
+
assert_block(build_message msg, "#{ana}.") { false }
|
176
|
+
end
|
177
|
+
else
|
178
|
+
super
|
179
|
+
end
|
179
180
|
end
|
181
|
+
|
180
182
|
else
|
181
|
-
|
183
|
+
|
184
|
+
def assert *args
|
185
|
+
if block_given?
|
186
|
+
if yield
|
187
|
+
assert_block('true') { true }
|
188
|
+
else
|
189
|
+
msg = args.empty? ? '' : args.first
|
190
|
+
ana = Combinator.new(&Proc.new).analyse
|
191
|
+
assert_block(message(msg) { ana }) { false }
|
192
|
+
end
|
193
|
+
else
|
194
|
+
test, msg = *args
|
195
|
+
case msg
|
196
|
+
when nil, String
|
197
|
+
msg = message(msg) { '<false> is not true' }
|
198
|
+
end
|
199
|
+
super test, msg
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
182
203
|
end
|
183
204
|
end
|
184
205
|
end
|
185
|
-
|
186
|
-
end
|
data/test/.rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
inherit_from: ../.rubocop.yml
|
2
|
+
|
3
|
+
# We need to rescue Exception to test exceptions thrown by assert
|
4
|
+
# TODO: Remove once support for Ruby 1.8 is dropped.
|
5
|
+
Lint/RescueException:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
# Allow compact syntax when adding to Test::Unit::TestCase
|
9
|
+
Style/ClassAndModuleChildren:
|
10
|
+
Enabled: false
|
data/test/analyse_test.rb
CHANGED
@@ -3,41 +3,41 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
3
3
|
# Test how the combinator analyses the parsed block contents.
|
4
4
|
class AnalyseTest < Test::Unit::TestCase
|
5
5
|
def test_empty_block
|
6
|
-
assert_equal
|
6
|
+
assert_equal 'nil is nil', combinator {}.analyse
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_variable
|
10
10
|
foo = 23
|
11
|
-
assert_equal
|
11
|
+
assert_equal 'foo is 23', combinator { foo }.analyse
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_operator_equals
|
15
15
|
foo = 42
|
16
16
|
bar = 23
|
17
|
-
|
18
|
-
|
17
|
+
result = combinator { foo == bar }.analyse
|
18
|
+
assert_equal "(foo == bar) is false\nfoo is 42, bar is 23", result
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_operator_equals_literal
|
22
22
|
foo = 42
|
23
|
-
|
24
|
-
|
23
|
+
result = combinator { foo == 23 }.analyse
|
24
|
+
assert_equal "(foo == 23) is false\nfoo is 42", result
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_operator_equals_array_literal
|
28
|
-
foo = [1,
|
29
|
-
|
30
|
-
|
28
|
+
foo = [1, 'bar']
|
29
|
+
result = combinator { foo == [2, 'baz'] }.analyse
|
30
|
+
assert_equal "(foo == [2, \"baz\"]) is false\nfoo is [1, \"bar\"]", result
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_string_variable
|
34
|
-
foo =
|
34
|
+
foo = 'blub'
|
35
35
|
assert_equal "foo is \"blub\"", combinator { foo }.analyse
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_array_variable
|
39
39
|
foo = [1, 2]
|
40
|
-
assert_equal
|
40
|
+
assert_equal 'foo is [1, 2]', combinator { foo }.analyse
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_object_variable
|
@@ -47,12 +47,11 @@ class AnalyseTest < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_literal
|
50
|
-
assert_equal
|
50
|
+
assert_equal '23 is 23', combinator { 23 }.analyse
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_instance_variable
|
54
54
|
@foo = 23
|
55
|
-
assert_equal
|
55
|
+
assert_equal '@foo is 23', combinator { @foo }.analyse
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
data/test/assert_test.rb
CHANGED
@@ -7,15 +7,13 @@ class AssertTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def failing_block_assertion_test message, &block
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
assert_equal message, e.message
|
14
|
-
end
|
10
|
+
assert(&block)
|
11
|
+
rescue Exception => e
|
12
|
+
assert_equal message, e.message
|
15
13
|
end
|
16
14
|
|
17
15
|
def test_simple_failing_assert
|
18
|
-
failing_block_assertion_test(
|
16
|
+
failing_block_assertion_test('false is false.') { false }
|
19
17
|
end
|
20
18
|
|
21
19
|
def test_operator_equals_assert
|
@@ -33,26 +31,21 @@ class AssertTest < Test::Unit::TestCase
|
|
33
31
|
def test_assert_with_custom_message
|
34
32
|
foo = false
|
35
33
|
begin
|
36
|
-
assert(
|
34
|
+
assert('We want foo') { foo }
|
37
35
|
rescue Exception => e
|
38
36
|
assert_equal "We want foo.\nfoo is false.", e.message
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
assert_equal "<false> is not true.", e.message
|
47
|
-
end
|
40
|
+
def test_blockless_assert
|
41
|
+
assert false
|
42
|
+
rescue Exception => e
|
43
|
+
assert_equal '<false> is not true.', e.message
|
48
44
|
end
|
49
45
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
assert_equal "We want the truth.\n<false> is not true.", e.message
|
55
|
-
end
|
46
|
+
def test_blockless_assert_with_custom_message
|
47
|
+
assert false, 'We want the truth'
|
48
|
+
rescue Exception => e
|
49
|
+
assert_equal "We want the truth.\n<false> is not true.", e.message
|
56
50
|
end
|
57
51
|
end
|
58
|
-
|
data/test/call_test.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
3
3
|
# Test how the combinator calls the passed block.
|
4
4
|
class CallTest < Test::Unit::TestCase
|
5
5
|
def test_empty_combinator
|
6
|
-
assert_equal nil, combinator {
|
6
|
+
assert_equal nil, combinator {}.call
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_variable
|
data/test/display_test.rb
CHANGED
@@ -3,55 +3,55 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
3
3
|
# Test how the combinator displays the parsed block contents.
|
4
4
|
class DisplayTest < Test::Unit::TestCase
|
5
5
|
def test_empty_combinator
|
6
|
-
assert_equal
|
6
|
+
assert_equal 'nil', combinator {}.to_s
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_literal_number
|
10
|
-
assert_equal
|
10
|
+
assert_equal '23', combinator { 23 }.to_s
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_literal_string
|
14
|
-
assert_equal "\"aa\"", combinator {
|
14
|
+
assert_equal "\"aa\"", combinator { 'aa' }.to_s
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_method_calls
|
18
|
-
assert_equal
|
19
|
-
assert_equal
|
20
|
-
assert_equal
|
21
|
-
assert_equal
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
18
|
+
assert_equal 'foo', combinator { foo }.to_s
|
19
|
+
assert_equal 'foo.foo', combinator { foo.foo }.to_s
|
20
|
+
assert_equal 'foo.foo(1)', combinator { foo.foo 1 }.to_s
|
21
|
+
assert_equal 'foo(1)', combinator { foo 1 }.to_s
|
22
|
+
assert_equal 'foo(bar)', combinator { foo bar }.to_s
|
23
|
+
assert_equal 'foo(1).bar', combinator { foo(1).bar }.to_s
|
24
|
+
assert_equal 'foo.foo.foo', combinator { foo.foo.foo }.to_s
|
25
|
+
assert_equal 'foo(bar.baz)', combinator { foo bar.baz }.to_s
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_operators
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
29
|
+
assert_equal '(foo + 1)', combinator { foo + 1 }.to_s
|
30
|
+
assert_equal '(foo - 1)', combinator { foo - 1 }.to_s
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_operator_equals
|
34
|
-
assert_equal
|
34
|
+
assert_equal '(foo == 1)', combinator { foo == 1 }.to_s
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_array_index
|
38
|
-
assert_equal
|
38
|
+
assert_equal 'foo[1]', combinator { foo[1] }.to_s
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_to_s_method
|
42
|
-
assert_equal
|
42
|
+
assert_equal 'foo.to_s', combinator { foo.to_s }.to_s
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_operator_unary_minus
|
46
|
-
assert_equal
|
46
|
+
assert_equal '-foo', combinator { -foo }.to_s
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_operator_if_wont_work
|
50
|
-
assert_equal
|
50
|
+
assert_equal 'bar', combinator { foo ? bar : baz }.to_s
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_defined_instance_variables
|
54
54
|
@foo = 1
|
55
|
-
assert_equal
|
55
|
+
assert_equal '@foo', combinator { @foo }.to_s
|
56
56
|
end
|
57
57
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,11 +2,10 @@ require 'test/unit'
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'iba'
|
4
4
|
|
5
|
-
class Test::Unit::TestCase
|
5
|
+
class Test::Unit::TestCase
|
6
6
|
include Iba::BlockAssertion
|
7
7
|
|
8
8
|
def combinator &blk
|
9
|
-
|
9
|
+
Iba::Combinator.new(&blk)
|
10
10
|
end
|
11
|
-
|
12
11
|
end
|
metadata
CHANGED
@@ -1,89 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: iba
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Matijs van Zuijlen
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.1'
|
22
27
|
description: Asserts blocks, prints introspective failure messages.
|
23
|
-
email:
|
28
|
+
email:
|
24
29
|
- matijs@matijs.net
|
25
30
|
executables: []
|
26
|
-
|
27
31
|
extensions: []
|
28
|
-
|
29
|
-
extra_rdoc_files:
|
32
|
+
extra_rdoc_files:
|
30
33
|
- README.rdoc
|
31
34
|
- LICENSE
|
32
35
|
- COPYING.LESSER
|
33
36
|
- COPYING
|
34
|
-
files:
|
35
|
-
-
|
36
|
-
- test/analyse_test.rb
|
37
|
-
- test/test_helper.rb
|
38
|
-
- test/call_test.rb
|
39
|
-
- test/assert_test.rb
|
40
|
-
- test/display_test.rb
|
41
|
-
- tasks/test.rake
|
42
|
-
- tasks/setup.rb
|
43
|
-
- tasks/notes.rake
|
37
|
+
files:
|
38
|
+
- COPYING
|
44
39
|
- COPYING.LESSER
|
45
40
|
- LICENSE
|
46
41
|
- README.rdoc
|
47
42
|
- Rakefile
|
48
|
-
-
|
49
|
-
|
43
|
+
- lib/iba.rb
|
44
|
+
- test/.rubocop.yml
|
45
|
+
- test/analyse_test.rb
|
46
|
+
- test/assert_test.rb
|
47
|
+
- test/call_test.rb
|
48
|
+
- test/display_test.rb
|
49
|
+
- test/test_helper.rb
|
50
50
|
homepage: http://www.github.com/mvz/iba
|
51
51
|
licenses: []
|
52
|
-
|
52
|
+
metadata: {}
|
53
53
|
post_install_message:
|
54
|
-
rdoc_options:
|
55
|
-
- --main
|
54
|
+
rdoc_options:
|
55
|
+
- "--main"
|
56
56
|
- README.rdoc
|
57
|
-
require_paths:
|
57
|
+
require_paths:
|
58
58
|
- lib
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
|
61
|
-
requirements:
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
62
61
|
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
version: "0"
|
68
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
71
66
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
77
69
|
requirements: []
|
78
|
-
|
79
70
|
rubyforge_project:
|
80
|
-
rubygems_version:
|
71
|
+
rubygems_version: 2.4.5
|
81
72
|
signing_key:
|
82
|
-
specification_version:
|
73
|
+
specification_version: 4
|
83
74
|
summary: Introspective Block Assertions
|
84
|
-
test_files:
|
75
|
+
test_files:
|
76
|
+
- test/.rubocop.yml
|
85
77
|
- test/analyse_test.rb
|
86
78
|
- test/assert_test.rb
|
87
79
|
- test/call_test.rb
|
88
80
|
- test/display_test.rb
|
89
81
|
- test/test_helper.rb
|
82
|
+
has_rdoc:
|
data/tasks/notes.rake
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
# The following code is based on Bones 2.5.1
|
2
|
-
#
|
3
|
-
|
4
|
-
module Bones
|
5
|
-
|
6
|
-
# A helper class used to find and display any annotations in a collection of
|
7
|
-
# project files.
|
8
|
-
#
|
9
|
-
class AnnotationExtractor
|
10
|
-
|
11
|
-
class Annotation < Struct.new(:line, :tag, :text)
|
12
|
-
# Returns a string representation of the annotation. If the
|
13
|
-
# <tt>:tag</tt> parameter is given as +true+, then the annotation tag
|
14
|
-
# will be included in the string.
|
15
|
-
#
|
16
|
-
def to_s( opts = {} )
|
17
|
-
s = "[%3d] " % line
|
18
|
-
s << "[#{tag}] " if opts[:tag]
|
19
|
-
s << text
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Enumerate all the annoations for the given _project_ and _tag_. This
|
24
|
-
# will search for all athe annotations and display them on standard
|
25
|
-
# output.
|
26
|
-
#
|
27
|
-
def self.enumerate tag, id = nil, opts = {}
|
28
|
-
extractor = new(tag, id)
|
29
|
-
extractor.display(extractor.find, opts)
|
30
|
-
end
|
31
|
-
|
32
|
-
attr_reader :tag, :id
|
33
|
-
|
34
|
-
# Creates a new annotation extractor configured to use the _project_ open
|
35
|
-
# strcut and to search for the given _tag_ (which can be more than one tag
|
36
|
-
# via a regular expression 'or' operation -- i.e. THIS|THAT|OTHER)
|
37
|
-
#
|
38
|
-
def initialize tag, id
|
39
|
-
@tag = tag
|
40
|
-
@id = @id_rgxp = nil
|
41
|
-
|
42
|
-
unless id.nil? or id.empty?
|
43
|
-
@id = id
|
44
|
-
@id_rgxp = Regexp.new(Regexp.escape(id), Regexp::IGNORECASE)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Iterate over all the files in the project and extract annotations from
|
49
|
-
# the those files. Returns the results as a hash for display.
|
50
|
-
#
|
51
|
-
def find
|
52
|
-
results = {}
|
53
|
-
rgxp = %r/(#{tag}):?\s*(.*?)(?:\s*(?:-?%>|\*+\/))?$/o
|
54
|
-
|
55
|
-
files = Dir.glob("lib/**/*.rb")
|
56
|
-
files += Dir.glob("test/**/*.rb")
|
57
|
-
files += Dir.glob("bin/*")
|
58
|
-
files.each do |fn|
|
59
|
-
results.update(extract_annotations_from(fn, rgxp))
|
60
|
-
end
|
61
|
-
|
62
|
-
results
|
63
|
-
end
|
64
|
-
|
65
|
-
# Extract any annotations from the given _file_ using the regular
|
66
|
-
# expression _pattern_ provided.
|
67
|
-
#
|
68
|
-
def extract_annotations_from( file, pattern )
|
69
|
-
lineno = 0
|
70
|
-
result = File.readlines(file).inject([]) do |list, line|
|
71
|
-
lineno += 1
|
72
|
-
next list unless m = pattern.match(line)
|
73
|
-
next list << Annotation.new(lineno, m[1], m[2]) unless id
|
74
|
-
|
75
|
-
text = m[2]
|
76
|
-
if text =~ @id_rgxp
|
77
|
-
list << Annotation.new(lineno, m[1], text)
|
78
|
-
end
|
79
|
-
list
|
80
|
-
end
|
81
|
-
result.empty? ? {} : { file => result }
|
82
|
-
end
|
83
|
-
|
84
|
-
# Print the results of the annotation extraction to the screen. If the
|
85
|
-
# <tt>:tags</tt> option is set to +true+, then the annotation tag will be
|
86
|
-
# displayed.
|
87
|
-
#
|
88
|
-
def display( results, opts = {} )
|
89
|
-
results.keys.sort.each do |file|
|
90
|
-
puts "#{file}:"
|
91
|
-
results[file].each do |note|
|
92
|
-
puts " * #{note.to_s(opts)}"
|
93
|
-
end
|
94
|
-
puts
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end # class AnnotationExtractor
|
99
|
-
end # module Bones
|
100
|
-
|
101
|
-
note_tags = ["TODO", "FIXME", "OPTIMIZE"]
|
102
|
-
|
103
|
-
desc "Enumerate all annotations"
|
104
|
-
task :notes do |t|
|
105
|
-
id = if t.application.top_level_tasks.length > 1
|
106
|
-
t.application.top_level_tasks.slice!(1..-1).join(' ')
|
107
|
-
end
|
108
|
-
Bones::AnnotationExtractor.enumerate(
|
109
|
-
note_tags.join('|'), id, :tag => true)
|
110
|
-
end
|
111
|
-
|
112
|
-
namespace :notes do
|
113
|
-
note_tags.each do |tag|
|
114
|
-
desc "Enumerate all #{tag} annotations"
|
115
|
-
task tag.downcase.to_sym do |t|
|
116
|
-
id = if t.application.top_level_tasks.length > 1
|
117
|
-
t.application.top_level_tasks.slice!(1..-1).join(' ')
|
118
|
-
end
|
119
|
-
Bones::AnnotationExtractor.enumerate(tag, id)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
data/tasks/setup.rb
DELETED
data/tasks/test.rake
DELETED