-
Notifications
You must be signed in to change notification settings - Fork 135
/
underscores.t
78 lines (52 loc) · 1.68 KB
/
underscores.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use v6;
use Test;
# L<S02/Underscores/"A single underscore is allowed only">
=begin pod
_ should be allowed in numbers
But according to L<S02/Literals/"A single underscore is allowed only">, only between two digits.
=end pod
plan 19;
is 1_0, 10, "Single embedded underscore works";
throws_like { EVAL '1__0' },
X::Comp::Group,
"Multiple embedded underscores fail";
throws_like { EVAL '_10' },
X::Undeclared::Symbols,
"Leading underscore fails";
throws_like { EVAL '10_' },
X::Syntax::Confused,
"Trailing underscore fails";
throws_like { EVAL '10_.0' },
X::Syntax::Confused,
"Underscore before . fails";
throws_like { EVAL '10._0' },
X::Method::NotFound,
"Underscore after . fails";
throws_like { EVAL '10_e1' },
X::Syntax::Confused,
"Underscore before e fails";
throws_like { EVAL '10e_1' },
X::Syntax::Confused,
"Underscore after e fails";
throws_like { EVAL '10_E1' },
X::Syntax::Confused,
"Underscore before E fails";
throws_like { EVAL '10E_1' },
X::Syntax::Confused,
"Underscore after E fails";
ok 3.1_41 == 3.141, "Underscores work with floating point after decimal";
ok 10_0.8 == 100.8, "Underscores work with floating point before decimal";
is 0xdead_beef, 0xdeadbeef, "Underscores work with hex";
is 0b1101_1110_1010_1101_1011_1110_1110_1111, 0xdeadbeef, "Underscores work with binary";
is 2e0_1, 20, "Underscores work in the argument for e";
ok 2.1_23 == 2.123, "2.1_23 parses as number";
throws_like { 2._foo },
X::Method::NotFound,
"2._foo parses as method call";
throws_like { 2._123 },
X::Method::NotFound,
"2._123 parses as method call";
throws_like { 2._e23 },
X::Method::NotFound,
"2._23 parses as method call";
# vim: ft=perl6