From 8490bb921bd03239f5856cd44b7e21ef6db23eca Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Fri, 8 Oct 2010 17:11:45 -0700 Subject: Fix bug with Lexer not recognizing exponential values and values starting with dots --- test/ParserTest.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/ParserTest.js') diff --git a/test/ParserTest.js b/test/ParserTest.js index 6a70bce8..916beb26 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -141,6 +141,38 @@ LexerTest.prototype.testNumber = function(){ expect(tokens[0].text).toEqual(0.5); }; +LexerTest.prototype.testNegativeNumber = function(){ + var value = createScope().$eval("-0.5"); + expect(value).toEqual(-0.5); + + value = createScope().$eval("{a:-0.5}"); + expect(value).toEqual({a:-0.5}); +}; + +LexerTest.prototype.testNumberExponent = function(){ + var tokens = lex("0.5E-10"); + expect(tokens[0].text).toEqual(0.5E-10); + expect(createScope().$eval("0.5E-10")).toEqual(0.5E-10); + + tokens = lex("0.5E+10"); + expect(tokens[0].text).toEqual(0.5E+10); +}; + +LexerTest.prototype.testNumberExponentInvalid = function(){ + assertThrows('Lexer found invalid exponential value "0.5E-"', function(){ + lex("0.5E-"); + }); + assertThrows('Lexer found invalid exponential value "0.5E-A"', function(){ + lex("0.5E-A"); + }); +}; + +LexerTest.prototype.testNumberStartingWithDot = function(){ + var tokens = lex(".5"); + expect(tokens[0].text).toEqual(0.5); +}; + + ParserTest = TestCase('ParserTest'); ParserTest.prototype.testExpressions = function(){ -- cgit v1.2.3