From 18cdab7450d1877af889358125d13b3b377299c0 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 4 Nov 2014 16:08:01 -0800 Subject: [PATCH] refactor(parser): clean up tests --- .../test/parser/parser_spec.js | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/modules/change_detection/test/parser/parser_spec.js b/modules/change_detection/test/parser/parser_spec.js index bdb1856a60..c7273f1f58 100644 --- a/modules/change_detection/test/parser/parser_spec.js +++ b/modules/change_detection/test/parser/parser_spec.js @@ -59,6 +59,10 @@ export function main() { expectEval("a.a", td(td(999))).toEqual(999); }); + it('should throw when accessing a field on null', () => { + expectEvalError("a.a.a").toThrowError(); + }); + it('should parse numerical expressions', () => { expectEval("1").toEqual(1); }); @@ -107,6 +111,11 @@ export function main() { expectEval("false?10:20").toEqual(20); }); + it('should throw on incorrect ternary operator syntax', () => { + expectEvalError("true?1"). + toThrowError(new RegExp('Parser Error: Conditional expression true\\?1 requires all 3 expressions')); + }); + it('should auto convert ints to strings', () => { expectEval("'str ' + 4").toEqual("str 4"); expectEval("4 + ' str'").toEqual("4 str"); @@ -115,11 +124,6 @@ export function main() { expectEval("'str ' + 4 + 4").toEqual("str 44"); }); - it('should behave gracefully with a null scope', () => { - var exp = createParser().parseAction("null"); - expect(exp.eval(null)).toEqual(null); - }); - it('should eval binary operators with null as null', () => { expectEvalError("null < 0").toThrowError(); expectEvalError("null * 3").toThrowError(); @@ -131,27 +135,20 @@ export function main() { expectEvalError("null - null").toThrowError(); }); - describe("error handling", () => { - it('should throw on incorrect ternary operator syntax', () => { - expectEvalError("true?1"). - toThrowError(new RegExp('Parser Error: Conditional expression true\\?1 requires all 3 expressions')); - }); + it('should only allow identifier or keyword as member names', () => { + expect(() => parseAction("x.(")).toThrowError(new RegExp('identifier or keyword')); + expect(() => parseAction('x. 1234')).toThrowError(new RegExp('identifier or keyword')); + expect(() => parseAction('x."foo"')).toThrowError(new RegExp('identifier or keyword')); + }); - it('should pass exceptions', () => { - expect(() => { - createParser().parseAction('boo').eval(new ContextWithErrors()); - }).toThrowError('boo to you'); - }); + it("should error when using formatters", () => { + expectEvalError('x|blah').toThrowError(new RegExp('Cannot have a formatter')); + }); - it('should only allow identifier or keyword as member names', () => { - expect(() => parseAction("x.(")).toThrowError(new RegExp('identifier or keyword')); - expect(() => parseAction('x. 1234')).toThrowError(new RegExp('identifier or keyword')); - expect(() => parseAction('x."foo"')).toThrowError(new RegExp('identifier or keyword')); - }); - - it("should error when using formatters", () => { - expectEvalError('x|blah').toThrowError(new RegExp('Cannot have a formatter')); - }); + it('should pass exceptions', () => { + expect(() => { + createParser().parseAction('boo').eval(new ContextWithErrors()); + }).toThrowError('boo to you'); }); });