Update Trac ticket URLs to point to GitLab
[ghc.git] / testsuite / tests / parser / should_run / NumericUnderscores0.hs
1 {-# LANGUAGE NumericUnderscores #-}
2 {-# LANGUAGE BinaryLiterals #-}
3 {-# LANGUAGE HexFloatLiterals #-}
4 {-# LANGUAGE NegativeLiterals #-}
5
6 -- Test for NumericUnderscores extension.
7 -- See #14473
8 -- This is a testcase for boxed literals.
9
10 main :: IO ()
11 main = do
12 -- Each case corresponds to the definition of Lexer.x
13 --
14 -- Normal integral literals
15 -- decimal
16 print [ 1_000_000 == 1000000,
17 1__0 == 10,
18 299_792_458 == 299792458,
19 8_04_1 == 8041,
20 2017_12_31 == 20171231
21 ]
22
23 -- binary
24 print [ 0b01_0000_0000 == 0b0100000000,
25 0b1_11_01_0000_0_111 == 0b1110100000111,
26 0b1100_1011__1110_1111__0101_0011 ==
27 0b110010111110111101010011
28 ]
29
30 -- octal
31 print [ 0o1_000_000 == 0o1000000,
32 0O1__0 == 0O10
33 ]
34
35 -- hexadecimal
36 print [ 0x1_000_000 == 0x1000000,
37 0x1__0 == 0x10,
38 0xff_00_00 == 0xff0000,
39 0X3fff_ffff == 0x3fffffff
40 ]
41
42 -- negative decimal
43 print [ -1_0 == -10
44 ]
45
46 -- negative binary
47 print [ -0b1_0 == -0b10
48 ]
49
50 -- negative octal
51 print [ -0o1_0 == -0o10
52 ]
53
54 -- negative hexadecimal
55 print [ -0x1_0 == -0x10
56 ]
57
58 ---- Normal rational literals
59 -- float
60 print [ 3.141_592_653_589_793 == 3.141592653589793,
61 96_485.332_89 == 96485.33289,
62 6.022_140_857e+23 == 6.022140857e+23
63 ]
64
65 -- negative float
66 print [ -1_0.0_1 == -10.01,
67 -1_0e+2 == -10e+2,
68 -1_0.0_1e+3 == -10.01e+3
69 ]
70
71 -- hexadecimal float
72 print [ 0xF_F.1F == 0xFF.1F,
73 0xF_01p-8 == 0xF01p-8,
74 0x0.F_1p4 == 0x0.F1p4
75 ]
76
77 -- negative hexadecimal float
78 print [ -0xF_F.F == -0xFF.F,
79 -0xF_01p-1 == -0xF01p-1,
80 -0x0.F_1p1 == -0x0.F1p1
81 ]
82
83 -- Additional testcase
84 --
85 -- Validity
86 print [ 0.000_1 == 0.0001,
87 1_0.000_1 == 10.0001,
88 1e+23 == 1e+23,
89 1_e+23 == 1e+23,
90 1__e+23 == 1e+23,
91 1.0_e+23 == 1.0e+23,
92 1.0_e+2_3 == 1.0e+23,
93 1_e23 == 1e23,
94 1_e-23 == 1e-23,
95 1_0_e23 == 10e23,
96 1_0_e-23 == 10e-23,
97 0b_01 == 0b01,
98 0b__11 == 0b11,
99 0x_ff == 0xff,
100 0x__ff == 0xff
101 ]