/* tslint:disable:no-unused-expression */ import { expect } from "chai"; import * as AST from "../src/ast"; import { isError } from "../src/error"; import Lexer from "../src/lexer"; import Parser from "../src/parser"; const parse = (source: string): AST.Statement[] => { const tokens = new Lexer(source).scan(); if (isError(tokens)) { throw tokens.message; } else { const tree = new Parser(tokens).parse(); if (isError(tree)) { throw tree.message; } return tree; } }; describe("Parser", () => { it("should parse a number selection", () => { const tree = parse("select 5"); expect(tree).to.deep.equal([ new AST.SelectStatement({ arguments: [new AST.Number(5)], }), ]); }); it("should parse a multiple number selection", () => { const tree = parse("select 5, 6"); expect(tree).to.deep.equal([ new AST.SelectStatement({ arguments: [ new AST.Number(5), new AST.Number(6), ], }), ]); }); it("should parse a selection of identifiers", () => { const tree = parse("select a, b"); expect(tree).to.deep.equal([ new AST.SelectStatement({ arguments: [ new AST.Identifier("a"), new AST.Identifier("b"), ], }), ]); }); it("should parse a selection of identifiers and numbers", () => { const tree = parse("select a, 5"); expect(tree).to.deep.equal([ new AST.SelectStatement({ arguments: [ new AST.Identifier("a"), new AST.Number(5), ], }), ]); }); it("should parse the from of a selection", () => { const tree = parse("select a from t"); expect(tree).to.deep.equal([ new AST.SelectStatement({ arguments: [ new AST.Identifier("a"), ], from: new AST.Identifier("t"), }), ]); }); });