Skip to content

Commit 0573362

Browse files
committed
start testing numbers
1 parent ad2b9ab commit 0573362

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

src/lexer/numbers.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
* @url http://glayzzle.com
55
*/
66

7+
"use strict";
8+
79
/* istanbul ignore else */
810
if (process.arch == 'x64') {
911
var SIZEOF_LONG = 8;
10-
var MAX_LENGTH_OF_LONG = 20;
12+
var MAX_LENGTH_OF_LONG = 19;
1113
var long_min_digits = "9223372036854775808";
1214
} else {
1315
var SIZEOF_LONG = 4;
14-
var MAX_LENGTH_OF_LONG = 11;
16+
var MAX_LENGTH_OF_LONG = 10;
1517
var long_min_digits = "2147483648";
1618
}
1719

@@ -76,8 +78,10 @@ module.exports = {
7678
return this.tok.T_LNUMBER;
7779
} else {
7880
if (
79-
this.yytext.length == MAX_LENGTH_OF_LONG
80-
&& this.yytext < long_min_digits
81+
this.yytext.length < MAX_LENGTH_OF_LONG || (
82+
this.yytext.length == MAX_LENGTH_OF_LONG
83+
&& this.yytext < long_min_digits
84+
)
8185
) {
8286
return this.tok.T_LNUMBER;
8387
}

test/astTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var should = require("should");
2-
var parser = require('../src/index');
2+
var parser = require('./main');
33

44
describe('Test AST structure', function() {
55

test/numberTests.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var should = require("should");
2+
var parser = require('./main');
3+
4+
describe('Test numbers', function() {
5+
6+
describe('comon tests', function() {
7+
var ast = parser.parseEval([
8+
'$a = -1.5;',
9+
'$b = 1234;',
10+
'$c = 9223372036854775807;',
11+
'$c = 9223372036854775808;',
12+
'$d = 0x1A;',
13+
'$d = 0xFF;',
14+
'$e = 0b1011;',
15+
'$f = 0123;',
16+
'$g = 1.2e3;',
17+
'$h = 7E-10;'
18+
].join('\n'));
19+
it('should be float', function() {
20+
ast.children[0].right.kind.should.be.exactly('number');
21+
ast.children[0].right.value.should.be.exactly('-1.5');
22+
});
23+
24+
});
25+
// @fixme should test bad syntaxes
26+
// like 01239 (octal number with bad token)
27+
describe('edge tests', function() {
28+
var ast = parser.parseEval([
29+
'$a = 0xx;',
30+
'$b = 0b2;',
31+
'$c = 01239;',
32+
'$d = 7E-a;',
33+
'$e = 7EX;'
34+
].join('\n'), {
35+
parser: {
36+
suppressErrors: true
37+
}
38+
});
39+
40+
});
41+
});

0 commit comments

Comments
 (0)