neuroncheck 0.1.0 → 0.1.1
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 +4 -4
- data/lib/neuroncheck/builtin_keyword.rb +55 -55
- data/lib/neuroncheck/cond_block.rb +30 -30
- data/lib/neuroncheck/declaration.rb +288 -288
- data/lib/neuroncheck/error.rb +6 -6
- data/lib/neuroncheck/kernel.rb +598 -598
- data/lib/neuroncheck/matcher.rb +229 -229
- data/lib/neuroncheck/plugin.rb +144 -144
- data/lib/neuroncheck/syntax.rb +44 -44
- data/lib/neuroncheck/utils.rb +80 -80
- data/lib/neuroncheck/version.rb +1 -1
- data/test/test_advanced_syntactical.rb +101 -101
- data/test/test_inheritance.rb +140 -140
- data/test/test_main.rb +863 -863
- data/test/test_main_syntax.rb +219 -219
- data/test/test_plugin.rb +77 -77
- metadata +1 -1
data/lib/neuroncheck/version.rb
CHANGED
@@ -4,122 +4,122 @@ require 'neuroncheck'
|
|
4
4
|
|
5
5
|
# スクリプトエラーのチェック
|
6
6
|
class ScriptErrorTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
# 二重に定義することはできない
|
8
|
+
test 'double declaration' do
|
9
|
+
assert_raise(NeuronCheckSystem::DeclarationError) do
|
10
|
+
module Foo2
|
11
|
+
extend NeuronCheck
|
12
|
+
|
13
|
+
ndecl {
|
14
|
+
}
|
15
|
+
|
16
|
+
ndecl {
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# ndeclを複数回定義してもエラーにならないことと、1回しか呼ばれないことをチェック
|
24
24
|
class MultipleDeclareTest < Test::Unit::TestCase
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
25
|
+
def self.counter; @counter; end
|
26
|
+
def self.counter=(v); @counter = v; end
|
27
|
+
test "" do
|
28
|
+
cls = Class.new
|
29
|
+
MultipleDeclareTest.counter = 0
|
30
|
+
|
31
|
+
assert_nothing_raised(NeuronCheckSystem::DeclarationError){
|
32
|
+
cls.class_eval do
|
33
|
+
extend NeuronCheck
|
34
|
+
|
35
|
+
3.times do
|
36
|
+
ndecl {
|
37
|
+
args String
|
38
|
+
}
|
39
|
+
|
40
|
+
def foo_method(arg)
|
41
|
+
MultipleDeclareTest.counter += 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
cls.new.foo_method('')
|
48
|
+
assert_equal(1, MultipleDeclareTest.counter)
|
49
|
+
|
50
|
+
assert_raise(NeuronCheckError){
|
51
|
+
cls.new.foo_method(1)
|
52
|
+
}
|
53
|
+
end
|
54
54
|
end
|
55
55
|
|
56
56
|
# もともとmethod_addedが定義されていたときに両方とも呼ばれるかどうかのチェック
|
57
57
|
class MethodAddedPreservedTest < Test::Unit::TestCase
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
58
|
+
test 'define method_added -> extend NeuronCheck' do
|
59
|
+
class Foo3
|
60
|
+
def self.original_method_added_called; @original_method_added_called; end
|
61
|
+
def self.method_added(name)
|
62
|
+
super
|
63
|
+
@original_method_added_called = true
|
64
|
+
end
|
65
|
+
extend NeuronCheck
|
66
|
+
|
67
|
+
ndecl {
|
68
|
+
args String
|
69
|
+
}
|
70
|
+
def foo3_method(arg1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
assert(Foo3.original_method_added_called)
|
75
|
+
|
76
|
+
assert_raise(NeuronCheckError) do
|
77
|
+
Foo3.new.foo3_method(nil)
|
78
|
+
end
|
79
|
+
end
|
80
80
|
end
|
81
81
|
|
82
82
|
|
83
83
|
# もともとsingleton_method_addedが定義されていたときに呼ばれるかどうかのチェック
|
84
84
|
class SingletonMethodAddedPreservedTest < Test::Unit::TestCase
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
85
|
+
test 'define method_added -> extend NeuronCheck' do
|
86
|
+
class Foo1
|
87
|
+
def self.original_singleton_method_added_called; @original_singleton_method_added_called; end
|
88
|
+
def self.original_singleton_method_added_called=(v); @original_singleton_method_added_called = v; end
|
89
|
+
|
90
|
+
def self.singleton_method_added(name)
|
91
|
+
@original_singleton_method_added_called = true
|
92
|
+
end
|
93
|
+
|
94
|
+
extend NeuronCheck
|
95
|
+
|
96
|
+
ndecl {
|
97
|
+
args String
|
98
|
+
}
|
99
|
+
def foo1_method(arg1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Foo1.original_singleton_method_added_called = false
|
104
|
+
def Foo1.test1
|
105
|
+
p 1
|
106
|
+
end
|
107
|
+
assert{ Foo1.original_singleton_method_added_called }
|
108
|
+
|
109
|
+
assert_raise(NeuronCheckError) do
|
110
|
+
Foo1.new.foo1_method(nil)
|
111
|
+
end
|
112
|
+
end
|
113
113
|
end
|
114
114
|
|
115
115
|
# 複数回extendしても例外は発生しないか?
|
116
116
|
class MultipleExtendTest < Test::Unit::TestCase
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
test 'define method_added -> extend NeuronCheck' do
|
118
|
+
assert_nothing_raised do
|
119
|
+
module Foo3
|
120
|
+
extend NeuronCheck
|
121
|
+
extend NeuronCheck
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
125
|
end
|
data/test/test_inheritance.rb
CHANGED
@@ -4,150 +4,150 @@ require 'neuroncheck'
|
|
4
4
|
|
5
5
|
# 継承時のチェック
|
6
6
|
class InheritanceTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
7
|
+
def setup
|
8
|
+
parent_cls = Class.new do
|
9
|
+
extend NeuronCheck
|
10
|
+
|
11
|
+
ndecl {
|
12
|
+
args /a/
|
13
|
+
returns /A/
|
14
|
+
}
|
15
|
+
def test1(name, ret)
|
16
|
+
ret
|
17
|
+
end
|
18
|
+
|
19
|
+
ndecl {
|
20
|
+
args /c/
|
21
|
+
returns /C/
|
22
|
+
}
|
23
|
+
def test2_only_parent(name, ret)
|
24
|
+
ret
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
ndecl {
|
29
|
+
precond do
|
30
|
+
assert{arg1 =~ /a/}
|
31
|
+
end
|
32
|
+
|
33
|
+
postcond do |ret|
|
34
|
+
assert{ret =~ /A/}
|
35
|
+
end
|
36
|
+
}
|
37
|
+
def cond_test1(arg1, ret1)
|
38
|
+
ret1
|
39
|
+
end
|
40
|
+
|
41
|
+
ndecl {
|
42
|
+
val String
|
43
|
+
}
|
44
|
+
attr_accessor :attr1
|
45
|
+
end
|
46
|
+
|
47
|
+
child_cls = Class.new(parent_cls) do
|
48
|
+
extend NeuronCheck
|
49
|
+
|
50
|
+
ndecl {
|
51
|
+
args /b/
|
52
|
+
returns /B/
|
53
|
+
}
|
54
|
+
def test1(name, ret = 'ABC')
|
55
|
+
super
|
56
|
+
|
57
|
+
ret
|
58
|
+
end
|
59
|
+
|
60
|
+
ndecl {
|
61
|
+
precond do
|
62
|
+
assert{ arg1 =~ /b/ }
|
63
|
+
end
|
64
|
+
|
65
|
+
postcond do |ret|
|
66
|
+
assert{ ret =~ /B/ }
|
67
|
+
end
|
68
|
+
}
|
69
|
+
def cond_test1(arg1, ret1 = 'ABC')
|
70
|
+
super
|
71
|
+
|
72
|
+
ret1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
@parent_inst = parent_cls.new
|
77
|
+
@inst = child_cls.new
|
78
|
+
end
|
79
|
+
|
80
|
+
# 親の引数チェックを引き継ぐ
|
81
|
+
test 'arguments check inherited by superclass' do
|
82
|
+
assert_raise(NeuronCheckError){ @inst.test1(nil) }
|
83
|
+
assert_raise(NeuronCheckError){ @inst.test1('') }
|
84
|
+
assert_raise(NeuronCheckError){ @inst.test1('a123') }
|
85
|
+
assert_raise(NeuronCheckError){ @inst.test1('b123') }
|
86
|
+
assert_nothing_raised{ @inst.test1('a123b') }
|
87
|
+
end
|
88
|
+
|
89
|
+
# 親の引数チェックを引き継ぐ (子で再定義されていない場合)
|
90
|
+
test 'arguments check inherited by superclass (without child overridding)' do
|
91
|
+
assert_raise(NeuronCheckError){ @inst.test2_only_parent('c', 10) }
|
92
|
+
assert_raise(NeuronCheckError){ @inst.test2_only_parent('a', 'C') }
|
93
|
+
assert_nothing_raised{ @inst.test2_only_parent('c', 'C') }
|
94
|
+
end
|
95
|
+
|
96
|
+
# 親の戻り値チェックを引き継ぐ
|
97
|
+
test 'results check inherited by superclass' do
|
98
|
+
assert_raise(NeuronCheckError){ @inst.test1('ab', 'AC') }
|
99
|
+
assert_raise(NeuronCheckError){ @inst.test1('ab', 'BC') }
|
100
|
+
assert_nothing_raised{ @inst.test1('ab', 'aaABC') }
|
101
|
+
end
|
102
|
+
# 親の事前条件チェックを引き継ぐ
|
103
|
+
test 'precond check inherited by superclass' do
|
104
|
+
assert_raise(NeuronCheckError){ @inst.cond_test1(nil) }
|
105
|
+
assert_raise(NeuronCheckError){ @inst.cond_test1('') }
|
106
|
+
assert_raise(NeuronCheckError){ @inst.cond_test1('a123') }
|
107
|
+
assert_raise(NeuronCheckError){ @inst.cond_test1('b123') }
|
108
|
+
assert_nothing_raised{ @inst.cond_test1('a123b') }
|
109
|
+
end
|
110
|
+
|
111
|
+
# 親の事後条件チェックを引き継ぐ
|
112
|
+
test 'postcond check inherited by superclass' do
|
113
|
+
assert_raise(NeuronCheckError){ @inst.cond_test1('ab', 'AC') }
|
114
|
+
assert_raise(NeuronCheckError){ @inst.cond_test1('ab', 'BC') }
|
115
|
+
assert_nothing_raised{ @inst.cond_test1('ab', 'aaABC') }
|
116
|
+
end
|
117
|
+
|
118
|
+
# 親の属性チェックを引き継ぐ
|
119
|
+
test 'attribute check inherited by superclass' do
|
120
|
+
assert_raise(NeuronCheckError){ @inst.attr1 = 30 }
|
121
|
+
assert_nothing_raised{ @inst.attr1 = '1s' }
|
122
|
+
end
|
123
123
|
end
|
124
124
|
|
125
125
|
# 親と子でそれぞれ別々にextendした場合
|
126
126
|
class InheritanceOtherExtendTest < Test::Unit::TestCase
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
128
|
+
# 親のみextend
|
129
|
+
test 'extend only Parent' do
|
130
|
+
par_cls = Class.new do
|
131
|
+
extend NeuronCheck
|
132
|
+
|
133
|
+
ndecl {
|
134
|
+
args String
|
135
|
+
}
|
136
|
+
def foo_method(str1)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
chd_cls = Class.new(par_cls) do
|
141
|
+
ndecl {
|
142
|
+
args String
|
143
|
+
}
|
144
|
+
def bar_method(str2)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
chd = chd_cls.new
|
149
|
+
assert_raise(NeuronCheckError){ chd.foo_method(1) }
|
150
|
+
assert_raise(NeuronCheckError){ chd.bar_method(2) }
|
151
|
+
end
|
152
152
|
|
153
153
|
end
|