ruby2c 1.0.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,74 +3,74 @@
3
3
  $TESTING = true
4
4
 
5
5
  require 'minitest/autorun' if $0 == __FILE__
6
- require 'minitest/unit'
6
+ require 'minitest/test'
7
7
  require 'function_table'
8
8
  require 'type'
9
9
 
10
- class TestFunctionTable < MiniTest::Unit::TestCase
10
+ class TestFunctionTable < Minitest::Test
11
11
 
12
12
  def setup
13
13
  @function_table = FunctionTable.new
14
14
  end
15
15
 
16
16
  def test_add_function
17
- type = @function_table.add_function :func, Type.long
17
+ type = @function_table.add_function :func, CType.long
18
18
 
19
- assert_equal Type.long, type
20
- assert_equal Type.long, @function_table[:func]
19
+ assert_equal CType.long, type
20
+ assert_equal CType.long, @function_table[:func]
21
21
  end
22
22
 
23
23
  def test_cheat
24
- @function_table.add_function :func, Type.long
25
- @function_table.add_function :func, Type.str
24
+ @function_table.add_function :func, CType.long
25
+ @function_table.add_function :func, CType.str
26
26
 
27
- assert_equal [Type.long, Type.str], @function_table.cheat(:func)
27
+ assert_equal [CType.long, CType.str], @function_table.cheat(:func)
28
28
  end
29
29
 
30
30
  def test_has_key?
31
- @function_table.add_function :func, Type.long
31
+ @function_table.add_function :func, CType.long
32
32
 
33
33
  assert_equal true, @function_table.has_key?(:func)
34
34
  assert_equal false, @function_table.has_key?('no such func')
35
35
  end
36
36
 
37
37
  def test_index
38
- @function_table.add_function :func, Type.long
38
+ @function_table.add_function :func, CType.long
39
39
 
40
- assert_equal Type.long, @function_table[:func]
40
+ assert_equal CType.long, @function_table[:func]
41
41
 
42
- @function_table.add_function :func, Type.str
42
+ @function_table.add_function :func, CType.str
43
43
 
44
- assert_equal Type.long, @function_table[:func]
44
+ assert_equal CType.long, @function_table[:func]
45
45
  end
46
46
 
47
47
  def test_unify_one_type
48
- @function_table.add_function :func, Type.unknown
48
+ @function_table.add_function :func, CType.unknown
49
49
 
50
- @function_table.unify :func, Type.long do
50
+ @function_table.unify :func, CType.long do
51
51
  flunk "Block should not have been called"
52
52
  end
53
53
 
54
- assert_equal Type.long, @function_table[:func]
54
+ assert_equal CType.long, @function_table[:func]
55
55
  end
56
56
 
57
57
  def test_unify_two_type
58
- @function_table.add_function :func, Type.unknown
59
- @function_table.add_function :func, Type.str
58
+ @function_table.add_function :func, CType.unknown
59
+ @function_table.add_function :func, CType.str
60
60
 
61
- @function_table.unify :func, Type.long do
61
+ @function_table.unify :func, CType.long do
62
62
  flunk "Block should not have been called"
63
63
  end
64
64
 
65
- assert_equal Type.long, @function_table[:func]
65
+ assert_equal CType.long, @function_table[:func]
66
66
  end
67
67
 
68
68
  def test_unify_block_called_no_type
69
- @function_table.add_function :func, Type.str
69
+ @function_table.add_function :func, CType.str
70
70
 
71
71
  test_var = false
72
72
 
73
- @function_table.unify :func, Type.long do
73
+ @function_table.unify :func, CType.long do
74
74
  test_var = true
75
75
  end
76
76
 
@@ -80,7 +80,7 @@ class TestFunctionTable < MiniTest::Unit::TestCase
80
80
  def test_unify_block_called_no_unify
81
81
  test_var = false
82
82
 
83
- @function_table.unify :func, Type.long do
83
+ @function_table.unify :func, CType.long do
84
84
  test_var = true
85
85
  end
86
86
 
@@ -3,53 +3,53 @@
3
3
  $TESTING = true
4
4
 
5
5
  require 'minitest/autorun' if $0 == __FILE__
6
- require 'minitest/unit'
6
+ require 'minitest/test'
7
7
  require 'function_type'
8
8
  require 'type'
9
9
 
10
- class TestFunctionType < MiniTest::Unit::TestCase
10
+ class TestFunctionType < Minitest::Test
11
11
  def setup
12
- @function_type = FunctionType.new Type.void, [Type.long, Type.str], Type.value
12
+ @function_type = FunctionType.new CType.void, [CType.long, CType.str], CType.value
13
13
  end
14
14
 
15
15
  def test_formal_types
16
- assert_equal [Type.long, Type.str], @function_type.formal_types
16
+ assert_equal [CType.long, CType.str], @function_type.formal_types
17
17
  end
18
18
 
19
19
  def test_formal_types=
20
- @function_type.formal_types = [Type.str, Type.long]
21
- assert_equal [Type.str, Type.long], @function_type.formal_types
20
+ @function_type.formal_types = [CType.str, CType.long]
21
+ assert_equal [CType.str, CType.long], @function_type.formal_types
22
22
  end
23
23
 
24
24
  def test_receiver_type
25
- assert_equal Type.void, @function_type.receiver_type
25
+ assert_equal CType.void, @function_type.receiver_type
26
26
  end
27
27
 
28
28
  def test_receiver_type=
29
- @function_type.receiver_type = Type.str
30
- assert_equal Type.str, @function_type.receiver_type
29
+ @function_type.receiver_type = CType.str
30
+ assert_equal CType.str, @function_type.receiver_type
31
31
  end
32
32
 
33
33
  def test_return_type
34
- assert_equal Type.value, @function_type.return_type
34
+ assert_equal CType.value, @function_type.return_type
35
35
  end
36
36
 
37
37
  def test_return_type=
38
- @function_type.return_type = Type.long
39
- assert_equal Type.long, @function_type.return_type
38
+ @function_type.return_type = CType.long
39
+ assert_equal CType.long, @function_type.return_type
40
40
  end
41
41
 
42
42
  def test_equals
43
43
  funs = []
44
- funs << FunctionType.new(Type.unknown, [], Type.unknown)
45
- funs << FunctionType.new(Type.unknown, [Type.unknown], Type.unknown)
46
- funs << FunctionType.new(Type.unknown, [], Type.long)
47
- funs << FunctionType.new(Type.unknown, [Type.long], Type.unknown)
48
- funs << FunctionType.new(Type.unknown, [Type.long], Type.long)
49
- funs << FunctionType.new(Type.unknown, [Type.unknown, Type.unknown], Type.unknown)
50
- funs << FunctionType.new(Type.unknown, [Type.long, Type.unknown], Type.unknown)
51
- funs << FunctionType.new(Type.unknown, [Type.long, Type.long], Type.long)
52
- #funs << FunctionType.new(Type.unknown, [], Type.long)
44
+ funs << FunctionType.new(CType.unknown, [], CType.unknown)
45
+ funs << FunctionType.new(CType.unknown, [CType.unknown], CType.unknown)
46
+ funs << FunctionType.new(CType.unknown, [], CType.long)
47
+ funs << FunctionType.new(CType.unknown, [CType.long], CType.unknown)
48
+ funs << FunctionType.new(CType.unknown, [CType.long], CType.long)
49
+ funs << FunctionType.new(CType.unknown, [CType.unknown, CType.unknown], CType.unknown)
50
+ funs << FunctionType.new(CType.unknown, [CType.long, CType.unknown], CType.unknown)
51
+ funs << FunctionType.new(CType.unknown, [CType.long, CType.long], CType.long)
52
+ #funs << FunctionType.new(CType.unknown, [], CType.long)
53
53
 
54
54
  funs.each_with_index do |fun1, i|
55
55
  funs.each_with_index do |fun2, j|
@@ -63,59 +63,59 @@ class TestFunctionType < MiniTest::Unit::TestCase
63
63
  end
64
64
 
65
65
  def test_unify_components
66
- fun1 = FunctionType.new(Type.unknown, [Type.unknown], Type.unknown)
67
- fun2 = FunctionType.new(Type.long, [Type.long], Type.long)
66
+ fun1 = FunctionType.new(CType.unknown, [CType.unknown], CType.unknown)
67
+ fun2 = FunctionType.new(CType.long, [CType.long], CType.long)
68
68
  fun1.unify_components fun2
69
69
  assert_equal fun2, fun1
70
70
 
71
- fun3 = FunctionType.new(Type.unknown, [Type.long], Type.unknown)
72
- fun4 = FunctionType.new(Type.long, [Type.unknown], Type.long)
71
+ fun3 = FunctionType.new(CType.unknown, [CType.long], CType.unknown)
72
+ fun4 = FunctionType.new(CType.long, [CType.unknown], CType.long)
73
73
  fun3.unify_components fun4
74
74
  assert_equal fun4, fun3
75
75
 
76
- fun5 = FunctionType.new(Type.unknown, [], Type.unknown)
77
- fun6 = FunctionType.new(Type.long, [], Type.long)
76
+ fun5 = FunctionType.new(CType.unknown, [], CType.unknown)
77
+ fun6 = FunctionType.new(CType.long, [], CType.long)
78
78
  fun5.unify_components fun6
79
79
  assert_equal fun6, fun5
80
80
  end
81
81
 
82
82
  def test_initialize_fail
83
83
  assert_raises(RuntimeError) do
84
- FunctionType.new(Type.unknown, nil, Type.long)
84
+ FunctionType.new(CType.unknown, nil, CType.long)
85
85
  end
86
86
 
87
87
  assert_raises(RuntimeError)do
88
- FunctionType.new(Type.unknown, [], nil)
88
+ FunctionType.new(CType.unknown, [], nil)
89
89
  end
90
90
  end
91
91
 
92
92
  def test_unify_components_fail
93
- fun1 = FunctionType.new(Type.long, [Type.str], Type.unknown)
94
- fun2 = FunctionType.new(Type.unknown, [Type.long], Type.long)
93
+ fun1 = FunctionType.new(CType.long, [CType.str], CType.unknown)
94
+ fun2 = FunctionType.new(CType.unknown, [CType.long], CType.long)
95
95
  assert_raises(TypeError) do
96
96
  fun1.unify_components fun2
97
97
  end
98
98
 
99
- fun3 = FunctionType.new(Type.long, [], Type.unknown)
100
- fun4 = FunctionType.new(Type.unknown, [Type.unknown], Type.long)
99
+ fun3 = FunctionType.new(CType.long, [], CType.unknown)
100
+ fun4 = FunctionType.new(CType.unknown, [CType.unknown], CType.long)
101
101
  assert_raises(TypeError) do
102
102
  fun3.unify_components fun4
103
103
  end
104
104
 
105
- fun5 = FunctionType.new(Type.long, [Type.unknown], Type.unknown)
106
- fun6 = FunctionType.new(Type.unknown, [], Type.long)
105
+ fun5 = FunctionType.new(CType.long, [CType.unknown], CType.unknown)
106
+ fun6 = FunctionType.new(CType.unknown, [], CType.long)
107
107
  assert_raises(TypeError) do
108
108
  fun5.unify_components fun6
109
109
  end
110
110
 
111
- fun7 = FunctionType.new(Type.long, [], Type.str)
112
- fun8 = FunctionType.new(Type.unknown, [], Type.long)
111
+ fun7 = FunctionType.new(CType.long, [], CType.str)
112
+ fun8 = FunctionType.new(CType.unknown, [], CType.long)
113
113
  assert_raises(TypeError) do
114
114
  fun7.unify_components fun8
115
115
  end
116
116
 
117
- fun9 = FunctionType.new(Type.long, [], Type.str)
118
- funa = FunctionType.new(Type.str, [], Type.unknown)
117
+ fun9 = FunctionType.new(CType.long, [], CType.str)
118
+ funa = FunctionType.new(CType.str, [], CType.unknown)
119
119
 
120
120
  fun9, funa = funa, fun9 # get rid of unused warnings but keep them rooted
121
121
 
@@ -125,4 +125,3 @@ class TestFunctionType < MiniTest::Unit::TestCase
125
125
  end
126
126
 
127
127
  end
128
-
@@ -3,10 +3,10 @@
3
3
  $TESTING = true
4
4
 
5
5
  require 'minitest/autorun' if $0 == __FILE__
6
- require 'minitest/unit'
6
+ require 'minitest/test'
7
7
  require 'handle'
8
8
 
9
- class TestHandle < MiniTest::Unit::TestCase
9
+ class TestHandle < Minitest::Test
10
10
 
11
11
  def setup
12
12
  @handle = Handle.new("text")
@@ -3,31 +3,31 @@
3
3
  $TESTING = true
4
4
 
5
5
  require 'minitest/autorun' if $0 == __FILE__
6
- require 'minitest/unit'
6
+ require 'minitest/test'
7
7
  require 'r2cenvironment'
8
8
  require 'type'
9
9
 
10
- class TestR2CEnvironment < MiniTest::Unit::TestCase
10
+ class TestR2CEnvironment < Minitest::Test
11
11
 
12
12
  def setup
13
13
  @env = R2CEnvironment.new
14
14
  end
15
15
 
16
16
  def test_add
17
- assert_equal Type.long, @env.add(:var, Type.long)
18
- assert_equal Type.long, @env.lookup(:var)
17
+ assert_equal CType.long, @env.add(:var, CType.long)
18
+ assert_equal CType.long, @env.lookup(:var)
19
19
  end
20
20
 
21
21
  def test_add_depth
22
22
  @env.scope do
23
- assert_equal Type.long, @env.add(:var, Type.long, 1)
23
+ assert_equal CType.long, @env.add(:var, CType.long, 1)
24
24
  end
25
- assert_equal Type.long, @env.lookup(:var)
25
+ assert_equal CType.long, @env.lookup(:var)
26
26
  end
27
27
 
28
28
  def test_add_raises_on_illegal
29
29
  assert_raises RuntimeError do
30
- @env.add nil, Type.long
30
+ @env.add nil, CType.long
31
31
  end
32
32
 
33
33
  assert_raises RuntimeError do
@@ -37,8 +37,8 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
37
37
 
38
38
  def test_add_segmented
39
39
  @env.scope do
40
- @env.add :var, Type.long
41
- assert_equal Type.long, @env.lookup(:var)
40
+ @env.add :var, CType.long
41
+ assert_equal CType.long, @env.lookup(:var)
42
42
  end
43
43
 
44
44
  assert_raises NameError do
@@ -47,30 +47,30 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
47
47
  end
48
48
 
49
49
  def test_current
50
- @env.add :var, Type.long
50
+ @env.add :var, CType.long
51
51
  @env.set_val :var, 42
52
-
53
- expected = { :var => [Type.long, 42] }
52
+
53
+ expected = { :var => [CType.long, 42] }
54
54
  assert_equal expected, @env.current
55
55
  end
56
56
 
57
57
  def test_all
58
58
  @env.scope do
59
- @env.add :x, Type.long
59
+ @env.add :x, CType.long
60
60
 
61
61
  @env.scope do
62
- @env.add :y, Type.str
63
- @env.add :x, Type.float
62
+ @env.add :y, CType.str
63
+ @env.add :x, CType.float
64
64
 
65
- expected = { :x => [Type.float], :y => [Type.str] }
65
+ expected = { :x => [CType.float], :y => [CType.str] }
66
66
  assert_equal expected, @env.all
67
67
  end
68
68
 
69
- expected = { :x => [Type.long] }
69
+ expected = { :x => [CType.long] }
70
70
  assert_equal expected, @env.all
71
71
  end
72
72
  end
73
-
73
+
74
74
  def test_depth
75
75
  assert_equal 1, @env.depth
76
76
 
@@ -86,28 +86,28 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
86
86
  end
87
87
 
88
88
  def test_get_val
89
- @env.add :var, Type.long
89
+ @env.add :var, CType.long
90
90
  @env.set_val :var, 42
91
91
 
92
92
  assert_equal 42, @env.get_val(:var)
93
93
  end
94
94
 
95
95
  def test_set_val
96
- @env.add :var, Type.long
96
+ @env.add :var, CType.long
97
97
  assert_equal 42, @env.set_val(:var, 42)
98
98
 
99
99
  assert_equal 42, @env.get_val(:var)
100
100
  end
101
101
 
102
102
  def test_set_val_static_array
103
- @env.add :var, Type.long
103
+ @env.add :var, CType.long
104
104
  assert_equal "[2]", @env.set_val(:var, "[2]")
105
105
 
106
106
  assert_equal "[2]", @env.get_val(:var)
107
107
  end
108
108
 
109
109
  def test_get_val_unset
110
- @env.add :var, Type.long
110
+ @env.add :var, CType.long
111
111
 
112
112
  assert_nil @env.get_val(:var)
113
113
  end
@@ -126,8 +126,8 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
126
126
  end
127
127
 
128
128
  def test_lookup
129
- @env.add :var, Type.long
130
- assert_equal Type.long, @env.lookup(:var)
129
+ @env.add :var, CType.long
130
+ assert_equal CType.long, @env.lookup(:var)
131
131
  end
132
132
 
133
133
  def test_lookup_raises
@@ -137,49 +137,49 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
137
137
  end
138
138
 
139
139
  def test_lookup_scope
140
- @env.add :var, Type.long
141
- assert_equal Type.long, @env.lookup(:var)
140
+ @env.add :var, CType.long
141
+ assert_equal CType.long, @env.lookup(:var)
142
142
 
143
143
  @env.scope do
144
- assert_equal Type.long, @env.lookup(:var)
144
+ assert_equal CType.long, @env.lookup(:var)
145
145
  end
146
146
  end
147
147
 
148
148
  def test_scope
149
- @env.add :var, Type.long
150
- assert_equal Type.long, @env.lookup(:var)
149
+ @env.add :var, CType.long
150
+ assert_equal CType.long, @env.lookup(:var)
151
151
 
152
152
  @env.scope do
153
- @env.add :var, Type.float
154
- assert_equal Type.float, @env.lookup(:var)
153
+ @env.add :var, CType.float
154
+ assert_equal CType.float, @env.lookup(:var)
155
155
  end
156
156
 
157
- assert_equal Type.long, @env.lookup(:var)
157
+ assert_equal CType.long, @env.lookup(:var)
158
158
  end
159
159
 
160
160
  def test_scope_raise
161
- @env.add :a, Type.float
161
+ @env.add :a, CType.float
162
162
 
163
163
  begin
164
164
  @env.scope do
165
- @env.add :a, Type.long
166
- @env.add :b, Type.long
165
+ @env.add :a, CType.long
166
+ @env.add :b, CType.long
167
167
  raise "woo"
168
168
  end
169
169
  rescue
170
170
  # should replicate baddies
171
171
  end
172
172
 
173
- expected = { :a => [Type.float] }
173
+ expected = { :a => [CType.float] }
174
174
  assert_equal expected, @env.all
175
175
  end
176
176
 
177
177
  def test_unextend
178
178
  @env.extend
179
179
 
180
- @env.add :var, Type.long
180
+ @env.add :var, CType.long
181
181
 
182
- assert_equal Type.long, @env.lookup(:var)
182
+ assert_equal CType.long, @env.lookup(:var)
183
183
 
184
184
  @env.unextend
185
185