forked from atduskgreg/rad
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_variable_processing.rb
238 lines (198 loc) · 6.11 KB
/
test_variable_processing.rb
1
2
3
4
5
6
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
123
124
125
126
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/local/bin/ruby -w
$TESTING = true
# need to tell it where we are
# lets review these
# neee to remove this constant from tests and pull it from rad
C_VAR_TYPES = "unsigned|int|long|double|str|char|byte|float|bool"
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/variable_processing"
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/rad/arduino_sketch"
require 'test/unit'
class TestVariableProcessing < Test::Unit::TestCase
def setup
@t = ArduinoSketch.new
end
# question for brian... do we need variable assignment with no value when
# we have "" and 0
def test_int_as_int
name = "foo_a"
value_string = 1
expected = "int __foo_a = 1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_string_as_int
name = "foo_b"
value_string = "1"
expected = "int __foo_b = 1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_float_as_float
name = "foo_c"
value_string = 0.10
expected = "float __foo_c = 0.1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_string_as_float
name = "foo_d"
value_string = "0.10"
expected = "float __foo_d = 0.1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_byte # would this to return hex
name = "foo_f"
value_string = 0x00
expected = "int __foo_f = 0;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_byte_with_string_input
name = "foo_g"
value_string = "0x00"
expected = "byte __foo_g = 0x00;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_string
name = "foo_h"
value_string = "arduino"
expected = "char* __foo_h = \"arduino\";"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_type
name = "foo_i"
value_string = "int"
expected = "int __foo_i;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_odd_name
name = "bacon_j"
value_string = "arduino"
expected = "char* __bacon_j = \"arduino\";"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_type_two
name = "foo_k"
value_string = "2, int"
expected = "int __foo_k = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_long
name = "foo_l"
value_string = "2, int"
expected = "int __foo_l = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_byte
name = "foo_m"
value_string = "2, byte"
expected = "byte __foo_m = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_unsigned_int
name = "foo_n"
value_string = "2, unsigned int"
expected = "unsigned int __foo_n = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_unsigned_long
name = "foo_o"
value_string = "2, unsigned long"
expected = "unsigned long __foo_o = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_short_int
name = "foo_q"
value_string = "2, short int"
expected = "short int __foo_q = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_int_with_unsigned_short_int
name = "foo_r"
value_string = "2, unsigned short int"
expected = "unsigned short int __foo_r = 2;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_float_with_type
name = "foo_s"
value_string = "2.0, float"
expected = "float __foo_s = 2.0;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_true
name = "foo_t"
value_string = true
expected = "bool __foo_t = 1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_false
name = "foo_v"
value_string = false
expected = "bool __foo_v = 0;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_negative_int_string
name = "foo_w"
value_string = "-1, int"
expected = "int __foo_w = -1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_negative_float_string
name = "foo_x"
value_string = "-0.1, float"
expected = "float __foo_x = -0.1;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_negative_larger_float_string
name = "foo_y"
value_string = "-1000.01, float"
expected = "float __foo_y = -1000.01;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_negative_long_string
name = "foo_z"
value_string = "-.0991, float"
expected = "float __foo_z = -0.0991;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_negative_float_string_two
name = "foo_aa"
value_string = "-.01, float"
expected = "float __foo_aa = -0.01;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_negative_interter_string
name = "foo_bb"
value_string = "-.01, float"
expected = "float __foo_bb = -0.01;"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
def test_dash_string
name = "foo_cc"
value_string = "-hmmm"
expected = "char* __foo_cc = \"-hmmm\";"
result = @t.pre_process_vars(name, value_string)
assert_equal(expected, result[0])
end
end