refactor(parser): clean up tests
This commit is contained in:
parent
03c779321f
commit
18cdab7450
|
@ -59,6 +59,10 @@ export function main() {
|
||||||
expectEval("a.a", td(td(999))).toEqual(999);
|
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', () => {
|
it('should parse numerical expressions', () => {
|
||||||
expectEval("1").toEqual(1);
|
expectEval("1").toEqual(1);
|
||||||
});
|
});
|
||||||
|
@ -107,6 +111,11 @@ export function main() {
|
||||||
expectEval("false?10:20").toEqual(20);
|
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', () => {
|
it('should auto convert ints to strings', () => {
|
||||||
expectEval("'str ' + 4").toEqual("str 4");
|
expectEval("'str ' + 4").toEqual("str 4");
|
||||||
expectEval("4 + ' str'").toEqual("4 str");
|
expectEval("4 + ' str'").toEqual("4 str");
|
||||||
|
@ -115,11 +124,6 @@ export function main() {
|
||||||
expectEval("'str ' + 4 + 4").toEqual("str 44");
|
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', () => {
|
it('should eval binary operators with null as null', () => {
|
||||||
expectEvalError("null < 0").toThrowError();
|
expectEvalError("null < 0").toThrowError();
|
||||||
expectEvalError("null * 3").toThrowError();
|
expectEvalError("null * 3").toThrowError();
|
||||||
|
@ -131,27 +135,20 @@ export function main() {
|
||||||
expectEvalError("null - null").toThrowError();
|
expectEvalError("null - null").toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("error handling", () => {
|
it('should only allow identifier or keyword as member names', () => {
|
||||||
it('should throw on incorrect ternary operator syntax', () => {
|
expect(() => parseAction("x.(")).toThrowError(new RegExp('identifier or keyword'));
|
||||||
expectEvalError("true?1").
|
expect(() => parseAction('x. 1234')).toThrowError(new RegExp('identifier or keyword'));
|
||||||
toThrowError(new RegExp('Parser Error: Conditional expression true\\?1 requires all 3 expressions'));
|
expect(() => parseAction('x."foo"')).toThrowError(new RegExp('identifier or keyword'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pass exceptions', () => {
|
it("should error when using formatters", () => {
|
||||||
expect(() => {
|
expectEvalError('x|blah').toThrowError(new RegExp('Cannot have a formatter'));
|
||||||
createParser().parseAction('boo').eval(new ContextWithErrors());
|
});
|
||||||
}).toThrowError('boo to you');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should only allow identifier or keyword as member names', () => {
|
it('should pass exceptions', () => {
|
||||||
expect(() => parseAction("x.(")).toThrowError(new RegExp('identifier or keyword'));
|
expect(() => {
|
||||||
expect(() => parseAction('x. 1234')).toThrowError(new RegExp('identifier or keyword'));
|
createParser().parseAction('boo').eval(new ContextWithErrors());
|
||||||
expect(() => parseAction('x."foo"')).toThrowError(new RegExp('identifier or keyword'));
|
}).toThrowError('boo to you');
|
||||||
});
|
|
||||||
|
|
||||||
it("should error when using formatters", () => {
|
|
||||||
expectEvalError('x|blah').toThrowError(new RegExp('Cannot have a formatter'));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue