diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ApiSpecs.js | 8 | ||||
| -rw-r--r-- | test/ParserSpec.js | 463 | ||||
| -rw-r--r-- | test/ParserTest.js | 463 | ||||
| -rw-r--r-- | test/scenario/DSLSpec.js | 113 | ||||
| -rw-r--r-- | test/scenario/HtmlUISpec.js | 44 | ||||
| -rw-r--r-- | test/scenario/SpecRunnerSpec.js | 12 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 6 |
7 files changed, 554 insertions, 555 deletions
diff --git a/test/ApiSpecs.js b/test/ApiSpecs.js index 5548d795..d1f693a5 100644 --- a/test/ApiSpecs.js +++ b/test/ApiSpecs.js @@ -159,11 +159,9 @@ describe('api', function(){ it('should use function', function(){ expect( orderBy( - [{a:15, b:1},{a:2, b:1}], - function(value){ return value.a; } - ) - ).toEqual([{a:2, b:1},{a:15, b:1}]); - + [{a:15, b:1},{a:2, b:1}], + function(value){ return value.a; })). + toEqual([{a:2, b:1},{a:15, b:1}]); }); }); diff --git a/test/ParserSpec.js b/test/ParserSpec.js new file mode 100644 index 00000000..e7b4e7f5 --- /dev/null +++ b/test/ParserSpec.js @@ -0,0 +1,463 @@ +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); + }); + }); + + it('should parse Expressions', 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); + }); + + it('should parse Comparison', 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")); + + }); + + it('should parse Logical', 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); + }); + + it('should parse String', function(){ + var scope = createScope(); + assertEquals(scope.$eval("'a' + 'b c'"), "ab c"); + }); + + it('should parse Filters', 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"); + }); + + it('should parse ScopeAccess', 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); + }); + + it('should parse Grouping', function(){ + var scope = createScope(); + assertEquals(scope.$eval("(1+2)*3"), (1+2)*3); + }); + + it('should parse Assignments', 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")); + }); + + it('should parse FunctionCallsNoArgs', function(){ + var scope = createScope(); + scope.$set('const', function(a,b){return 123;}); + assertEquals(scope.$eval("const()"), 123); + }); + + it('should parse FunctionCalls', function(){ + var scope = createScope(); + scope.$set('add', function(a,b){ + return a+b; + }); + assertEquals(3, scope.$eval("add(1,2)")); + }); + + it('should parse CalculationBug', 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); + }); + + it('should parse Array', 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); + }); + + it('should parse ArrayAccess', 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); + }); + + it('should parse Object', 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"}'); + }); + + it('should parse ObjectAccess', function(){ + var scope = createScope(); + assertEquals("WC", scope.$eval("{false:'WC', true:'CC'}[false]")); + }); + + it('should parse JSON', function(){ + var scope = createScope(); + assertEquals(toJson(scope.$eval("[{}]")), "[{}]"); + assertEquals(toJson(scope.$eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); + }); + + it('should parse MultippleStatements', function(){ + var scope = createScope(); + assertEquals(scope.$eval("a=1;b=3;a+b"), 4); + assertEquals(scope.$eval(";;1;;"), 1); + }); + + it('should parse ParseThrow', function(){ + expectAsserts(1); + var scope = createScope(); + scope.$set('e', 'abc'); + try { + scope.$eval("throw e"); + } catch(e) { + assertEquals(e, 'abc'); + } + }); + + it('should parse MethodsGetDispatchedWithCorrectThis', 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()")); + }); + it('should parse MethodsArgumentsGetCorrectThis', 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())")); + }); + + it('should parse ObjectPointsToScopeValue', function(){ + var scope = createScope(); + scope.$set('a', "abc"); + assertEquals("abc", scope.$eval("{a:a}").a); + }); + + it('should parse FieldAccess', function(){ + var scope = createScope(); + var fn = function(){ + return {name:'misko'}; + }; + scope.$set('a', fn); + assertEquals("misko", scope.$eval("a().name")); + }); + + it('should parse ArrayIndexBug', function () { + var scope = createScope(); + scope.$set('items', [{}, {name:'misko'}]); + + assertEquals("misko", scope.$eval('items[1].name')); + }); + + it('should parse ArrayAssignment', 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]')); + }); + + it('should parse FiltersCanBeGrouped', function () { + var scope = createScope({name:'MISKO'}); + assertEquals('misko', scope.$eval('n = (name|lowercase)')); + assertEquals('misko', scope.$eval('n')); + }); + + it('should parse FiltersCanBeGrouped', function () { + var scope = createScope({name:'MISKO'}); + assertEquals('misko', scope.$eval('n = (name|lowercase)')); + assertEquals('misko', scope.$eval('n')); + }); + + it('should parse Remainder', function () { + var scope = createScope(); + assertEquals(1, scope.$eval('1%2')); + }); + + it('should parse SumOfUndefinedIsNotUndefined', function () { + var scope = createScope(); + assertEquals(1, scope.$eval('1+undefined')); + assertEquals(1, scope.$eval('undefined+1')); + }); + + it('should parse MissingThrowsError', function(){ + var scope = createScope(); + try { + scope.$eval('[].count('); + fail(); + } catch (e) { + assertEquals('Unexpected end of expression: [].count(', e); + } + }); + + it('should parse DoubleNegationBug', 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]')); + }); + + it('should parse NegationBug', 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")); + }); + + it('should parse BugStringConfusesParser', function(){ + var scope = createScope(); + assertEquals('!', scope.$eval('suffix = "!"')); + }); + + it('should parse ParsingBug', function () { + var scope = createScope(); + assertEquals({a: "-"}, scope.$eval("{a:'-'}")); + }); + + it('should parse Undefined', function () { + var scope = createScope(); + assertEquals(undefined, scope.$eval("undefined")); + assertEquals(undefined, scope.$eval("a=undefined")); + assertEquals(undefined, scope.$get("a")); + }); +}); + + 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")); -}; diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 9b011847..b144a3ce 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -38,7 +38,7 @@ describe("angular.scenario.dsl", function() { var $window; var $root; var application; - + beforeEach(function() { $window = { document: _jQuery("<div></div>"), @@ -55,9 +55,9 @@ describe("angular.scenario.dsl", function() { }; $root.application = new angular.scenario.Application($window.document); $root.application.getWindow = function() { - return $window; + return $window; }; - $root.application.navigateTo = function(url, callback) { + $root.application.navigateTo = function(url, callback) { $window.location = url; callback(); }; @@ -65,7 +65,7 @@ describe("angular.scenario.dsl", function() { $root.addFutureAction = angular.scenario. SpecRunner.prototype.addFutureAction; }); - + describe('Pause', function() { beforeEach(function() { $root.setTimeout = function(fn, value) { @@ -73,14 +73,14 @@ describe("angular.scenario.dsl", function() { fn(); }; }); - + it('should pause for specified seconds', function() { angular.scenario.dsl.pause.call($root).call($root, 10); expect($root.timerValue).toEqual(10000); expect($root.futureResult).toEqual(10000); - }); + }); }); - + describe('Expect', function() { it('should chain and execute matcher', function() { var future = {value: 10}; @@ -88,41 +88,41 @@ describe("angular.scenario.dsl", function() { result.toEqual(10); expect($root.futureError).toBeUndefined(); expect($root.futureResult).toBeUndefined(); - var result = angular.scenario.dsl.expect.call($root).call($root, future); + result = angular.scenario.dsl.expect.call($root).call($root, future); result.toEqual(20); expect($root.futureError).toBeDefined(); }); }); - - describe('NavigateTo', function() { + + describe('NavigateTo', function() { it('should allow a string url', function() { angular.scenario.dsl.navigateTo.call($root).call($root, 'http://myurl'); expect($window.location).toEqual('http://myurl'); expect($root.futureResult).toEqual('http://myurl'); }); - + it('should allow a future url', function() { var future = {name: 'future name', value: 'http://myurl'}; angular.scenario.dsl.navigateTo.call($root).call($root, future); expect($window.location).toEqual('http://myurl'); expect($root.futureResult).toEqual('http://myurl'); }); - + it('should complete if angular is missing from app frame', function() { delete $window.angular; angular.scenario.dsl.navigateTo.call($root).call($root, 'http://myurl'); expect($window.location).toEqual('http://myurl'); expect($root.futureResult).toEqual('http://myurl'); }); - + it('should wait for angular notify when no requests pending', function() { angular.scenario.dsl.navigateTo.call($root).call($root, 'url'); expect($window.angular.log).toContain('$brower.poll()'); - expect($window.angular.log) - .toContain('$brower.notifyWhenNoOutstandingRequests()'); + expect($window.angular.log). + toContain('$brower.notifyWhenNoOutstandingRequests()'); }); }); - + describe('Element Finding', function() { var doc; //TODO(esprehn): Work around a bug in jQuery where attribute selectors @@ -133,14 +133,14 @@ describe("angular.scenario.dsl", function() { // beforeEach(function() { doc = _jQuery('<div id="angular-scenario-binding"></div>'); - _jQuery(document.body).append(doc); + _jQuery(document.body).html('').append(doc); $window.document = window.document; }); - + afterEach(function() { - _jQuery(document.body) - .find('#angular-scenario-binding') - .remove(); + _jQuery(document.body). + find('#angular-scenario-binding'). + remove(); }); describe('Binding', function() { @@ -149,53 +149,53 @@ describe("angular.scenario.dsl", function() { angular.scenario.dsl.binding.call($root).call($root, 'foo.bar'); expect($root.futureResult).toEqual('some value'); }); - + it('should return error if no binding exists', function() { angular.scenario.dsl.binding.call($root).call($root, 'foo.bar'); expect($root.futureError).toMatch(/does not exist/); }); }); - + describe('Input', function() { it('should change value in text input', function() { doc.append('<input name="test.input" value="something">'); - var chain = angular.scenario.dsl.input - .call($root).call($root, 'test.input'); + var chain = angular.scenario.dsl.input. + call($root).call($root, 'test.input'); chain.enter('foo'); expect($window.angular.log).toContain('element(input)'); expect($window.angular.log).toContain('element().trigger(change)'); expect(_jQuery('input[name="test.input"]').val()).toEqual('foo'); }); - + it('should return error if no input exists', function() { - var chain = angular.scenario.dsl.input - .call($root).call($root, 'test.input'); + var chain = angular.scenario.dsl.input. + call($root).call($root, 'test.input'); chain.enter('foo'); expect($root.futureError).toMatch(/does not exist/); }); - + it('should toggle checkbox state', function() { doc.append('<input type="checkbox" name="test.input" checked>'); - expect(_jQuery('input[name="test.input"]') - .attr('checked')).toBeTruthy(); - var chain = angular.scenario.dsl.input - .call($root).call($root, 'test.input'); + expect(_jQuery('input[name="test.input"]'). + attr('checked')).toBeTruthy(); + var chain = angular.scenario.dsl.input. + call($root).call($root, 'test.input'); chain.check(); expect($window.angular.log).toContain('element(input)'); expect($window.angular.log).toContain('element().trigger(click)'); - expect(_jQuery('input[name="test.input"]') - .attr('checked')).toBeFalsy(); + expect(_jQuery('input[name="test.input"]'). + attr('checked')).toBeFalsy(); $window.angular.reset(); chain.check(); expect($window.angular.log).toContain('element(input)'); expect($window.angular.log).toContain('element().trigger(click)'); - expect(_jQuery('input[name="test.input"]') - .attr('checked')).toBeTruthy(); + expect(_jQuery('input[name="test.input"]'). + attr('checked')).toBeTruthy(); }); - + it('should return error if checkbox does not exist', function() { - var chain = angular.scenario.dsl.input - .call($root).call($root, 'test.input'); + var chain = angular.scenario.dsl.input. + call($root).call($root, 'test.input'); chain.check(); expect($root.futureError).toMatch(/does not exist/); }); @@ -203,30 +203,31 @@ describe("angular.scenario.dsl", function() { it('should select option from radio group', function() { doc.append( '<input type="radio" name="0@test.input" value="foo">' + - '<input type="radio" name="0@test.input" value="bar" checked>' - ); - expect(_jQuery('input[name="0@test.input"][value="bar"]') - .attr('checked')).toBeTruthy(); - expect(_jQuery('input[name="0@test.input"][value="foo"]') - .attr('checked')).toBeFalsy(); - var chain = angular.scenario.dsl.input - .call($root).call($root, 'test.input'); + '<input type="radio" name="0@test.input" value="bar" checked="checked">'); + // HACK! We don't know why this is sometimes false on chrome + _jQuery('input[name="0@test.input"][value="bar"]').attr('checked', true); + expect(_jQuery('input[name="0@test.input"][value="bar"]'). + attr('checked')).toBeTruthy(); + expect(_jQuery('input[name="0@test.input"][value="foo"]'). + attr('checked')).toBeFalsy(); + var chain = angular.scenario.dsl.input. + call($root).call($root, 'test.input'); chain.select('foo'); expect($window.angular.log).toContain('element(input)'); expect($window.angular.log).toContain('element().trigger(click)'); - expect(_jQuery('input[name="0@test.input"][value="bar"]') - .attr('checked')).toBeFalsy(); - expect(_jQuery('input[name="0@test.input"][value="foo"]') - .attr('checked')).toBeTruthy(); + expect(_jQuery('input[name="0@test.input"][value="bar"]'). + attr('checked')).toBeFalsy(); + expect(_jQuery('input[name="0@test.input"][value="foo"]'). + attr('checked')).toBeTruthy(); }); - + it('should return error if radio button does not exist', function() { - var chain = angular.scenario.dsl.input - .call($root).call($root, 'test.input'); + var chain = angular.scenario.dsl.input. + call($root).call($root, 'test.input'); chain.select('foo'); expect($root.futureError).toMatch(/does not exist/); }); }); }); - + }); diff --git a/test/scenario/HtmlUISpec.js b/test/scenario/HtmlUISpec.js index b2e2652f..5b800fca 100644 --- a/test/scenario/HtmlUISpec.js +++ b/test/scenario/HtmlUISpec.js @@ -2,7 +2,7 @@ describe('angular.scenario.HtmlUI', function() { var ui; var context; var spec; - + beforeEach(function() { spec = { name: 'test spec', @@ -20,18 +20,18 @@ describe('angular.scenario.HtmlUI', function() { context = _jQuery("<div></div>"); ui = new angular.scenario.ui.Html(context); }); - + it('should create nested describe context', function() { ui.addSpec(spec); - expect(context.find('#describe-20 #describe-10 > h2').text()) - .toEqual('describe: child'); + expect(context.find('#describe-20 #describe-10 > h2').text()). + toEqual('describe: child'); expect(context.find('#describe-20 > h2').text()).toEqual('describe: parent'); - expect(context.find('#describe-10 .tests > li .test-info .test-name').text()) - .toEqual('it test spec'); - expect(context.find('#describe-10 .tests > li').hasClass('status-pending')) - .toBeTruthy(); + expect(context.find('#describe-10 .tests > li .test-info .test-name').text()). + toEqual('it test spec'); + expect(context.find('#describe-10 .tests > li').hasClass('status-pending')). + toBeTruthy(); }); - + it('should update totals when steps complete', function() { // Error ui.addSpec(spec).error('error'); @@ -55,31 +55,31 @@ describe('angular.scenario.HtmlUI', function() { specUI = ui.addSpec(spec); specUI.addStep('some step').finish(); specUI.finish(); - - expect(parseInt(context.find('#status-legend .status-failure').text())) - .toEqual(3); - expect(parseInt(context.find('#status-legend .status-error').text())) - .toEqual(2); - expect(parseInt(context.find('#status-legend .status-success').text())) - .toEqual(1); + + expect(parseInt(context.find('#status-legend .status-failure').text(), 10)). + toEqual(3); + expect(parseInt(context.find('#status-legend .status-error').text(), 10)). + toEqual(2); + expect(parseInt(context.find('#status-legend .status-success').text(), 10)). + toEqual(1); }); - + it('should update timer when test completes', function() { // Success specUI = ui.addSpec(spec); specUI.addStep('some step').finish(); specUI.finish(); - + // Failure specUI = ui.addSpec(spec); specUI.addStep('some step').finish('failure'); specUI.finish('failure'); - + // Error specUI = ui.addSpec(spec).error('error'); - - context.find('#describe-10 .tests > li .test-info .timer-result') - .each(function(index, timer) { + + context.find('#describe-10 .tests > li .test-info .timer-result'). + each(function(index, timer) { expect(timer.innerHTML).toMatch(/ms$/); }); }); diff --git a/test/scenario/SpecRunnerSpec.js b/test/scenario/SpecRunnerSpec.js index 81b66956..0926c3f8 100644 --- a/test/scenario/SpecRunnerSpec.js +++ b/test/scenario/SpecRunnerSpec.js @@ -30,8 +30,8 @@ UIMock.prototype = { log.push('spec error:' + (e ? e : '')); return this; } - }; - }, + }; + } }; /** @@ -56,7 +56,7 @@ describe('angular.scenario.SpecRunner', function() { runner.application = new ApplicationMock($window); runner.$become(angular.scenario.SpecRunner); }); - + it('should bind futures to the spec', function() { runner.addFuture('test future', function(done) { this.application.value = 10; @@ -65,7 +65,7 @@ describe('angular.scenario.SpecRunner', function() { runner.futures[0].execute(angular.noop); expect(runner.application.value).toEqual(10); }); - + it('should pass done to future action behavior', function() { runner.addFutureAction('test future', function(done) { expect(angular.isFunction(done)).toBeTruthy(); @@ -76,7 +76,7 @@ describe('angular.scenario.SpecRunner', function() { expect(result).toEqual(20); }); }); - + it('should pass execute future action on the $window', function() { runner.addFutureAction('test future', function(done) { this.test = 'test value'; @@ -123,7 +123,7 @@ describe('angular.scenario.SpecRunner', function() { 'spec error:message' ]); }); - + it('should execute notify UI on step failure', function() { var finished = false; var ui = new UIMock(); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 47bc0d0d..59d8f4ac 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -32,7 +32,7 @@ beforeEach(function(){ this.message = function(){ return "Expected '" + sortedHtml(this.actual) + "' to have class '" + clazz + "'."; }; - return this.actual.hasClass ? + return this.actual.hasClass ? this.actual.hasClass(clazz) : jqLite(this.actual).hasClass(clazz); } @@ -208,8 +208,8 @@ function click(element) { } } -function rethrow(e) { +function rethrow(e) { if(e) { - throw e; + throw e; } } |
