rex 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +50 -0
- data/lib/rex.rb +23 -0
- data/lib/rex/array.rb +13 -0
- data/lib/rex/kernel.rb +11 -0
- data/lib/rex/modules/boolean.rb +14 -0
- data/lib/rex/modules/caller_name.rb +15 -0
- data/lib/rex/modules/ordinal.rb +35 -0
- data/lib/rex/modules/propercase.rb +15 -0
- data/lib/rex/modules/roman.rb +41 -0
- data/lib/rex/modules/scrub.rb +66 -0
- data/lib/rex/modules/stacktrace.rb +31 -0
- data/lib/rex/modules/swap.rb +13 -0
- data/lib/rex/modules/to_proc.rb +13 -0
- data/lib/rex/modules/tuple.rb +14 -0
- data/lib/rex/modules/wrap.rb +15 -0
- data/lib/rex/numeric.rb +19 -0
- data/lib/rex/string.rb +21 -0
- data/lib/rex/symbol.rb +13 -0
- data/test/boolean.rb +64 -0
- data/test/caller_name.rb +26 -0
- data/test/ordinal.rb +609 -0
- data/test/propercase.rb +40 -0
- data/test/roman.rb +335 -0
- data/test/scrub.rb +27 -0
- data/test/stacktrace.rb +24 -0
- data/test/swap.rb +44 -0
- data/test/to_proc.rb +24 -0
- data/test/tuple.rb +26 -0
- data/test/wrap.rb +44 -0
- metadata +92 -0
data/test/propercase.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# propercase.rb
|
4
|
+
# String#propercase unit tests
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'pathname'
|
9
|
+
dir = Pathname.new(File.expand_path(__FILE__)).realpath
|
10
|
+
require File.join(File.dirname(dir.to_s), '../lib/rex')
|
11
|
+
|
12
|
+
class ProperCaseTests < Test::Unit::TestCase
|
13
|
+
def test_empty_string
|
14
|
+
expected = ''
|
15
|
+
actual = nil
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
actual = ''.propercase
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_not_nil(actual)
|
22
|
+
assert_instance_of(String, actual)
|
23
|
+
assert_equal(true, actual.empty?)
|
24
|
+
assert_equal(expected, actual)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_regular_string
|
28
|
+
expected = 'Ruby Extension Library'
|
29
|
+
actual = nil
|
30
|
+
|
31
|
+
assert_nothing_raised do
|
32
|
+
actual = 'rUby eXtension lIbrAry'.propercase
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_not_nil(actual)
|
36
|
+
assert_instance_of(String, actual)
|
37
|
+
assert_equal(false, actual.empty?)
|
38
|
+
assert_equal(expected, actual)
|
39
|
+
end
|
40
|
+
end
|
data/test/roman.rb
ADDED
@@ -0,0 +1,335 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# roman.rb
|
4
|
+
# Integer#to_roman and Integer#from_roman unit tests
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'pathname'
|
9
|
+
dir = Pathname.new(File.expand_path(__FILE__)).realpath
|
10
|
+
require File.join(File.dirname(dir.to_s), '../lib/rex')
|
11
|
+
|
12
|
+
class RomanToTests < Test::Unit::TestCase
|
13
|
+
def test_to_0
|
14
|
+
expected = 'I'
|
15
|
+
actual = nil
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
actual = 1.to_roman
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_not_nil(actual)
|
22
|
+
assert_instance_of(String, actual)
|
23
|
+
assert_equal(false, actual.empty?)
|
24
|
+
assert_equal(expected, actual)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_to_1
|
28
|
+
expected = 'V'
|
29
|
+
actual = nil
|
30
|
+
|
31
|
+
assert_nothing_raised do
|
32
|
+
actual = 5.to_roman
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_not_nil(actual)
|
36
|
+
assert_instance_of(String, actual)
|
37
|
+
assert_equal(false, actual.empty?)
|
38
|
+
assert_equal(expected, actual)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_to_2
|
42
|
+
expected = 'X'
|
43
|
+
actual = nil
|
44
|
+
|
45
|
+
assert_nothing_raised do
|
46
|
+
actual = 10.to_roman
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_not_nil(actual)
|
50
|
+
assert_instance_of(String, actual)
|
51
|
+
assert_equal(false, actual.empty?)
|
52
|
+
assert_equal(expected, actual)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_3
|
56
|
+
expected = 'XV'
|
57
|
+
actual = nil
|
58
|
+
|
59
|
+
assert_nothing_raised do
|
60
|
+
actual = 15.to_roman
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_not_nil(actual)
|
64
|
+
assert_instance_of(String, actual)
|
65
|
+
assert_equal(false, actual.empty?)
|
66
|
+
assert_equal(expected, actual)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_to_4
|
70
|
+
expected = 'L'
|
71
|
+
actual = nil
|
72
|
+
|
73
|
+
assert_nothing_raised do
|
74
|
+
actual = 50.to_roman
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_not_nil(actual)
|
78
|
+
assert_instance_of(String, actual)
|
79
|
+
assert_equal(false, actual.empty?)
|
80
|
+
assert_equal(expected, actual)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_to_5
|
84
|
+
expected = 'C'
|
85
|
+
actual = nil
|
86
|
+
|
87
|
+
assert_nothing_raised do
|
88
|
+
actual = 100.to_roman
|
89
|
+
end
|
90
|
+
|
91
|
+
assert_not_nil(actual)
|
92
|
+
assert_instance_of(String, actual)
|
93
|
+
assert_equal(false, actual.empty?)
|
94
|
+
assert_equal(expected, actual)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_to_6
|
98
|
+
expected = 'D'
|
99
|
+
actual = nil
|
100
|
+
|
101
|
+
assert_nothing_raised do
|
102
|
+
actual = 500.to_roman
|
103
|
+
end
|
104
|
+
|
105
|
+
assert_not_nil(actual)
|
106
|
+
assert_instance_of(String, actual)
|
107
|
+
assert_equal(false, actual.empty?)
|
108
|
+
assert_equal(expected, actual)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_to_7
|
112
|
+
expected = 'M'
|
113
|
+
actual = nil
|
114
|
+
|
115
|
+
assert_nothing_raised do
|
116
|
+
actual = 1000.to_roman
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_not_nil(actual)
|
120
|
+
assert_instance_of(String, actual)
|
121
|
+
assert_equal(false, actual.empty?)
|
122
|
+
assert_equal(expected, actual)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_to_8
|
126
|
+
expected = 'MDCCCLXXXVIII'
|
127
|
+
actual = nil
|
128
|
+
|
129
|
+
assert_nothing_raised do
|
130
|
+
actual = 1888.to_roman
|
131
|
+
end
|
132
|
+
|
133
|
+
assert_not_nil(actual)
|
134
|
+
assert_instance_of(String, actual)
|
135
|
+
assert_equal(false, actual.empty?)
|
136
|
+
assert_equal(expected, actual)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_to_9
|
140
|
+
expected = 'MCMXCIX'
|
141
|
+
actual = nil
|
142
|
+
|
143
|
+
assert_nothing_raised do
|
144
|
+
actual = 1999.to_roman
|
145
|
+
end
|
146
|
+
|
147
|
+
assert_not_nil(actual)
|
148
|
+
assert_instance_of(String, actual)
|
149
|
+
assert_equal(false, actual.empty?)
|
150
|
+
assert_equal(expected, actual)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_to_10
|
154
|
+
expected = 'MM'
|
155
|
+
actual = nil
|
156
|
+
|
157
|
+
assert_nothing_raised do
|
158
|
+
actual = 2000.to_roman
|
159
|
+
end
|
160
|
+
|
161
|
+
assert_not_nil(actual)
|
162
|
+
assert_instance_of(String, actual)
|
163
|
+
assert_equal(false, actual.empty?)
|
164
|
+
assert_equal(expected, actual)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class RomanFromTests < Test::Unit::TestCase
|
169
|
+
def test_from_0
|
170
|
+
expected = 1
|
171
|
+
actual = nil
|
172
|
+
|
173
|
+
assert_nothing_raised do
|
174
|
+
actual = Integer.from_roman('I')
|
175
|
+
end
|
176
|
+
|
177
|
+
assert_not_nil(actual)
|
178
|
+
assert_instance_of(Fixnum, actual)
|
179
|
+
assert_equal(expected, actual)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_from_1
|
183
|
+
expected = 5
|
184
|
+
actual = nil
|
185
|
+
|
186
|
+
assert_nothing_raised do
|
187
|
+
actual = Integer.from_roman('V')
|
188
|
+
end
|
189
|
+
|
190
|
+
assert_not_nil(actual)
|
191
|
+
assert_instance_of(Fixnum, actual)
|
192
|
+
assert_equal(expected, actual)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_from_2
|
196
|
+
expected = 10
|
197
|
+
actual = nil
|
198
|
+
|
199
|
+
assert_nothing_raised do
|
200
|
+
actual = Integer.from_roman('X')
|
201
|
+
end
|
202
|
+
|
203
|
+
assert_not_nil(actual)
|
204
|
+
assert_instance_of(Fixnum, actual)
|
205
|
+
assert_equal(expected, actual)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_from_3
|
209
|
+
expected = 15
|
210
|
+
actual = nil
|
211
|
+
|
212
|
+
assert_nothing_raised do
|
213
|
+
actual = Integer.from_roman('XV')
|
214
|
+
end
|
215
|
+
|
216
|
+
assert_not_nil(actual)
|
217
|
+
assert_instance_of(Fixnum, actual)
|
218
|
+
assert_equal(expected, actual)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_from_4
|
222
|
+
expected = 50
|
223
|
+
actual = nil
|
224
|
+
|
225
|
+
assert_nothing_raised do
|
226
|
+
actual = Integer.from_roman('L')
|
227
|
+
end
|
228
|
+
|
229
|
+
assert_not_nil(actual)
|
230
|
+
assert_instance_of(Fixnum, actual)
|
231
|
+
assert_equal(expected, actual)
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_from_5
|
235
|
+
expected = 100
|
236
|
+
actual = nil
|
237
|
+
|
238
|
+
assert_nothing_raised do
|
239
|
+
actual = Integer.from_roman('C')
|
240
|
+
end
|
241
|
+
|
242
|
+
assert_not_nil(actual)
|
243
|
+
assert_instance_of(Fixnum, actual)
|
244
|
+
assert_equal(expected, actual)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_from_6
|
248
|
+
expected = 500
|
249
|
+
actual = nil
|
250
|
+
|
251
|
+
assert_nothing_raised do
|
252
|
+
actual = Integer.from_roman('D')
|
253
|
+
end
|
254
|
+
|
255
|
+
assert_not_nil(actual)
|
256
|
+
assert_instance_of(Fixnum, actual)
|
257
|
+
assert_equal(expected, actual)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_from_7
|
261
|
+
expected = 1000
|
262
|
+
actual = nil
|
263
|
+
|
264
|
+
assert_nothing_raised do
|
265
|
+
actual = Integer.from_roman('M')
|
266
|
+
end
|
267
|
+
|
268
|
+
assert_not_nil(actual)
|
269
|
+
assert_instance_of(Fixnum, actual)
|
270
|
+
assert_equal(expected, actual)
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_from_8
|
274
|
+
expected = 1888
|
275
|
+
actual = nil
|
276
|
+
|
277
|
+
assert_nothing_raised do
|
278
|
+
actual = Integer.from_roman('MDCCCLXXXVIII')
|
279
|
+
end
|
280
|
+
|
281
|
+
assert_not_nil(actual)
|
282
|
+
assert_instance_of(Fixnum, actual)
|
283
|
+
assert_equal(expected, actual)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_from_9
|
287
|
+
expected = 1999
|
288
|
+
actual = nil
|
289
|
+
|
290
|
+
assert_nothing_raised do
|
291
|
+
actual = Integer.from_roman('MCMXCIX')
|
292
|
+
end
|
293
|
+
|
294
|
+
assert_not_nil(actual)
|
295
|
+
assert_instance_of(Fixnum, actual)
|
296
|
+
assert_equal(expected, actual)
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_from_10
|
300
|
+
expected = 2000
|
301
|
+
actual = nil
|
302
|
+
|
303
|
+
assert_nothing_raised do
|
304
|
+
actual = Integer.from_roman('MM')
|
305
|
+
end
|
306
|
+
|
307
|
+
assert_not_nil(actual)
|
308
|
+
assert_instance_of(Fixnum, actual)
|
309
|
+
assert_equal(expected, actual)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_from_11
|
313
|
+
for i in (1..10000)
|
314
|
+
expected = i
|
315
|
+
roman = nil
|
316
|
+
number = nil
|
317
|
+
|
318
|
+
assert_nothing_raised do
|
319
|
+
roman = i.to_roman
|
320
|
+
end
|
321
|
+
|
322
|
+
assert_not_nil(roman)
|
323
|
+
assert_instance_of(String, roman)
|
324
|
+
assert_equal(false, roman.empty?)
|
325
|
+
|
326
|
+
assert_nothing_raised do
|
327
|
+
number = Integer.from_roman(roman)
|
328
|
+
end
|
329
|
+
|
330
|
+
assert_not_nil(number)
|
331
|
+
assert_instance_of(Fixnum, number)
|
332
|
+
assert_equal(i, number)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
data/test/scrub.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# scrub.rb
|
4
|
+
# String#scrub! unit tests
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'pathname'
|
9
|
+
dir = Pathname.new(File.expand_path(__FILE__)).realpath
|
10
|
+
require File.join(File.dirname(dir.to_s), '../lib/rex')
|
11
|
+
|
12
|
+
class ScrubTests < Test::Unit::TestCase
|
13
|
+
def test_xss
|
14
|
+
expected = "alert('xss from yesmar');"
|
15
|
+
actual = nil
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
actual = "<script>alert('xss from yesmar');</script>"
|
19
|
+
actual.scrub!
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_not_nil(actual)
|
23
|
+
assert_instance_of(String, actual)
|
24
|
+
assert_equal(false, actual.empty?)
|
25
|
+
assert_equal(expected, actual)
|
26
|
+
end
|
27
|
+
end
|
data/test/stacktrace.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# stacktrace.rb
|
4
|
+
# Kernel#stacktrace unit tests
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'pathname'
|
9
|
+
dir = Pathname.new(File.expand_path(__FILE__)).realpath
|
10
|
+
require File.join(File.dirname(dir.to_s), '../lib/rex')
|
11
|
+
|
12
|
+
class StacktraceTests < Test::Unit::TestCase
|
13
|
+
def test_stacktrace
|
14
|
+
actual = nil
|
15
|
+
|
16
|
+
assert_nothing_raised do
|
17
|
+
actual = stacktrace
|
18
|
+
end
|
19
|
+
|
20
|
+
assert_not_nil(actual)
|
21
|
+
assert_instance_of(Array, actual)
|
22
|
+
assert_equal(false, actual.empty?)
|
23
|
+
end
|
24
|
+
end
|
data/test/swap.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# swap.rb
|
4
|
+
# Array#swap! unit tests
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'pathname'
|
9
|
+
dir = Pathname.new(File.expand_path(__FILE__)).realpath
|
10
|
+
require File.join(File.dirname(dir.to_s), '../lib/rex')
|
11
|
+
|
12
|
+
class SwapTests < Test::Unit::TestCase
|
13
|
+
def test_swap_nil
|
14
|
+
expected = [nil,nil]
|
15
|
+
actual = nil
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
actual = []
|
19
|
+
actual.swap!(0,1)
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_not_nil(actual)
|
23
|
+
assert_instance_of(Array, actual)
|
24
|
+
assert_equal(false, actual.empty?)
|
25
|
+
assert_equal(2, actual.size)
|
26
|
+
assert_equal(expected, actual)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_swap_321
|
30
|
+
expected = [3,2,1]
|
31
|
+
actual = nil
|
32
|
+
|
33
|
+
assert_nothing_raised do
|
34
|
+
actual = [1,2,3]
|
35
|
+
actual.swap!(0,2)
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_not_nil(actual)
|
39
|
+
assert_instance_of(Array, actual)
|
40
|
+
assert_equal(false, actual.empty?)
|
41
|
+
assert_equal(3, actual.size)
|
42
|
+
assert_equal(expected, actual)
|
43
|
+
end
|
44
|
+
end
|