aboutsummaryrefslogtreecommitdiffstats
path: root/test/ParserTest.js
diff options
context:
space:
mode:
authorMisko Hevery2010-10-15 13:44:53 -0700
committerMisko Hevery2010-10-15 13:44:53 -0700
commita36964799be3d21163ba6350d862fced2bbd3437 (patch)
tree8c703eb9b19541c25c4e1105e511426a646c9c4d /test/ParserTest.js
parentd320e3d2c3b72896603a3df3abd26adc0bfa3c10 (diff)
downloadangular.js-a36964799be3d21163ba6350d862fced2bbd3437.tar.bz2
fixed lint warnings and one flaky test
Diffstat (limited to 'test/ParserTest.js')
-rw-r--r--test/ParserTest.js463
1 files changed, 0 insertions, 463 deletions
diff --git a/test/ParserTest.js b/test/ParserTest.js
deleted file mode 100644
index a8211404..00000000
--- a/test/ParserTest.js
+++ /dev/null
@@ -1,463 +0,0 @@
-desccribe('parser', function(){
- describe('lexer', function(){
- it('should TokenizeAString', function(){
- var tokens = lex("a.bc[22]+1.3|f:'a\\\'c':\"d\\\"e\"");
- var i = 0;
- assertEquals(tokens[i].index, 0);
- assertEquals(tokens[i].text, 'a.bc');
-
- i++;
- assertEquals(tokens[i].index, 4);
- assertEquals(tokens[i].text, '[');
-
- i++;
- assertEquals(tokens[i].index, 5);
- assertEquals(tokens[i].text, 22);
-
- i++;
- assertEquals(tokens[i].index, 7);
- assertEquals(tokens[i].text, ']');
-
- i++;
- assertEquals(tokens[i].index, 8);
- assertEquals(tokens[i].text, '+');
-
- i++;
- assertEquals(tokens[i].index, 9);
- assertEquals(tokens[i].text, 1.3);
-
- i++;
- assertEquals(tokens[i].index, 12);
- assertEquals(tokens[i].text, '|');
-
- i++;
- assertEquals(tokens[i].index, 13);
- assertEquals(tokens[i].text, 'f');
-
- i++;
- assertEquals(tokens[i].index, 14);
- assertEquals(tokens[i].text, ':');
-
- i++;
- assertEquals(tokens[i].index, 15);
- assertEquals(tokens[i].string, "a'c");
-
- i++;
- assertEquals(tokens[i].index, 21);
- assertEquals(tokens[i].text, ':');
-
- i++;
- assertEquals(tokens[i].index, 22);
- assertEquals(tokens[i].string, 'd"e');
- });
-
- it('should TokenizeUndefined', function(){
- var tokens = lex("undefined");
- var i = 0;
- assertEquals(tokens[i].index, 0);
- assertEquals(tokens[i].text, 'undefined');
- assertEquals(undefined, tokens[i].fn());
- });
-
-
-
- it('should TokenizeRegExp', function(){
- var tokens = lex("/r 1/");
- var i = 0;
- assertEquals(tokens[i].index, 0);
- assertEquals(tokens[i].text, 'r 1');
- assertEquals("r 1".match(tokens[i].fn())[0], 'r 1');
- });
-
- it('should QuotedString', function(){
- var str = "['\\'', \"\\\"\"]";
- var tokens = lex(str);
-
- assertEquals(1, tokens[1].index);
- assertEquals("'", tokens[1].string);
-
- assertEquals(7, tokens[3].index);
- assertEquals('"', tokens[3].string);
- });
-
- it('should QuotedStringEscape', function(){
- var str = '"\\"\\n\\f\\r\\t\\v\\u00A0"';
- var tokens = lex(str);
-
- assertEquals('"\n\f\r\t\v\u00A0', tokens[0].string);
- });
-
- it('should TokenizeUnicode', function(){
- var tokens = lex('"\\u00A0"');
- assertEquals(1, tokens.length);
- assertEquals('\u00a0', tokens[0].string);
- });
-
- it('should TokenizeRegExpWithOptions', function(){
- var tokens = lex("/r/g");
- var i = 0;
- assertEquals(tokens[i].index, 0);
- assertEquals(tokens[i].text, 'r');
- assertEquals(tokens[i].flags, 'g');
- assertEquals("rr".match(tokens[i].fn()).length, 2);
- });
-
- it('should TokenizeRegExpWithEscape', function(){
- var tokens = lex("/\\/\\d/");
- var i = 0;
- assertEquals(tokens[i].index, 0);
- assertEquals(tokens[i].text, '\\/\\d');
- assertEquals("/1".match(tokens[i].fn())[0], '/1');
- });
-
- it('should IgnoreWhitespace', function(){
- var tokens = lex("a \t \n \r b");
- assertEquals(tokens[0].text, 'a');
- assertEquals(tokens[1].text, 'b');
- });
-
- it('should Relation', function(){
- var tokens = lex("! == != < > <= >=");
- assertEquals(tokens[0].text, '!');
- assertEquals(tokens[1].text, '==');
- assertEquals(tokens[2].text, '!=');
- assertEquals(tokens[3].text, '<');
- assertEquals(tokens[4].text, '>');
- assertEquals(tokens[5].text, '<=');
- assertEquals(tokens[6].text, '>=');
- });
-
- it('should Statements', function(){
- var tokens = lex("a;b;");
- assertEquals(tokens[0].text, 'a');
- assertEquals(tokens[1].text, ';');
- assertEquals(tokens[2].text, 'b');
- assertEquals(tokens[3].text, ';');
- });
-
- it('should Number', function(){
- var tokens = lex("0.5");
- expect(tokens[0].text).toEqual(0.5);
- });
-
- it('should NegativeNumber', function(){
- var value = createScope().$eval("-0.5");
- expect(value).toEqual(-0.5);
-
- value = createScope().$eval("{a:-0.5}");
- expect(value).toEqual({a:-0.5});
- });
-
- it('should NumberExponent', 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);
- });
-
- it('should NumberExponentInvalid', 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");
- });
- });
-
- it('should NumberStartingWithDot', function(){
- var tokens = lex(".5");
- expect(tokens[0].text).toEqual(0.5);
- });
- });
-});
-
-ParserTest = TestCase('ParserTest');
-
-ParserTest.prototype.testExpressions = function(){
- var scope = createScope();
- assertEquals(scope.$eval("-1"), -1);
- assertEquals(scope.$eval("1 + 2.5"), 3.5);
- assertEquals(scope.$eval("1 + -2.5"), -1.5);
- assertEquals(scope.$eval("1+2*3/4"), 1+2*3/4);
- assertEquals(scope.$eval("0--1+1.5"), 0- -1 + 1.5);
- assertEquals(scope.$eval("-0--1++2*-3/-4"), -0- -1+ +2*-3/-4);
- assertEquals(scope.$eval("1/2*3"), 1/2*3);
-};
-
-ParserTest.prototype.testComparison = function(){
- var scope = createScope();
- assertEquals(scope.$eval("false"), false);
- assertEquals(scope.$eval("!true"), false);
- assertEquals(scope.$eval("1==1"), true);
- assertEquals(scope.$eval("1!=2"), true);
- assertEquals(scope.$eval("1<2"), true);
- assertEquals(scope.$eval("1<=1"), true);
- assertEquals(scope.$eval("1>2"), 1>2);
- assertEquals(scope.$eval("2>=1"), 2>=1);
-
- assertEquals(true === 2<3, scope.$eval("true==2<3"));
-
-};
-
-ParserTest.prototype.testLogical = function(){
- var scope = createScope();
- assertEquals(scope.$eval("0&&2"), 0&&2);
- assertEquals(scope.$eval("0||2"), 0||2);
- assertEquals(scope.$eval("0||1&&2"), 0||1&&2);
-};
-
-ParserTest.prototype.testString = function(){
- var scope = createScope();
- assertEquals(scope.$eval("'a' + 'b c'"), "ab c");
-};
-
-ParserTest.prototype.testFilters = function(){
- angular.filter.substring = function(input, start, end) {
- return input.substring(start, end);
- };
-
- angular.filter.upper = {_case:function(input) {
- return input.toUpperCase();
- }};
- var scope = createScope();
- try {
- scope.$eval("1|nonExistant");
- fail();
- } catch (e) {
- assertEquals(e, "Function 'nonExistant' at column '3' in '1|nonExistant' is not defined.");
- }
- scope.$set('offset', 3);
- assertEquals(scope.$eval("'abcd'|upper._case"), "ABCD");
- assertEquals(scope.$eval("'abcd'|substring:1:offset"), "bc");
- assertEquals(scope.$eval("'abcd'|substring:1:3|upper._case"), "BC");
-};
-
-ParserTest.prototype.testScopeAccess = function(){
- var scope = createScope();
- scope.$set('a', 123);
- scope.$set('b.c', 456);
- assertEquals(scope.$eval("a", scope), 123);
- assertEquals(scope.$eval("b.c", scope), 456);
- assertEquals(scope.$eval("x.y.z", scope), undefined);
-};
-
-ParserTest.prototype.testGrouping = function(){
- var scope = createScope();
- assertEquals(scope.$eval("(1+2)*3"), (1+2)*3);
-};
-
-ParserTest.prototype.testAssignments = function(){
- var scope = createScope();
- assertEquals(scope.$eval("a=12"), 12);
- assertEquals(scope.$get("a"), 12);
-
- scope = createScope();
- assertEquals(scope.$eval("x.y.z=123;"), 123);
- assertEquals(scope.$get("x.y.z"), 123);
-
- assertEquals(234, scope.$eval("a=123; b=234"));
- assertEquals(123, scope.$get("a"));
- assertEquals(234, scope.$get("b"));
-};
-
-ParserTest.prototype.testFunctionCallsNoArgs = function(){
- var scope = createScope();
- scope.$set('const', function(a,b){return 123;});
- assertEquals(scope.$eval("const()"), 123);
-};
-
-ParserTest.prototype.testFunctionCalls = function(){
- var scope = createScope();
- scope.$set('add', function(a,b){
- return a+b;
- });
- assertEquals(3, scope.$eval("add(1,2)"));
-};
-
-ParserTest.prototype.testCalculationBug = function(){
- var scope = createScope();
- scope.$set('taxRate', 8);
- scope.$set('subTotal', 100);
- assertEquals(scope.$eval("taxRate / 100 * subTotal"), 8);
- assertEquals(scope.$eval("subTotal * taxRate / 100"), 8);
-};
-
-ParserTest.prototype.testArray = function(){
- var scope = createScope();
- assertEquals(scope.$eval("[]").length, 0);
- assertEquals(scope.$eval("[1, 2]").length, 2);
- assertEquals(scope.$eval("[1, 2]")[0], 1);
- assertEquals(scope.$eval("[1, 2]")[1], 2);
-};
-
-ParserTest.prototype.testArrayAccess = function(){
- var scope = createScope();
- assertEquals(scope.$eval("[1][0]"), 1);
- assertEquals(scope.$eval("[[1]][0][0]"), 1);
- assertEquals(scope.$eval("[].length"), 0);
- assertEquals(scope.$eval("[1, 2].length"), 2);
-};
-
-ParserTest.prototype.testObject = function(){
- var scope = createScope();
- assertEquals(toJson(scope.$eval("{}")), "{}");
- assertEquals(toJson(scope.$eval("{a:'b'}")), '{"a":"b"}');
- assertEquals(toJson(scope.$eval("{'a':'b'}")), '{"a":"b"}');
- assertEquals(toJson(scope.$eval("{\"a\":'b'}")), '{"a":"b"}');
-};
-
-ParserTest.prototype.testObjectAccess = function(){
- var scope = createScope();
- assertEquals("WC", scope.$eval("{false:'WC', true:'CC'}[false]"));
-};
-
-ParserTest.prototype.testJSON = function(){
- var scope = createScope();
- assertEquals(toJson(scope.$eval("[{}]")), "[{}]");
- assertEquals(toJson(scope.$eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]');
-};
-
-ParserTest.prototype.testMultippleStatements = function(){
- var scope = createScope();
- assertEquals(scope.$eval("a=1;b=3;a+b"), 4);
- assertEquals(scope.$eval(";;1;;"), 1);
-};
-
-ParserTest.prototype.testParseThrow = function(){
- expectAsserts(1);
- var scope = createScope();
- scope.$set('e', 'abc');
- try {
- scope.$eval("throw e");
- } catch(e) {
- assertEquals(e, 'abc');
- }
-};
-
-ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){
- var scope = createScope();
- var C = function (){
- this.a=123;
- };
- C.prototype.getA = function(){
- return this.a;
- };
-
- scope.$set("obj", new C());
- assertEquals(123, scope.$eval("obj.getA()"));
-};
-ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){
- var scope = createScope();
- var C = function (){
- this.a=123;
- };
- C.prototype.sum = function(value){
- return this.a + value;
- };
- C.prototype.getA = function(){
- return this.a;
- };
-
- scope.$set("obj", new C());
- assertEquals(246, scope.$eval("obj.sum(obj.getA())"));
-};
-
-ParserTest.prototype.testObjectPointsToScopeValue = function(){
- var scope = createScope();
- scope.$set('a', "abc");
- assertEquals("abc", scope.$eval("{a:a}").a);
-};
-
-ParserTest.prototype.testFieldAccess = function(){
- var scope = createScope();
- var fn = function(){
- return {name:'misko'};
- };
- scope.$set('a', fn);
- assertEquals("misko", scope.$eval("a().name"));
-};
-
-ParserTest.prototype.testArrayIndexBug = function () {
- var scope = createScope();
- scope.$set('items', [{}, {name:'misko'}]);
-
- assertEquals("misko", scope.$eval('items[1].name'));
-};
-
-ParserTest.prototype.testArrayAssignment = function () {
- var scope = createScope();
- scope.$set('items', []);
-
- assertEquals("abc", scope.$eval('items[1] = "abc"'));
- assertEquals("abc", scope.$eval('items[1]'));
-// Dont know how to make this work....
-// assertEquals("moby", scope.$eval('books[1] = "moby"'));
-// assertEquals("moby", scope.$eval('books[1]'));
-};
-
-ParserTest.prototype.testFiltersCanBeGrouped = function () {
- var scope = createScope({name:'MISKO'});
- assertEquals('misko', scope.$eval('n = (name|lowercase)'));
- assertEquals('misko', scope.$eval('n'));
-};
-
-ParserTest.prototype.testFiltersCanBeGrouped = function () {
- var scope = createScope({name:'MISKO'});
- assertEquals('misko', scope.$eval('n = (name|lowercase)'));
- assertEquals('misko', scope.$eval('n'));
-};
-
-ParserTest.prototype.testRemainder = function () {
- var scope = createScope();
- assertEquals(1, scope.$eval('1%2'));
-};
-
-ParserTest.prototype.testSumOfUndefinedIsNotUndefined = function () {
- var scope = createScope();
- assertEquals(1, scope.$eval('1+undefined'));
- assertEquals(1, scope.$eval('undefined+1'));
-};
-
-ParserTest.prototype.testMissingThrowsError = function() {
- var scope = createScope();
- try {
- scope.$eval('[].count(');
- fail();
- } catch (e) {
- assertEquals('Unexpected end of expression: [].count(', e);
- }
-};
-
-ParserTest.prototype.testDoubleNegationBug = function (){
- var scope = createScope();
- assertEquals(true, scope.$eval('true'));
- assertEquals(false, scope.$eval('!true'));
- assertEquals(true, scope.$eval('!!true'));
- assertEquals('a', scope.$eval('{true:"a", false:"b"}[!!true]'));
-};
-
-ParserTest.prototype.testNegationBug = function () {
- var scope = createScope();
- assertEquals(!false || true, scope.$eval("!false || true"));
- assertEquals(!11 == 10, scope.$eval("!11 == 10"));
- assertEquals(12/6/2, scope.$eval("12/6/2"));
-};
-
-ParserTest.prototype.testBugStringConfusesParser = function() {
- var scope = createScope();
- assertEquals('!', scope.$eval('suffix = "!"'));
-};
-
-ParserTest.prototype.testParsingBug = function () {
- var scope = createScope();
- assertEquals({a: "-"}, scope.$eval("{a:'-'}"));
-};
-
-ParserTest.prototype.testUndefined = function () {
- var scope = createScope();
- assertEquals(undefined, scope.$eval("undefined"));
- assertEquals(undefined, scope.$eval("a=undefined"));
- assertEquals(undefined, scope.$get("a"));
-};