13
13
# Binary Integer Literals
14
14
# Binary notation is understood as would be decimal notation.
15
15
16
+ toJS = (str ) ->
17
+ CoffeeScript .compile str, bare : yes
18
+ .replace / ^ \s + | \s + $ / g , ' ' # Trim leading/trailing whitespace
19
+
16
20
test " Parser recognises binary numbers" , ->
17
21
eq 4 , 0b100
18
22
23
+ test " Binary literals are compiled to binary literals" , ->
24
+ input = """
25
+ a = 0b100
26
+ """
27
+
28
+ output = """
29
+ var a;
30
+
31
+ a = 0b100;
32
+ """
33
+
34
+ eq toJS (input), output
35
+
19
36
# Decimal Integer Literals
20
37
21
38
test " call methods directly on numbers" , ->
@@ -24,6 +41,32 @@ test "call methods directly on numbers", ->
24
41
25
42
eq - 1 , 3 - 4
26
43
44
+ test " Decimal literals are compiled to decimal literals" , ->
45
+ input = """
46
+ a = 10
47
+ """
48
+
49
+ output = """
50
+ var a;
51
+
52
+ a = 10;
53
+ """
54
+
55
+ eq toJS (input), output
56
+
57
+ test " Decimal literals are compiled to decimal literals" , ->
58
+ input = """
59
+ a = 10.1
60
+ """
61
+
62
+ output = """
63
+ var a;
64
+
65
+ a = 10.1;
66
+ """
67
+
68
+ eq toJS (input), output
69
+
27
70
# 764: Numbers should be indexable
28
71
eq Number :: toString , 42 [' toString' ]
29
72
@@ -66,6 +109,19 @@ test "Python-style octal literal notation '0o777'", ->
66
109
eq Number :: toString , 0o777 [' toString' ]
67
110
eq Number :: toString , 0o777 .toString
68
111
112
+ test " Octal literals are compiled to octal literals" , ->
113
+ input = """
114
+ a = 0o123
115
+ """
116
+
117
+ output = """
118
+ var a;
119
+
120
+ a = 0o123;
121
+ """
122
+
123
+ eq toJS (input), output
124
+
69
125
test " #2060: Disallow uppercase radix prefixes and exponential notation" , ->
70
126
for char in [' b' , ' o' , ' x' , ' e' ]
71
127
program = " 0#{ char} 0"
0 commit comments