Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 231 lines (185 sloc) 8.999 kB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
2 use Test;
3
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
4 # L<S02/General radices/":10<42>">
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
5 is( :10<0>, 0, 'got the correct int value from decimal 0' );
6 is( :10<1>, 1, 'got the correct int value from decimal 1' );
7 is( :10<2>, 0d2, 'got the correct int value from decimal 2' );
8 is( :10<3>, 0d3, 'got the correct int value from decimal 3' );
799274b [t]: refactoring radix conversion tests for decimals
particle authored
9
10 # the answer to everything
11 is( 42, 0d42, '42 and 0d42 are the same' );
12 is( :10<42>, 42, ':10<42> and 42 are the same' );
13 is( :10<42>, 0d42, ':10<42> and 0d42 are the same' );
14
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
15 # L<S02/Conversion functions/"Think of these as setting the default radix">
799274b [t]: refactoring radix conversion tests for decimals
particle authored
16 # setting the default radix
17
41a51d3 @colomon Fudge for niecza.
colomon authored
18 #?niecza skip ":radix() NYI"
799274b [t]: refactoring radix conversion tests for decimals
particle authored
19 {
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
20 is(:10('01110') , 0d1110, ":10('01110') is default decimal");
21 #?pugs 4 todo "unimpl"
22 is(:10('0b1110'), 0b1110, ":10('0b1110') overrides default decimal");
23 is(:10('0x20'), 0x20, ":10('0x20') overrides default decimal");
24 is(:10('0o377'), 0o377, ":10('0o255') overrides default decimal");
25 is(:10('0d37'), 0d37, ":10('0d37') overrides default decimal");
799274b [t]: refactoring radix conversion tests for decimals
particle authored
26 }
27
28
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
29 # L<S29/Conversions/"prefix:<:16>">
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
30 # L<S02/General radices/":16<DEAD_BEEF>">
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
31
32 # 0 - 9 is the same int
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
33 is(:16<0>, 0, 'got the correct int value from hex 0');
34 is(:16<1>, 1, 'got the correct int value from hex 1');
35 is(:16<2>, 2, 'got the correct int value from hex 2');
36 is(:16<3>, 3, 'got the correct int value from hex 3');
37 is(:16<4>, 4, 'got the correct int value from hex 4');
38 is(:16<5>, 5, 'got the correct int value from hex 5');
39 is(:16<6>, 6, 'got the correct int value from hex 6');
40 is(:16<7>, 7, 'got the correct int value from hex 7');
41 is(:16<8>, 8, 'got the correct int value from hex 8');
42 is(:16<9>, 9, 'got the correct int value from hex 9');
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
43
44 # check uppercase vals
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
45 is(:16<A>, 10, 'got the correct int value from hex A');
46 is(:16<B>, 11, 'got the correct int value from hex B');
47 is(:16<C>, 12, 'got the correct int value from hex C');
48 is(:16<D>, 13, 'got the correct int value from hex D');
49 is(:16<E>, 14, 'got the correct int value from hex E');
50 is(:16<F>, 15, 'got the correct int value from hex F');
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
51
52 # check lowercase vals
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
53 is(:16<a>, 10, 'got the correct int value from hex a');
54 is(:16<b>, 11, 'got the correct int value from hex b');
55 is(:16<c>, 12, 'got the correct int value from hex c');
56 is(:16<d>, 13, 'got the correct int value from hex d');
57 is(:16<e>, 14, 'got the correct int value from hex e');
58 is(:16<f>, 15, 'got the correct int value from hex f');
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
59
60 # check 2 digit numbers
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
61 is(:16<10>, 16, 'got the correct int value from hex 10');
62 is(:16<20>, 32, 'got the correct int value from hex 20');
63 is(:16<30>, 48, 'got the correct int value from hex 30');
64 is(:16<40>, 64, 'got the correct int value from hex 40');
65 is(:16<50>, 80, 'got the correct int value from hex 50');
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
66
67 # check 3 digit numbers
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
68 is(:16<100>, 256, 'got the correct int value from hex 100');
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
69
70 # check some weird versions
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
71 is(:16<FF>, 255, 'got the correct int value from hex FF');
72 is(:16<fF>, 255, 'got the correct int value from (mixed case) hex fF');
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
73
74 # some random mad up hex strings (these values are checked against perl5)
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
75 is :16<2_F_A_C_E_D>, 0x2FACED, 'got the correct int value from hex 2_F_A_C_E_D';
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
76
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
77 # L<S02/Conversion functions/"interpret leading 0b or 0d as hex digits">
fcecec7 @moritz rakudo (un)fudges
moritz authored
78 #?rakudo 2 skip ':base()'
41a51d3 @colomon Fudge for niecza.
colomon authored
79 #?niecza 2 skip ":radix() NYI"
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
80 is(:16('0b1110'), 0xB1110, ":16('0b1110') uses b as hex digit" );
81 is(:16('0d37'), 0x0D37, ":16('0d37') uses d as hex digit" );
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
82
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
83 # L<S02/Conversion functions/"Think of these as setting the default radix">
41a51d3 @colomon Fudge for niecza.
colomon authored
84 #?niecza skip ":radix() NYI"
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
85 {
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
86 is(:16('0fff'), 0xfff, ":16('0fff') defaults to hexadecimal");
87 #?pugs 2 todo 'feature'
88 is(:16('0x20'), 0x20, ":16('0x20') stays hexadecimal");
89 is(:16('0o377'), 0o377, ":16('0o255') converts from octal");
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
90 }
91
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
92 # L<S02/Exponentials/"which will be interpreted as they would outside the string">
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
93 # It seems odd that the numbers on the inside on the <> would be a mix of
94 # bases. Maybe I've misread the paragraph -- brian
f60ff61 [fudge] more sub counting tweaks
lwall authored
95 #?pugs todo 'feature'
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
96 {
4ad0098 @colomon Fix tests for improved is_approx.
colomon authored
97 is_approx(:16<dead_beef> * 16**8, :16<dead_beef*16**8>,
fddeaa8 [t]: refactoring radix conversion tests for hexadecimals
particle authored
98 'Powers outside same as powers inside');
99 }
100
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
101 # L<S02/General radices/"Any radix may include a fractional part">
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
102
4ad0098 @colomon Fix tests for improved is_approx.
colomon authored
103 is_approx(:16<dead_beef.face>, 0xDEAD_BEEF + 0xFACE / 65536.0, 'Fractional base 16 works' );
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
104
105
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
106 # L<S02/General radices/":8<177777>">
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
107 # L<S29/Conversions/"prefix:<:8>">
108
109 # 0 - 7 is the same int
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
110 is(:8<0>, 0, 'got the correct int value from oct 0');
111 is(:8<1>, 1, 'got the correct int value from oct 1');
112 is(:8<2>, 2, 'got the correct int value from oct 2');
113 is(:8<3>, 3, 'got the correct int value from oct 3');
114 is(:8<4>, 4, 'got the correct int value from oct 4');
115 is(:8<5>, 5, 'got the correct int value from oct 5');
116 is(:8<6>, 6, 'got the correct int value from oct 6');
117 is(:8<7>, 7, 'got the correct int value from oct 7');
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
118
119 # check 2 digit numbers
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
120 is(:8<10>, 8, 'got the correct int value from oct 10');
121 is(:8<20>, 16, 'got the correct int value from oct 20');
122 is(:8<30>, 24, 'got the correct int value from oct 30');
123 is(:8<40>, 32, 'got the correct int value from oct 40');
124 is(:8<50>, 40, 'got the correct int value from oct 50');
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
125
126 # check 3 digit numbers
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
127 is(:8<100>, 64, 'got the correct int value from oct 100');
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
128
129 # check some weird versions
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
130 is(:8<77>, 63, 'got the correct int value from oct 77');
131 is(:8<377>, 255, 'got the correct int value from oct 377');
132 is(:8<400>, 256, 'got the correct int value from oct 400');
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
133 is(:8<177777>, 65535, 'got the correct int value from oct 177777');
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
134 is(:8<200000>, 65536, 'got the correct int value from oct 200000');
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
135
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
136 # L<S02/Conversion functions/"Think of these as setting the default radix">
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
137 # setting the default radix
138
f60ff61 [fudge] more sub counting tweaks
lwall authored
139 #?pugs todo 'feature'
fcecec7 @moritz rakudo (un)fudges
moritz authored
140 #?rakudo skip "Some question of what this form should actually do"
41a51d3 @colomon Fudge for niecza.
colomon authored
141 #?niecza skip ":radix() NYI"
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
142 {
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
143 is(:8('0b1110'), 0o14, ':8(0b1110) converts from decimal');
144 is(:8('0x20'), 0o32, ':8(0x20) converts from decimal');
145 is(:8('0o377'), 0o255, ':8(0o255) stays decimal');
146 is(:8('0d37'), 0o37, ':8(0d37) converts from decimal');
0ff9d46 [t]: refactoring radix conversion tests for octals
particle authored
147 }
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
148
149
150 # L<S29/Conversions/"prefix:<:2>">
151
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
152 is(:2<0>, 0, 'got the correct int value from bin 0');
153 is(:2<1>, 1, 'got the correct int value from bin 1');
154 is(:2<10>, 2, 'got the correct int value from bin 10');
155 is(:2<1010>, 10, 'got the correct int value from bin 1010');
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
156
494b5a8 [t/spec] fix some incorrect test markers for rakudo
particle authored
157 is(
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
158 :2<11111111111111111111111111111111>,
494b5a8 [t/spec] fix some incorrect test markers for rakudo
particle authored
159 0xFFFFFFFF,
160 'got the correct int value from bin 11111111111111111111111111111111');
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
161
162
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
163 # L<S02/Conversion functions/"Think of these as setting the default radix">
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
164 # setting the default radix
165
f60ff61 [fudge] more sub counting tweaks
lwall authored
166 #?pugs todo 'feature'
41a51d3 @colomon Fudge for niecza.
colomon authored
167 #?niecza skip ":radix() NYI"
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
168 {
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
169 is(:2('0b1110'), 0d14, ':2<0b1110> stays binary');
170 is(:2('0x20'), 0d32, ':2<0x20> converts from hexadecimal');
171 is(:2('0o377'), 0d255, ':2<0o255> converts from octal');
172 is(:2('0d37'), 0d37, ':2<0d37> converts from decimal');
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
173 }
174
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
175 # L<S02/Exponentials/"not clear whether the exponentiator should be 10 or the radix">
3488142 [spec]
moritz authored
176 eval_dies_ok '0b1.1e10', 'Ambiguous, illegal syntax doesn\'t work';
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
177
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
178 # L<S02/Exponentials/"and this makes it explicit">
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
179 # probably don't need a test, but I'll write tests for any example :)
494b5a8 [t/spec] fix some incorrect test markers for rakudo
particle authored
180 is( :2<1.1> * 2 ** 10, 1536, 'binary number to power of 2' );
181 is( :2<1.1> * :2<10> ** :2<10>, 6, 'multiplication and exponentiation' );
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
182
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
183 # L<S02/Exponentials/"So we write those as">
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
184 # these should be the same values as the previous tests
f60ff61 [fudge] more sub counting tweaks
lwall authored
185 #?pugs todo 'feature'
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
186 {
187 is( :2<1.1*2**10>, 1536, 'Power of two in <> works');
001e798 @moritz &eval does not catch exceptions.
moritz authored
188 #?rakudo skip "Really?!"
41a51d3 @colomon Fudge for niecza.
colomon authored
189 #?niecza skip "WTF?"
001e798 @moritz &eval does not catch exceptions.
moritz authored
190 is( 2«1.1*:2<10>**:2<10>», 6, 'Powers of two in <<>> works');
ae58093 [radix.t] major overhaul of bogus functional forms that assumed paren…
lwall authored
191 }
494b5a8 [t/spec] fix some incorrect test markers for rakudo
particle authored
192
454dd67 [t] merged a few tests into spec/
moritz authored
193 # Tests for the :x[ <list> ] notations
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
194 # L<S02/General radices/"Alternately you can use a list of digits in decimal">
6813ef6 [t/spec] Fudge radix.t to work with lue++'s patch.
colomon authored
195 #?rakudo skip ":radix[] NYI"
41a51d3 @colomon Fudge for niecza.
colomon authored
196 #?niecza skip ":radix[] NYI"
454dd67 [t] merged a few tests into spec/
moritz authored
197 {
198 is( :60[12,34,56], 12 * 3600 + 34 * 60 + 56, 'List of numbers works' );
199 is( :100[3,'.',14,16], 3.1416, 'Decimal point in list works' );
200
201 is :100[10,10], 1010, "Adverbial form of base 100 integer works";
202 is :100[10,'.',10], 10.10, "Adverbial form of base 100 fraction works";
203 }
7a747c8 [t]: refactoring radix conversion tests for binary, and fractions
particle authored
204
87f2873 [t] merged syntax/numbers/misc.t iinto radix.t, deleted duplicate tests
moritz authored
205 # What follows are tests that were moved here from t/syntax/numbers/misc.t
206 # feel free to merge them inline into the other tests
207
208 # Ambiguity tests, see thread "Ambiguity of parsing numbers with
209 # underscores/methods" on p6l started by Ingo Blechschmidt:
210 # L<"http://www.nntp.perl.org/group/perl.perl6.language/22769">
211 # Answer from Luke:
212 # I think we should go with the method call semantics in all of the ambiguous
213 # forms, mostly because "no such method: Int::e5" is clearer than silently
214 # succeeding and the error coming up somewhere else.
215 dies_ok { 2.e123 }, "2.e123 parses as method call";
216 dies_ok { 2.foo }, "2.foo parses as method call";
217
218 is +'00123', 123, "Leading zeroes stringify correctly";
219
f2c5529 @colomon Refudge for latest niecza changes.
colomon authored
220 #?niecza 2 todo
87f2873 [t] merged syntax/numbers/misc.t iinto radix.t, deleted duplicate tests
moritz authored
221 eval_dies_ok ':2<2>', ':2<2> is illegal';
222 eval_dies_ok ':10<3a>', ':10<3a> is illegal';
223
224 for 2..36 {
225 is eval(":{$_}<11>"), $_ + 1, "Adverbial form of base $_ works";
226 }
227
7353f94 @moritz make test plan in radix.t dynamic, since I do not know if fudge misco…
moritz authored
228 done;
229
454dd67 [t] merged a few tests into spec/
moritz authored
230 # vim: ft=perl6
Something went wrong with that request. Please try again.