Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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