fto 0.1.0
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.
- data/CONTRIBUTORS.txt +5 -0
- data/LICENCE.txt +202 -0
- data/README.txt +75 -0
- data/doc/classes/FormatText.html +120 -0
- data/doc/classes/FormatText/Context.html +240 -0
- data/doc/classes/FormatText/Context.src/M000001.html +26 -0
- data/doc/classes/FormatText/Context.src/M000004.html +26 -0
- data/doc/classes/FormatText/Context.src/M000007.html +26 -0
- data/doc/classes/FormatText/Context.src/M000008.html +26 -0
- data/doc/classes/FormatText/Context.src/M000009.html +26 -0
- data/doc/classes/FormatText/Effector.html +411 -0
- data/doc/classes/FormatText/Effector.src/M000004.html +38 -0
- data/doc/classes/FormatText/Effector.src/M000005.html +39 -0
- data/doc/classes/FormatText/Effector.src/M000007.html +38 -0
- data/doc/classes/FormatText/Effector.src/M000008.html +42 -0
- data/doc/classes/FormatText/Effector.src/M000009.html +43 -0
- data/doc/classes/FormatText/Effector.src/M000010.html +19 -0
- data/doc/classes/FormatText/Effector.src/M000011.html +18 -0
- data/doc/classes/FormatText/Effector.src/M000012.html +19 -0
- data/doc/classes/FormatText/Effector.src/M000013.html +18 -0
- data/doc/classes/FormatText/Effector.src/M000014.html +18 -0
- data/doc/classes/FormatText/FTO.html +305 -0
- data/doc/classes/FormatText/FTO.src/M000001.html +19 -0
- data/doc/classes/FormatText/FTO.src/M000002.html +34 -0
- data/doc/classes/FormatText/FTO.src/M000003.html +22 -0
- data/doc/classes/FormatText/FTO.src/M000004.html +19 -0
- data/doc/classes/FormatText/FTO.src/M000005.html +22 -0
- data/doc/classes/FormatText/FTO.src/M000006.html +20 -0
- data/doc/classes/FormatText/FTO.src/M000007.html +63 -0
- data/doc/classes/FormatText/FTO.src/M000008.html +63 -0
- data/doc/created.rid +1 -0
- data/doc/files/fto_rb.html +141 -0
- data/doc/files/lib/fto_rb.html +150 -0
- data/doc/fr_class_index.html +30 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +39 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/fto.rb +1349 -0
- data/test/test_fto_api.rb +143 -0
- data/test/test_fto_effectors.rb +440 -0
- data/test/test_helper.rb +3 -0
- metadata +115 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby-debug'
|
3
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
4
|
+
|
5
|
+
class Test_FTO_API < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include FormatText
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def setup
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_truth
|
15
|
+
assert true
|
16
|
+
end
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
def test_arglistOverride()
|
21
|
+
cValue = 'construction value'
|
22
|
+
oValue = 'override value'
|
23
|
+
f = FTO.new('!AS', cValue)
|
24
|
+
assert_equal(cValue, f.format)
|
25
|
+
assert_equal(oValue, f.format(oValue))
|
26
|
+
assert_equal(cValue, f.format)
|
27
|
+
end # def test_arglistOverride()
|
28
|
+
|
29
|
+
def test_findEffectors()
|
30
|
+
#
|
31
|
+
# Check for not finding anything
|
32
|
+
#
|
33
|
+
pattern = 'No such string'
|
34
|
+
assert(FTO::findEffectors(pattern).empty?)
|
35
|
+
assert(FTO::findEffectors(Regexp.new(pattern)).empty?)
|
36
|
+
|
37
|
+
#
|
38
|
+
# Check for finding exactly one match
|
39
|
+
#
|
40
|
+
pattern = '^TAB$'
|
41
|
+
assert(FTO::findEffectors(pattern).length == 1)
|
42
|
+
assert(FTO::findEffectors(Regexp.new(pattern)).length == 1)
|
43
|
+
|
44
|
+
#
|
45
|
+
# Make sure we're getting the right thing.
|
46
|
+
#
|
47
|
+
assert(FTO::findEffectors(pattern).first.class.name.match(/Effector/))
|
48
|
+
|
49
|
+
#
|
50
|
+
# Check for fiddling with case
|
51
|
+
#
|
52
|
+
pattern = '^tab$'
|
53
|
+
assert(FTO::findEffectors(pattern).empty?)
|
54
|
+
assert(FTO::findEffectors(Regexp.new(pattern, Regexp::IGNORECASE)).length == 1)
|
55
|
+
|
56
|
+
#
|
57
|
+
# Check for finding a few ('String AS', 'String AN', 'String AD',
|
58
|
+
# and 'String AF').
|
59
|
+
# Anchored pattern.
|
60
|
+
#
|
61
|
+
pattern = '^String'
|
62
|
+
assert(FTO::findEffectors(pattern).length == 4)
|
63
|
+
assert(FTO::findEffectors(Regexp.new(pattern)).length == 4)
|
64
|
+
|
65
|
+
#
|
66
|
+
# Check for finding a few ('Word: hex' and 'Quadword: hex').
|
67
|
+
# Unanchored pattern.
|
68
|
+
#
|
69
|
+
pattern = 'rd: he'
|
70
|
+
assert(FTO::findEffectors(pattern).length == 2)
|
71
|
+
assert(FTO::findEffectors(Regexp.new(pattern)).length == 2)
|
72
|
+
end # def test_findEffectors()
|
73
|
+
|
74
|
+
def test_EnableDisableEffector()
|
75
|
+
e = FTO.findEffectors('^String AS$').first
|
76
|
+
#
|
77
|
+
# Check the switches and sensors around enablement. (Whether they
|
78
|
+
# actually do their jobs is next.)
|
79
|
+
#
|
80
|
+
|
81
|
+
#
|
82
|
+
# Instance methods checking an effector enabled by instance method.
|
83
|
+
# (Actually, by assumed default.)
|
84
|
+
#
|
85
|
+
assert(e.enabled?)
|
86
|
+
assert(! e.disabled?)
|
87
|
+
|
88
|
+
#
|
89
|
+
# Instance methods checking state altered by class method.
|
90
|
+
#
|
91
|
+
FTO.disableEffector(e.id)
|
92
|
+
assert(! e.enabled?)
|
93
|
+
assert(e.disabled?)
|
94
|
+
|
95
|
+
FTO.enableEffector(e.id)
|
96
|
+
assert(e.enabled?)
|
97
|
+
assert(! e.disabled?)
|
98
|
+
|
99
|
+
#
|
100
|
+
# *Now* instance methods checking on effect of other instance methods.
|
101
|
+
#
|
102
|
+
e.disable
|
103
|
+
assert(! e.enabled?)
|
104
|
+
assert(e.disabled?)
|
105
|
+
|
106
|
+
e.enable
|
107
|
+
assert(e.enabled?)
|
108
|
+
assert(! e.disabled?)
|
109
|
+
|
110
|
+
#
|
111
|
+
# Now time to see if this enable/disable stuff is really doing what it
|
112
|
+
# ought.
|
113
|
+
#
|
114
|
+
pattern = '!AS'
|
115
|
+
f = FTO.new(pattern, 'succeeded')
|
116
|
+
#
|
117
|
+
# Test reality of disablement using the Effector.disable method.
|
118
|
+
#
|
119
|
+
e.disable
|
120
|
+
assert_equal(pattern, f.format('succeeded'))
|
121
|
+
#
|
122
|
+
# Test reality of enablement using the FTO class method.
|
123
|
+
#
|
124
|
+
FTO.enableEffector(e.id)
|
125
|
+
assert_equal('succeeded', f.format('succeeded'))
|
126
|
+
|
127
|
+
#
|
128
|
+
# And contrariwise. Class method first.
|
129
|
+
#
|
130
|
+
FTO.disableEffector(e.id)
|
131
|
+
assert_equal(pattern, f.format('succeeded'))
|
132
|
+
#
|
133
|
+
# Then instance method.
|
134
|
+
#
|
135
|
+
e.enable
|
136
|
+
assert_equal('succeeded', f.format('succeeded'))
|
137
|
+
#
|
138
|
+
# Make sure we leave it on!
|
139
|
+
#
|
140
|
+
FTO.enableEffector(e.id)
|
141
|
+
end # def test_EnableDisableEffector()
|
142
|
+
|
143
|
+
end # class Test_FTO
|
@@ -0,0 +1,440 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class Test_FTO < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include FormatText
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def setup
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_truth
|
13
|
+
assert true
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_numeric_singleton(eff, val, expected)
|
17
|
+
assert_equal(expected, FTO.new(eff, val).format,
|
18
|
+
'Testing ' + eff + '/' + val)
|
19
|
+
end
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
def test_insertions()
|
24
|
+
assert_equal(FTO.new('!_').format, "\011", 'Testing !_')
|
25
|
+
assert_equal(FTO.new('!,').format, "\012", 'Testing !,')
|
26
|
+
assert_equal(FTO.new('!^').format, "\014", 'Testing !^')
|
27
|
+
assert_equal(FTO.new('!=').format, "\015", 'Testing !=')
|
28
|
+
assert_equal(FTO.new('!/').format, "\015\012", 'Testing !/')
|
29
|
+
assert_equal(FTO.new('!!').format, '!', 'Testing !!')
|
30
|
+
assert_equal(FTO.new('!5**').format, '*****', 'Testing !n*c')
|
31
|
+
end # def test_insertions()
|
32
|
+
|
33
|
+
def test_fixedWidth()
|
34
|
+
test_data = '1234567890'
|
35
|
+
assert_equal(test_data,
|
36
|
+
FTO.new('!10<!AS!>', test_data).format,
|
37
|
+
'Testing :!10<!AS!>:10');
|
38
|
+
assert_equal(' ' + test_data,
|
39
|
+
FTO.new('!15<!AS!>', test_data).format,
|
40
|
+
'Testing :!15<!AS!>:10');
|
41
|
+
assert_equal('67890',
|
42
|
+
FTO.new('!5<!AS!>', test_data).format,
|
43
|
+
'Testing :!5<!AS!>:10');
|
44
|
+
end # def test_fixedWidth()
|
45
|
+
|
46
|
+
#
|
47
|
+
# Test that the recursion does by the Fixed Window effector function
|
48
|
+
# doesn't b0rk the argument list.
|
49
|
+
#
|
50
|
+
def test_fixedWidthArguments()
|
51
|
+
test_data = 'abc'
|
52
|
+
assert_equal('abc-abc-abc',
|
53
|
+
FTO.new('!AS-!-!3<!AS!>-!-!AS', test_data).format,
|
54
|
+
'Testing :!AS-!-!3<!AS!>-!-!AS:');
|
55
|
+
assert_equal('abc-abc-abc',
|
56
|
+
FTO.new('!AS-!3<!-!AS!>-!-!AS', test_data).format,
|
57
|
+
'Testing :!AS-!3<!-!AS!>-!-!AS:');
|
58
|
+
assert_equal('1-abc-3',
|
59
|
+
FTO.new('!UL-!3<!AS!>-!UL', 1, test_data, 3).format,
|
60
|
+
'Testing :!AS-!3<!-!AS!>-!-!AS:');
|
61
|
+
end # def test_fixedWidthArguments
|
62
|
+
|
63
|
+
def test_unsized()
|
64
|
+
expectations = {
|
65
|
+
'-1' => '255',
|
66
|
+
'0' => '0',
|
67
|
+
'1' => '1',
|
68
|
+
'0x100' => '0',
|
69
|
+
'0xFFF' => '255',
|
70
|
+
'0xFFFF' => '255',
|
71
|
+
'0xFFFFF' => '255',
|
72
|
+
'0xFFFFFF' => '255',
|
73
|
+
'0xFFFFFFFF' => '255',
|
74
|
+
}
|
75
|
+
expectations.each { |val, exp| test_numeric_singleton('!UB', val, exp) }
|
76
|
+
expectations = {
|
77
|
+
'-1' => '-1',
|
78
|
+
'0' => '0',
|
79
|
+
'1' => '1',
|
80
|
+
'0x100' => '0',
|
81
|
+
'0xFFF' => '-1',
|
82
|
+
'0xFFFF' => '-1',
|
83
|
+
'0xFFFFF' => '-1',
|
84
|
+
'0xFFFFFF' => '-1',
|
85
|
+
'0xFFFFFFFF' => '-1',
|
86
|
+
}
|
87
|
+
expectations.each { |val, exp| test_numeric_singleton('!SB', val, exp) }
|
88
|
+
expectations = {
|
89
|
+
'-1' => '255',
|
90
|
+
'0' => '0',
|
91
|
+
'1' => '1',
|
92
|
+
'0x100' => '0',
|
93
|
+
'0xFFF' => '255',
|
94
|
+
'0xFFFF' => '255',
|
95
|
+
'0xFFFFF' => '255',
|
96
|
+
'0xFFFFFF' => '255',
|
97
|
+
'0xFFFFFFFF' => '255',
|
98
|
+
}
|
99
|
+
expectations.each { |val, exp| test_numeric_singleton('!ZB', val, exp) }
|
100
|
+
expectations = {
|
101
|
+
'-1' => '377',
|
102
|
+
'0' => '000',
|
103
|
+
'1' => '001',
|
104
|
+
'0x100' => '000',
|
105
|
+
'0xFFF' => '377',
|
106
|
+
'0xFFFF' => '377',
|
107
|
+
'0xFFFFF' => '377',
|
108
|
+
'0xFFFFFF' => '377',
|
109
|
+
'0xFFFFFFFF' => '377',
|
110
|
+
}
|
111
|
+
expectations.each { |val, exp| test_numeric_singleton('!OB', val, exp) }
|
112
|
+
expectations = {
|
113
|
+
'-1' => 'FF',
|
114
|
+
'0' => '00',
|
115
|
+
'1' => '01',
|
116
|
+
'0x100' => '00',
|
117
|
+
'0xFFF' => 'FF',
|
118
|
+
'0xFFFF' => 'FF',
|
119
|
+
'0xFFFFF' => 'FF',
|
120
|
+
'0xFFFFFF' => 'FF',
|
121
|
+
'0xFFFFFFFF' => 'FF',
|
122
|
+
}
|
123
|
+
expectations.each { |val, exp| test_numeric_singleton('!XB', val, exp) }
|
124
|
+
#
|
125
|
+
# Now the 16-bit word effectors
|
126
|
+
#
|
127
|
+
expectations = {
|
128
|
+
'-1' => '65535',
|
129
|
+
'0' => '0',
|
130
|
+
'1' => '1',
|
131
|
+
'0x100' => '256',
|
132
|
+
'0xFFF' => '4095',
|
133
|
+
'0xFFFF' => '65535',
|
134
|
+
'0xFFFFF' => '65535',
|
135
|
+
'0xFFFFFF' => '65535',
|
136
|
+
'0xFFFFFFFF' => '65535',
|
137
|
+
}
|
138
|
+
expectations.each { |val, exp| test_numeric_singleton('!UW', val, exp) }
|
139
|
+
expectations = {
|
140
|
+
'-1' => '-1',
|
141
|
+
'0' => '0',
|
142
|
+
'1' => '1',
|
143
|
+
'0x100' => '256',
|
144
|
+
'0xFFF' => '4095',
|
145
|
+
'0xFFFF' => '-1',
|
146
|
+
'0xFFFFF' => '-1',
|
147
|
+
'0xFFFFFF' => '-1',
|
148
|
+
'0xFFFFFFFF' => '-1',
|
149
|
+
}
|
150
|
+
expectations.each { |val, exp| test_numeric_singleton('!SW', val, exp) }
|
151
|
+
expectations = {
|
152
|
+
'-1' => '65535',
|
153
|
+
'0' => '0',
|
154
|
+
'1' => '1',
|
155
|
+
'0x100' => '256',
|
156
|
+
'0xFFF' => '4095',
|
157
|
+
'0xFFFF' => '65535',
|
158
|
+
'0xFFFFF' => '65535',
|
159
|
+
'0xFFFFFF' => '65535',
|
160
|
+
'0xFFFFFFFF' => '65535',
|
161
|
+
}
|
162
|
+
expectations.each { |val, exp| test_numeric_singleton('!ZW', val, exp) }
|
163
|
+
expectations = {
|
164
|
+
'-1' => '177777',
|
165
|
+
'0' => '000000',
|
166
|
+
'1' => '000001',
|
167
|
+
'0x100' => '000400',
|
168
|
+
'0xFFF' => '007777',
|
169
|
+
'0xFFFF' => '177777',
|
170
|
+
'0xFFFFF' => '177777',
|
171
|
+
'0xFFFFFF' => '177777',
|
172
|
+
'0xFFFFFFFF' => '177777',
|
173
|
+
}
|
174
|
+
expectations.each { |val, exp| test_numeric_singleton('!OW', val, exp) }
|
175
|
+
expectations = {
|
176
|
+
'-1' => 'FFFF',
|
177
|
+
'0' => '0000',
|
178
|
+
'1' => '0001',
|
179
|
+
'0x100' => '0100',
|
180
|
+
'0xFFF' => '0FFF',
|
181
|
+
'0xFFFF' => 'FFFF',
|
182
|
+
'0xFFFFF' => 'FFFF',
|
183
|
+
'0xFFFFFF' => 'FFFF',
|
184
|
+
'0xFFFFFFFF' => 'FFFF',
|
185
|
+
}
|
186
|
+
expectations.each { |val, exp| test_numeric_singleton('!XW', val, exp) }
|
187
|
+
#
|
188
|
+
# Now the 32-bit word effectors
|
189
|
+
#
|
190
|
+
expectations = {
|
191
|
+
'-1' => '4294967295',
|
192
|
+
'0' => '0',
|
193
|
+
'1' => '1',
|
194
|
+
'0x100' => '256',
|
195
|
+
'0xFFF' => '4095',
|
196
|
+
'0xFFFF' => '65535',
|
197
|
+
'0xFFFFF' => '1048575',
|
198
|
+
'0xFFFFFF' => '16777215',
|
199
|
+
'0xFFFFFFFF' => '4294967295',
|
200
|
+
}
|
201
|
+
expectations.each { |val, exp| test_numeric_singleton('!UL', val, exp) }
|
202
|
+
expectations = {
|
203
|
+
'-1' => '-1',
|
204
|
+
'0' => '0',
|
205
|
+
'1' => '1',
|
206
|
+
'0x100' => '256',
|
207
|
+
'0xFFF' => '4095',
|
208
|
+
'0xFFFF' => '65535',
|
209
|
+
'0xFFFFF' => '1048575',
|
210
|
+
'0xFFFFFF' => '16777215',
|
211
|
+
'0xFFFFFFFF' => '-1',
|
212
|
+
}
|
213
|
+
expectations.each { |val, exp| test_numeric_singleton('!SL', val, exp) }
|
214
|
+
expectations = {
|
215
|
+
'-1' => '65535',
|
216
|
+
'0' => '0',
|
217
|
+
'1' => '1',
|
218
|
+
'0x100' => '256',
|
219
|
+
'0xFFF' => '4095',
|
220
|
+
'0xFFFF' => '65535',
|
221
|
+
'0xFFFFF' => '65535',
|
222
|
+
'0xFFFFFF' => '65535',
|
223
|
+
'0xFFFFFFFF' => '65535',
|
224
|
+
}
|
225
|
+
# expectations.each { |val, exp| test_numeric_singleton('!ZL', val, exp) }
|
226
|
+
expectations = {
|
227
|
+
'-1' => '37777777777',
|
228
|
+
'0' => '00000000000',
|
229
|
+
'1' => '00000000001',
|
230
|
+
'0x100' => '00000000400',
|
231
|
+
'0xFFF' => '00000007777',
|
232
|
+
'0xFFFF' => '00000177777',
|
233
|
+
'0xFFFFF' => '00003777777',
|
234
|
+
'0xFFFFFF' => '00077777777',
|
235
|
+
'0xFFFFFFFF' => '37777777777',
|
236
|
+
}
|
237
|
+
expectations.each { |val, exp| test_numeric_singleton('!OL', val, exp) }
|
238
|
+
expectations = {
|
239
|
+
'-1' => 'FFFFFFFF',
|
240
|
+
'0' => '00000000',
|
241
|
+
'1' => '00000001',
|
242
|
+
'0x100' => '00000100',
|
243
|
+
'0xFFF' => '00000FFF',
|
244
|
+
'0xFFFF' => '0000FFFF',
|
245
|
+
'0xFFFFF' => '000FFFFF',
|
246
|
+
'0xFFFFFF' => '00FFFFFF',
|
247
|
+
'0xFFFFFFFF' => 'FFFFFFFF',
|
248
|
+
}
|
249
|
+
expectations.each { |val, exp| test_numeric_singleton('!XL', val, exp) }
|
250
|
+
|
251
|
+
#
|
252
|
+
# Now the 64-bit word effectors
|
253
|
+
#
|
254
|
+
expectations = {
|
255
|
+
'-1' => '18446744073709551615',
|
256
|
+
'0' => '0',
|
257
|
+
'1' => '1',
|
258
|
+
'0x100' => '256',
|
259
|
+
'0xFFF' => '4095',
|
260
|
+
'0xFFFF' => '65535',
|
261
|
+
'0xFFFFF' => '1048575',
|
262
|
+
'0xFFFFFF' => '16777215',
|
263
|
+
'0xFFFFFFF' => '268435455',
|
264
|
+
'0xFFFFFFFF' => '4294967295',
|
265
|
+
'0xFFFFFFFFF' => '68719476735',
|
266
|
+
'0xFFFFFFFFFF' => '1099511627775',
|
267
|
+
'0xFFFFFFFFFFF' => '17592186044415',
|
268
|
+
'0xFFFFFFFFFFFF' => '281474976710655',
|
269
|
+
'0xFFFFFFFFFFFFF' => '4503599627370495',
|
270
|
+
'0xFFFFFFFFFFFFFF' => '72057594037927935',
|
271
|
+
'0xFFFFFFFFFFFFFFF' => '1152921504606846975',
|
272
|
+
'0xFFFFFFFFFFFFFFFF' => '18446744073709551615',
|
273
|
+
}
|
274
|
+
expectations.each { |val, exp| test_numeric_singleton('!UQ', val, exp) }
|
275
|
+
|
276
|
+
expectations = {
|
277
|
+
'-1' => '-1',
|
278
|
+
'0' => '0',
|
279
|
+
'1' => '1',
|
280
|
+
'0x100' => '256',
|
281
|
+
'0xFFF' => '4095',
|
282
|
+
'0xFFFF' => '65535',
|
283
|
+
'0xFFFFF' => '1048575',
|
284
|
+
'0xFFFFFF' => '16777215',
|
285
|
+
'0xFFFFFFF' => '268435455',
|
286
|
+
'0xFFFFFFFF' => '4294967295',
|
287
|
+
'0xFFFFFFFFF' => '68719476735',
|
288
|
+
'0xFFFFFFFFFF' => '1099511627775',
|
289
|
+
'0xFFFFFFFFFFF' => '17592186044415',
|
290
|
+
'0xFFFFFFFFFFFF' => '281474976710655',
|
291
|
+
'0xFFFFFFFFFFFFF' => '4503599627370495',
|
292
|
+
'0xFFFFFFFFFFFFFF' => '72057594037927935',
|
293
|
+
'0xFFFFFFFFFFFFFFF' => '1152921504606846975',
|
294
|
+
'0xFFFFFFFFFFFFFFFF' => '-1',
|
295
|
+
}
|
296
|
+
expectations.each { |val, exp| test_numeric_singleton('!SQ', val, exp) }
|
297
|
+
expectations = {
|
298
|
+
'-1' => '18446744073709551615',
|
299
|
+
'0' => '0',
|
300
|
+
'1' => '1',
|
301
|
+
'0x100' => '256',
|
302
|
+
'0xFFF' => '4095',
|
303
|
+
'0xFFFF' => '65535',
|
304
|
+
'0xFFFFF' => '1048575',
|
305
|
+
'0xFFFFFF' => '16777215',
|
306
|
+
'0xFFFFFFF' => '268435455',
|
307
|
+
'0xFFFFFFFF' => '4294967295',
|
308
|
+
'0xFFFFFFFFF' => '68719476735',
|
309
|
+
'0xFFFFFFFFFF' => '1099511627775',
|
310
|
+
'0xFFFFFFFFFFF' => '17592186044415',
|
311
|
+
'0xFFFFFFFFFFFF' => '281474976710655',
|
312
|
+
'0xFFFFFFFFFFFFF' => '4503599627370495',
|
313
|
+
'0xFFFFFFFFFFFFFF' => '72057594037927935',
|
314
|
+
'0xFFFFFFFFFFFFFFF' => '1152921504606846975',
|
315
|
+
'0xFFFFFFFFFFFFFFFF' => '18446744073709551615',
|
316
|
+
}
|
317
|
+
expectations.each { |val, exp| test_numeric_singleton('!ZQ', val, exp) }
|
318
|
+
expectations = {
|
319
|
+
'-1' => '1777777777777777777777',
|
320
|
+
'0' => '0000000000000000000000',
|
321
|
+
'1' => '0000000000000000000001',
|
322
|
+
'0x100' => '0000000000000000000400',
|
323
|
+
'0xFFF' => '0000000000000000007777',
|
324
|
+
'0xFFFF' => '0000000000000000177777',
|
325
|
+
'0xFFFFF' => '0000000000000003777777',
|
326
|
+
'0xFFFFFF' => '0000000000000077777777',
|
327
|
+
'0xFFFFFFF' => '0000000000001777777777',
|
328
|
+
'0xFFFFFFFF' => '0000000000037777777777',
|
329
|
+
'0xFFFFFFFFF' => '0000000000777777777777',
|
330
|
+
'0xFFFFFFFFFF' => '0000000017777777777777',
|
331
|
+
'0xFFFFFFFFFFF' => '0000000377777777777777',
|
332
|
+
'0xFFFFFFFFFFFF' => '0000007777777777777777',
|
333
|
+
'0xFFFFFFFFFFFFF' => '0000177777777777777777',
|
334
|
+
'0xFFFFFFFFFFFFFF' => '0003777777777777777777',
|
335
|
+
'0xFFFFFFFFFFFFFFF' => '0077777777777777777777',
|
336
|
+
'0xFFFFFFFFFFFFFFFF' => '1777777777777777777777',
|
337
|
+
}
|
338
|
+
expectations.each { |val, exp| test_numeric_singleton('!OQ', val, exp) }
|
339
|
+
expectations = {
|
340
|
+
'-1' => 'FFFFFFFFFFFFFFFF',
|
341
|
+
'0' => '0000000000000000',
|
342
|
+
'1' => '0000000000000001',
|
343
|
+
'0x100' => '0000000000000100',
|
344
|
+
'0xFFF' => '0000000000000FFF',
|
345
|
+
'0xFFFF' => '000000000000FFFF',
|
346
|
+
'0xFFFFF' => '00000000000FFFFF',
|
347
|
+
'0xFFFFFF' => '0000000000FFFFFF',
|
348
|
+
'0xFFFFFFF' => '000000000FFFFFFF',
|
349
|
+
'0xFFFFFFFF' => '00000000FFFFFFFF',
|
350
|
+
'0xFFFFFFFFF' => '0000000FFFFFFFFF',
|
351
|
+
'0xFFFFFFFFFF' => '000000FFFFFFFFFF',
|
352
|
+
'0xFFFFFFFFFFF' => '00000FFFFFFFFFFF',
|
353
|
+
'0xFFFFFFFFFFFF' => '0000FFFFFFFFFFFF',
|
354
|
+
'0xFFFFFFFFFFFFF' => '000FFFFFFFFFFFFF',
|
355
|
+
'0xFFFFFFFFFFFFFF' => '00FFFFFFFFFFFFFF',
|
356
|
+
'0xFFFFFFFFFFFFFFF' => '0FFFFFFFFFFFFFFF',
|
357
|
+
'0xFFFFFFFFFFFFFFFF' => 'FFFFFFFFFFFFFFFF',
|
358
|
+
}
|
359
|
+
expectations.each { |val, exp| test_numeric_singleton('!XQ', val, exp) }
|
360
|
+
end # def test_unsized()
|
361
|
+
|
362
|
+
def test_strings()
|
363
|
+
testData = "A\001b\002C\003d\004E\005f\006G" +
|
364
|
+
"\007h\010I\011j\012K\013l\014M\015n"
|
365
|
+
dataLen = testData.length
|
366
|
+
|
367
|
+
assert_equal(':' + testData + ':',
|
368
|
+
FTO.new(':!AS:', testData).format,
|
369
|
+
"Testing :!AS:[0,#{dataLen}]")
|
370
|
+
assert_equal(':' + testData[0,5] + ':',
|
371
|
+
FTO.new(':!5AS:', testData).format,
|
372
|
+
"Testing :!5AS:[0,#{dataLen}]")
|
373
|
+
assert_equal(':' + testData[0,5] + (' ' * 5) + ':',
|
374
|
+
FTO.new(':!10AS:', testData[0,5]).format,
|
375
|
+
"Testing :!10AS:[0,5]")
|
376
|
+
assert_equal(':' + testData[0,5] + ':',
|
377
|
+
FTO.new(':!5AS:', testData[0,5]).format,
|
378
|
+
"Testing :!5AS:[0,5]")
|
379
|
+
|
380
|
+
assert_equal(':A.b.C.d.E.f.G.h.I.j.K.l.M.n:',
|
381
|
+
FTO.new(':!AN:', testData).format,
|
382
|
+
"Testing :!AN:[0,#{dataLen}]")
|
383
|
+
assert_equal(':A.b.C:',
|
384
|
+
FTO.new(':!5AN:', testData).format,
|
385
|
+
"Testing :!5AN:[0,#{dataLen}]")
|
386
|
+
assert_equal(':A.b.C :',
|
387
|
+
FTO.new(':!10AN:', testData[0,5]).format,
|
388
|
+
"Testing :!10AN:[0,5]")
|
389
|
+
assert_equal(':A.b.C:',
|
390
|
+
FTO.new(':!5AN:', testData[0,5]).format,
|
391
|
+
"Testing :!5AN:[0,5]")
|
392
|
+
|
393
|
+
assert_equal(':A.b.C.d.E.:',
|
394
|
+
FTO.new(':!AF:', 10, testData).format,
|
395
|
+
"Testing :!AF:10,[0,#{dataLen}]")
|
396
|
+
assert_equal(':A.b.C:',
|
397
|
+
FTO.new(':!5AF:', 10, testData).format,
|
398
|
+
"Testing :!5AF:10,[0,#{dataLen}]")
|
399
|
+
assert_equal(':A.b.C.....:',
|
400
|
+
FTO.new(':!10AF:', 10, testData[0,5]).format,
|
401
|
+
"Testing :!10AF:10,[0,5]")
|
402
|
+
assert_equal(':A.b.C.....:',
|
403
|
+
FTO.new(':!AF:', 10, testData[0,5]).format,
|
404
|
+
"Testing :!AF:10,[0,5]")
|
405
|
+
|
406
|
+
assert_equal(':' + testData[0,10] + ':',
|
407
|
+
FTO.new(':!AD:', 10, testData).format,
|
408
|
+
"Testing :!AD:10,[0,#{dataLen}]")
|
409
|
+
assert_equal(':' + testData[0,5] + ':',
|
410
|
+
FTO.new(':!5AD:', 10, testData).format,
|
411
|
+
"Testing :!5AD:10,[0,#{dataLen}]")
|
412
|
+
assert_equal(':' + testData[0,5] + ("\000" * 5) + ':',
|
413
|
+
FTO.new(':!10AD:', 10, testData[0,5]).format,
|
414
|
+
"Testing :!10AD:10,[0,5]")
|
415
|
+
assert_equal(':' + testData[0,5] + ("\000" * 5) + ':',
|
416
|
+
FTO.new(':!AD:', 10, testData[0,5]).format,
|
417
|
+
"Testing :!AD:10,[0,5]")
|
418
|
+
end # def test_strings()
|
419
|
+
|
420
|
+
def test_plurals()
|
421
|
+
assert_equal(FTO.new('I have !SB boat!%S', -1).format, 'I have -1 boats')
|
422
|
+
assert_equal(FTO.new('I HAVE !SB BOAT!%S', -1).format, 'I HAVE -1 BOATS')
|
423
|
+
assert_equal(FTO.new('I have !SB boat!%S', 0).format, 'I have 0 boats')
|
424
|
+
assert_equal(FTO.new('I HAVE !SB BOAT!%S', 0).format, 'I HAVE 0 BOATS')
|
425
|
+
assert_equal(FTO.new('I have !SB boat!%S', 1).format, 'I have 1 boat')
|
426
|
+
assert_equal(FTO.new('I HAVE !SB BOAT!%S', 1).format, 'I HAVE 1 BOAT')
|
427
|
+
assert_equal(FTO.new('I have !SB boat!%S', 2).format, 'I have 2 boats')
|
428
|
+
assert_equal(FTO.new('I HAVE !SB BOAT!%S', 2).format, 'I HAVE 2 BOATS')
|
429
|
+
|
430
|
+
assert_equal(FTO.new('!SB boat!%S !%is cool', -1).format, '-1 boats are cool')
|
431
|
+
assert_equal(FTO.new('!SB BOAT!%S !%IS COOL', -1).format, '-1 BOATS ARE COOL')
|
432
|
+
assert_equal(FTO.new('!SB boat!%S !%is cool', 0).format, '0 boats are cool')
|
433
|
+
assert_equal(FTO.new('!SB BOAT!%S !%IS COOL', 0).format, '0 BOATS ARE COOL')
|
434
|
+
assert_equal(FTO.new('!SB boat!%S !%is cool', 1).format, '1 boat is cool')
|
435
|
+
assert_equal(FTO.new('!SB BOAT!%S !%IS COOL', 1).format, '1 BOAT IS COOL')
|
436
|
+
assert_equal(FTO.new('!SB boat!%S !%is cool', 2).format, '2 boats are cool')
|
437
|
+
assert_equal(FTO.new('!SB BOAT!%S !%IS COOL', 2).format, '2 BOATS ARE COOL')
|
438
|
+
end # def test_plurals()
|
439
|
+
|
440
|
+
end # class Test_FTO
|