2 # Copyright (C) 2001-2008, Parrot Foundation.
7 t/library/string_utils.t
11 Tests for String/Utils.pbc
15 % prove t/library/string_utils.t
19 .const string TESTS = '29'
22 load_bytecode 'Test/Builder.pbc'
24 .local pmc test # the test harness object.
25 test = new [ 'Test'; 'Builder' ]
27 set_global '$test', test
31 load_bytecode 'String/Utils.pbc'
32 test.'ok'(1, 'loaded String/Utils.pbc')
34 $P0 = get_hll_global ['String';'Utils'], 'chomp'
36 test.'ok'($I0, 'loaded chomp')
38 $P0 = get_hll_global ['String';'Utils'], 'convert_string_to_int'
40 test.'ok'($I0, 'loaded convert_string_to_int')
42 test_radix('' , 'x', 0, 0 , 0, 'null string')
43 test_radix('nothing', 'x', 0, 0 , 0, 'no leading digits')
46 test_radix('41' , 'x', 0, 65 , 2, 'x41')
47 test_radix('42G' , 'x', 0, 66 , 2, 'x42G')
48 test_radix('0a' , 'x', 0, 10 , 2, 'x0a')
49 test_radix('000a' , 'x', 0, 10 , 4, 'x000a')
50 test_radix('abcd' , 'x', 0, 0xabcd, 4, 'xabcd')
51 test_radix('ab0aX' , 'x', 2, 10 , 2, 'pos offset')
52 test_radix('0A' , 'x', 0, 10 , 2, 'x0A')
53 test_radix('000A' , 'x', 0, 10 , 4, 'x000A')
54 test_radix('ABCD' , 'x', 0, 0xabcd, 4, 'xABCD')
55 test_radix('AB0AX' , 'x', 2, 10 , 2, 'pos offset')
58 test_radix('41' , 'o', 0, 33 , 2, 'o41')
59 test_radix('42G' , 'o', 0, 34 , 2, 'o42G')
60 test_radix('12' , 'o', 0, 10 , 2, 'o12')
61 test_radix('0012' , 'o', 0, 10 , 4, 'o0012')
62 test_radix('1238' , 'o', 0, 83 , 3, 'o1238')
63 test_radix('1212X' , 'o', 2, 10 , 2, 'pos offset')
65 test_radix_digits('41' , 'x', 0, 'A' , 2, '\x41')
66 test_radix_digits('41XYZ' , 'x', 0, 'A' , 2, '\x41')
67 test_radix_digits('[41,42]' , 'x', 0, 'AB', 7, '\x[41,42]')
68 test_radix_digits('[41,42]XYZ', 'x', 0, 'AB', 7, '\x[41,42]')
69 test_radix_digits('[41,42]' , 'x', 1, 'A' , 2, '\x41')
70 test_radix_digits('[41,42]' , 'x', 4, 'B', 2, '\x42')
71 test_radix_digits('2000' , 'x', 0, unicode:"\u2000", 4, '\x2000')
72 test_radix_digits('1680' , 'x', 0, unicode:"\u1680", 4, '\x1680')
82 .param string description
83 .param string todo :named('todo') :optional
84 .param int has_todo :opt_flag
87 convert = get_hll_global ['String';'Utils'], 'convert_string_to_int'
89 .local int t_target, t_len, ok_target, ok_len, ok
90 (t_target, t_len) = convert(source, radix, pos)
92 ok_target = iseq t_target, target
93 ok_len = iseq t_len, len
94 ok = and ok_target, ok_len
97 test = get_global '$test'
99 if has_todo goto todo_test
100 test.'ok'(ok, description)
103 test.'todo'(ok, description, todo)
107 .sub test_radix_digits
113 .param string description
114 .param string todo :named('todo') :optional
115 .param int has_todo :opt_flag
118 convert = get_hll_global ['String';'Utils'], 'convert_digits_to_string'
120 .local int t_target, t_len, ok_target, ok_len, ok
121 (t_target, t_len) = convert(source, radix, pos)
123 ok_target = iseq t_target, target
124 ok_len = iseq t_len, len
125 ok = and ok_target, ok_len
128 test = get_global '$test'
130 if has_todo goto todo_test
131 test.'ok'(ok, description)
134 test.'todo'(ok, description, todo)
142 # vim: expandtab shiftwidth=4 ft=pir: