Skip to content

HTTPS clone URL

Subversion checkout URL

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