Skip to content

Commit 18cdab7

Browse files
committed
refactor(parser): clean up tests
1 parent 03c7793 commit 18cdab7

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

modules/change_detection/test/parser/parser_spec.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export function main() {
5959
expectEval("a.a", td(td(999))).toEqual(999);
6060
});
6161

62+
it('should throw when accessing a field on null', () => {
63+
expectEvalError("a.a.a").toThrowError();
64+
});
65+
6266
it('should parse numerical expressions', () => {
6367
expectEval("1").toEqual(1);
6468
});
@@ -107,6 +111,11 @@ export function main() {
107111
expectEval("false?10:20").toEqual(20);
108112
});
109113

114+
it('should throw on incorrect ternary operator syntax', () => {
115+
expectEvalError("true?1").
116+
toThrowError(new RegExp('Parser Error: Conditional expression true\\?1 requires all 3 expressions'));
117+
});
118+
110119
it('should auto convert ints to strings', () => {
111120
expectEval("'str ' + 4").toEqual("str 4");
112121
expectEval("4 + ' str'").toEqual("4 str");
@@ -115,11 +124,6 @@ export function main() {
115124
expectEval("'str ' + 4 + 4").toEqual("str 44");
116125
});
117126

118-
it('should behave gracefully with a null scope', () => {
119-
var exp = createParser().parseAction("null");
120-
expect(exp.eval(null)).toEqual(null);
121-
});
122-
123127
it('should eval binary operators with null as null', () => {
124128
expectEvalError("null < 0").toThrowError();
125129
expectEvalError("null * 3").toThrowError();
@@ -131,27 +135,20 @@ export function main() {
131135
expectEvalError("null - null").toThrowError();
132136
});
133137

134-
describe("error handling", () => {
135-
it('should throw on incorrect ternary operator syntax', () => {
136-
expectEvalError("true?1").
137-
toThrowError(new RegExp('Parser Error: Conditional expression true\\?1 requires all 3 expressions'));
138-
});
139-
140-
it('should pass exceptions', () => {
141-
expect(() => {
142-
createParser().parseAction('boo').eval(new ContextWithErrors());
143-
}).toThrowError('boo to you');
144-
});
138+
it('should only allow identifier or keyword as member names', () => {
139+
expect(() => parseAction("x.(")).toThrowError(new RegExp('identifier or keyword'));
140+
expect(() => parseAction('x. 1234')).toThrowError(new RegExp('identifier or keyword'));
141+
expect(() => parseAction('x."foo"')).toThrowError(new RegExp('identifier or keyword'));
142+
});
145143

146-
it('should only allow identifier or keyword as member names', () => {
147-
expect(() => parseAction("x.(")).toThrowError(new RegExp('identifier or keyword'));
148-
expect(() => parseAction('x. 1234')).toThrowError(new RegExp('identifier or keyword'));
149-
expect(() => parseAction('x."foo"')).toThrowError(new RegExp('identifier or keyword'));
150-
});
144+
it("should error when using formatters", () => {
145+
expectEvalError('x|blah').toThrowError(new RegExp('Cannot have a formatter'));
146+
});
151147

152-
it("should error when using formatters", () => {
153-
expectEvalError('x|blah').toThrowError(new RegExp('Cannot have a formatter'));
154-
});
148+
it('should pass exceptions', () => {
149+
expect(() => {
150+
createParser().parseAction('boo').eval(new ContextWithErrors());
151+
}).toThrowError('boo to you');
155152
});
156153
});
157154

0 commit comments

Comments
 (0)