Best JavaScript code snippet using taiko
ParserTest.ts
Source:ParserTest.ts
1import { expect } from "chai";2import { Expr } from "../CodeAnalysis/Syntax/Expression";3import { Parser } from "../CodeAnalysis/Syntax/Parser";4import { Stmt } from "../CodeAnalysis/Syntax/Statement";5import { SyntaxType as Syntax } from "../CodeAnalysis/Syntax/SyntaxType";6describe("Parser", () => {7 describe("Binary operator test", () => {8 (() => {9 const parser = new Parser("true & false;");10 const statements: Stmt.Statement[] = parser.Parse();11 const binaryExprStatement = statements[0] as Stmt.Expression;12 const binaryExpression = binaryExprStatement.Expression as Expr.Logical;13 it("should produce a logical expression", () => {14 expect(binaryExpression).to.not.be.an("undefined");15 expect(binaryExpression).to.have.property("Left");16 expect(binaryExpression).to.have.property("Right");17 expect(binaryExpression).to.have.property("Operator");18 });19 it("should have the left evaluate to true and right to false", () => {20 expect(binaryExpression.Left).to.not.be.an("undefined");21 expect(binaryExpression.Right).to.not.be.an("undefined");22 expect(binaryExpression.Left as Expr.Literal).to.have.property("Value");23 expect(binaryExpression.Right as Expr.Literal).to.have.property("Value");24 expect((binaryExpression.Left as Expr.Literal).Value).to.equal(true);25 expect((binaryExpression.Right as Expr.Literal).Value).to.equal(false);26 })27 it("should have a & operator token", () => {28 expect(binaryExpression.Operator).to.not.be.an("undefined");29 expect(binaryExpression.Operator).to.have.property("Type");30 expect(binaryExpression.Operator).to.have.property("Lexeme");31 expect(binaryExpression.Operator).to.have.property("Line");32 expect(binaryExpression.Operator).to.have.property("Literal");33 expect(binaryExpression.Operator.Type).to.equal(Syntax.AND)34 });35 })();36 (() => {37 const parser = new Parser("false | true;");38 const statements: Stmt.Statement[] = parser.Parse();39 const binaryExprStatement = statements[0] as Stmt.Expression;40 const binaryExpression = binaryExprStatement.Expression as Expr.Logical;41 it("should produce a logical expression", () => {42 expect(binaryExpression).to.not.be.an("undefined");43 expect(binaryExpression).to.have.property("Left");44 expect(binaryExpression).to.have.property("Right");45 expect(binaryExpression).to.have.property("Operator");46 });47 it("should have the left evaluate to false and right to true", () => {48 expect(binaryExpression.Left).to.not.be.an("undefined");49 expect(binaryExpression.Right).to.not.be.an("undefined");50 expect(binaryExpression.Left as Expr.Literal).to.have.property("Value");51 expect(binaryExpression.Right as Expr.Literal).to.have.property("Value");52 expect((binaryExpression.Left as Expr.Literal).Value).to.equal(false);53 expect((binaryExpression.Right as Expr.Literal).Value).to.equal(true);54 })55 it("should have a | operator token", () => {56 expect(binaryExpression.Operator).to.not.be.an("undefined");57 expect(binaryExpression.Operator).to.have.property("Type");58 expect(binaryExpression.Operator).to.have.property("Lexeme");59 expect(binaryExpression.Operator).to.have.property("Line");60 expect(binaryExpression.Operator).to.have.property("Literal");61 expect(binaryExpression.Operator.Type).to.equal(Syntax.OR)62 });63 })();64 (() => {65 const parser = new Parser("2 + 4;");66 const statements: Stmt.Statement[] = parser.Parse();67 const binaryExprStatement = statements[0] as Stmt.Expression;68 const binaryExpression = binaryExprStatement.Expression as Expr.Binary;69 it("should produce a binary expression", () => {70 expect(binaryExpression).to.not.be.an("undefined");71 expect(binaryExpression).to.have.property("Left");72 expect(binaryExpression).to.have.property("Right");73 expect(binaryExpression).to.have.property("Operator");74 });75 it("should have the left evaluate to 2 and right to 4", () => {76 expect(binaryExpression.Left).to.not.be.an("undefined");77 expect(binaryExpression.Right).to.not.be.an("undefined");78 expect(binaryExpression.Left as Expr.Literal).to.have.property("Value");79 expect(binaryExpression.Right as Expr.Literal).to.have.property("Value");80 expect((binaryExpression.Left as Expr.Literal).Value).to.equal(2);81 expect((binaryExpression.Right as Expr.Literal).Value).to.equal(4);82 })83 it("should have a + operator token", () => {84 expect(binaryExpression.Operator).to.not.be.an("undefined");85 expect(binaryExpression.Operator).to.have.property("Type");86 expect(binaryExpression.Operator).to.have.property("Lexeme");87 expect(binaryExpression.Operator).to.have.property("Line");88 expect(binaryExpression.Operator).to.have.property("Literal");89 expect(binaryExpression.Operator.Type).to.equal(Syntax.PLUS)90 });91 })();92 (() => {93 const parser = new Parser("6 - 3 * 2;");94 const statements: Stmt.Statement[] = parser.Parse();95 const binaryExprStatement = statements[0] as Stmt.Expression;96 const binaryExpression = binaryExprStatement.Expression as Expr.Binary;97 it("should produce a binary expression", () => {98 expect(binaryExpression).to.not.be.an("undefined");99 expect(binaryExpression).to.have.property("Left");100 expect(binaryExpression).to.have.property("Right");101 expect(binaryExpression).to.have.property("Operator");102 });103 it("should have the left evaluate to 6 and right to binary(3 * 2)", () => {104 expect(binaryExpression.Left).to.not.be.an("undefined");105 expect(binaryExpression.Right).to.not.be.an("undefined");106 expect(binaryExpression.Left as Expr.Literal).to.have.property("Value");107 expect(binaryExpression.Right as Expr.Binary).to.have.property("Left");108 expect(binaryExpression.Right as Expr.Binary).to.have.property("Right");109 expect(binaryExpression.Right as Expr.Binary).to.have.property("Operator");110 expect((binaryExpression.Left as Expr.Literal).Value).to.equal(6);111 expect(((binaryExpression.Right as Expr.Binary).Left as Expr.Literal).Value).to.equal(3);112 expect(((binaryExpression.Right as Expr.Binary).Right as Expr.Literal).Value).to.equal(2);113 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Type");114 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Lexeme");115 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Line");116 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Literal");117 expect((binaryExpression.Right as Expr.Binary).Operator.Type).to.equal(Syntax.STAR);118 })119 it("should have a - operator token", () => {120 expect(binaryExpression.Operator).to.not.be.an("undefined");121 expect(binaryExpression.Operator).to.have.property("Type");122 expect(binaryExpression.Operator).to.have.property("Lexeme");123 expect(binaryExpression.Operator).to.have.property("Line");124 expect(binaryExpression.Operator).to.have.property("Literal");125 expect(binaryExpression.Operator.Type).to.equal(Syntax.MINUS)126 });127 })();128 (() => {129 const parser = new Parser("4 % 2 ^ 2;");130 const statements: Stmt.Statement[] = parser.Parse();131 const binaryExprStatement = statements[0] as Stmt.Expression;132 const binaryExpression = binaryExprStatement.Expression as Expr.Binary;133 it("should produce a binary expression", () => {134 expect(binaryExpression).to.not.be.an("undefined");135 expect(binaryExpression).to.have.property("Left");136 expect(binaryExpression).to.have.property("Right");137 expect(binaryExpression).to.have.property("Operator");138 });139 it("should have the left evaluate to 4 and right to binary(2 ^ 2)", () => {140 expect(binaryExpression.Left).to.not.be.an("undefined");141 expect(binaryExpression.Right).to.not.be.an("undefined");142 expect(binaryExpression.Left as Expr.Literal).to.have.property("Value");143 expect(binaryExpression.Right as Expr.Binary).to.have.property("Left");144 expect(binaryExpression.Right as Expr.Binary).to.have.property("Right");145 expect(binaryExpression.Right as Expr.Binary).to.have.property("Operator");146 expect((binaryExpression.Left as Expr.Literal).Value).to.equal(4);147 expect(((binaryExpression.Right as Expr.Binary).Left as Expr.Literal).Value).to.equal(2);148 expect(((binaryExpression.Right as Expr.Binary).Right as Expr.Literal).Value).to.equal(2);149 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Type");150 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Lexeme");151 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Line");152 expect((binaryExpression.Right as Expr.Binary).Operator).to.have.property("Literal");153 expect((binaryExpression.Right as Expr.Binary).Operator.Type).to.equal(Syntax.CARAT);154 })155 it("should have a % operator token", () => {156 expect(binaryExpression.Operator).to.not.be.an("undefined");157 expect(binaryExpression.Operator).to.have.property("Type");158 expect(binaryExpression.Operator).to.have.property("Lexeme");159 expect(binaryExpression.Operator).to.have.property("Line");160 expect(binaryExpression.Operator).to.have.property("Literal");161 expect(binaryExpression.Operator.Type).to.equal(Syntax.PERCENT)162 });163 })();164 });165 describe("Unary operator test", () => {166 (() => {167 const parser = new Parser("!true;");168 const statements: Stmt.Statement[] = parser.Parse();169 const unaryExprStatement = statements[0] as Stmt.Expression;170 const unaryExpression = unaryExprStatement.Expression as Expr.Unary;171 it("should produce a unary expression", () => {172 expect(unaryExpression).to.not.be.an("undefined");173 expect(unaryExpression).to.have.property("Right");174 expect(unaryExpression).to.have.property("Operator");175 });176 it("should have the operand evaluate to true", () => {177 expect(unaryExpression.Right).to.not.be.an("undefined");178 expect(unaryExpression.Right as Expr.Literal).to.have.property("Value");179 expect((unaryExpression.Right as Expr.Literal).Value).to.equal(true);180 })181 it("should have a ! operator token", () => {182 expect(unaryExpression.Operator).to.not.be.an("undefined");183 expect(unaryExpression.Operator).to.have.property("Type");184 expect(unaryExpression.Operator).to.have.property("Lexeme");185 expect(unaryExpression.Operator).to.have.property("Line");186 expect(unaryExpression.Operator).to.have.property("Literal");187 expect(unaryExpression.Operator.Type).to.equal(Syntax.BANG)188 });189 })();190 (() => {191 const parser = new Parser("-42;");192 const statements: Stmt.Statement[] = parser.Parse();193 const unaryExprStatement = statements[0] as Stmt.Expression;194 const unaryExpression = unaryExprStatement.Expression as Expr.Unary;195 it("should produce a unary expression", () => {196 expect(unaryExpression).to.not.be.an("undefined");197 expect(unaryExpression).to.have.property("Right");198 expect(unaryExpression).to.have.property("Operator");199 });200 it("should have the operand evaluate to 42", () => {201 expect(unaryExpression.Right).to.not.be.an("undefined");202 expect(unaryExpression.Right as Expr.Literal).to.have.property("Value");203 expect((unaryExpression.Right as Expr.Literal).Value).to.equal(42);204 })205 it("should have a - operator token", () => {206 expect(unaryExpression.Operator).to.not.be.an("undefined");207 expect(unaryExpression.Operator).to.have.property("Type");208 expect(unaryExpression.Operator).to.have.property("Lexeme");209 expect(unaryExpression.Operator).to.have.property("Line");210 expect(unaryExpression.Operator).to.have.property("Literal");211 expect(unaryExpression.Operator.Type).to.equal(Syntax.MINUS)212 });213 })();214 (() => {215 const parser = new Parser("+76;");216 const statements: Stmt.Statement[] = parser.Parse();217 const unaryExprStatement = statements[0] as Stmt.Expression;218 const unaryExpression = unaryExprStatement.Expression as Expr.Unary;219 it("should produce a unary expression", () => {220 expect(unaryExpression).to.not.be.an("undefined");221 expect(unaryExpression).to.have.property("Right");222 expect(unaryExpression).to.have.property("Operator");223 });224 it("should have the operand evaluate to 76", () => {225 expect(unaryExpression.Right).to.not.be.an("undefined");226 expect(unaryExpression.Right as Expr.Literal).to.have.property("Value");227 expect((unaryExpression.Right as Expr.Literal).Value).to.equal(76);228 })229 it("should have a + operator token", () => {230 expect(unaryExpression.Operator).to.not.be.an("undefined");231 expect(unaryExpression.Operator).to.have.property("Type");232 expect(unaryExpression.Operator).to.have.property("Lexeme");233 expect(unaryExpression.Operator).to.have.property("Line");234 expect(unaryExpression.Operator).to.have.property("Literal");235 expect(unaryExpression.Operator.Type).to.equal(Syntax.PLUS)236 });237 })();238 });239 describe("Error reporting test", () => {240 (() => {241 const parser = new Parser("print 5"); // Missing semicolon242 it("should raise an expected ';' error", () =>243 expect(parser.Parse).to.throw()244 );245 })();246 (() => {247 const parser = new Parser("raise 'Raised error';");248 it("should raise a 'Raised error' error", () =>249 expect(parser.Parse).to.throw()250 );251 })();252 (() => {253 const parser = new Parser("if (true)");254 it("should raise an expected '{' error", () =>255 expect(parser.Parse).to.throw()256 );257 })();258 (() => {259 const parser = new Parser("-false;");260 it("should raise a runtime error", () =>261 expect(parser.Parse).to.throw()262 );263 })();264 (() => {265 const parser = new Parser("return;");266 it("should raise a runtime error", () =>267 expect(parser.Parse).to.throw()268 );269 })();270 (() => {271 const parser = new Parser("method hello(name) { print 'hello ' + name ");272 it("should raise an expected '}' error", () =>273 expect(parser.Parse).to.throw()274 );275 })();276 (() => {277 const parser = new Parser("for (let i; i < 2) {}");278 it("should raise an expected ';' error", () =>279 expect(parser.Parse).to.throw()280 );281 })();282 });...
ParserTest.js
Source:ParserTest.js
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3const chai_1 = require("chai");4const Parser_1 = require("../CodeAnalysis/Syntax/Parser");5const SyntaxType_1 = require("../CodeAnalysis/Syntax/SyntaxType");6describe("Parser", () => {7 describe("Binary operator test", () => {8 (() => {9 const parser = new Parser_1.Parser("true & false;");10 const statements = parser.Parse();11 const binaryExprStatement = statements[0];12 const binaryExpression = binaryExprStatement.Expression;13 it("should produce a logical expression", () => {14 chai_1.expect(binaryExpression).to.not.be.an("undefined");15 chai_1.expect(binaryExpression).to.have.property("Left");16 chai_1.expect(binaryExpression).to.have.property("Right");17 chai_1.expect(binaryExpression).to.have.property("Operator");18 });19 it("should have the left evaluate to true and right to false", () => {20 chai_1.expect(binaryExpression.Left).to.not.be.an("undefined");21 chai_1.expect(binaryExpression.Right).to.not.be.an("undefined");22 chai_1.expect(binaryExpression.Left).to.have.property("Value");23 chai_1.expect(binaryExpression.Right).to.have.property("Value");24 chai_1.expect(binaryExpression.Left.Value).to.equal(true);25 chai_1.expect(binaryExpression.Right.Value).to.equal(false);26 });27 it("should have a & operator token", () => {28 chai_1.expect(binaryExpression.Operator).to.not.be.an("undefined");29 chai_1.expect(binaryExpression.Operator).to.have.property("Type");30 chai_1.expect(binaryExpression.Operator).to.have.property("Lexeme");31 chai_1.expect(binaryExpression.Operator).to.have.property("Line");32 chai_1.expect(binaryExpression.Operator).to.have.property("Literal");33 chai_1.expect(binaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.AND);34 });35 })();36 (() => {37 const parser = new Parser_1.Parser("false | true;");38 const statements = parser.Parse();39 const binaryExprStatement = statements[0];40 const binaryExpression = binaryExprStatement.Expression;41 it("should produce a logical expression", () => {42 chai_1.expect(binaryExpression).to.not.be.an("undefined");43 chai_1.expect(binaryExpression).to.have.property("Left");44 chai_1.expect(binaryExpression).to.have.property("Right");45 chai_1.expect(binaryExpression).to.have.property("Operator");46 });47 it("should have the left evaluate to false and right to true", () => {48 chai_1.expect(binaryExpression.Left).to.not.be.an("undefined");49 chai_1.expect(binaryExpression.Right).to.not.be.an("undefined");50 chai_1.expect(binaryExpression.Left).to.have.property("Value");51 chai_1.expect(binaryExpression.Right).to.have.property("Value");52 chai_1.expect(binaryExpression.Left.Value).to.equal(false);53 chai_1.expect(binaryExpression.Right.Value).to.equal(true);54 });55 it("should have a | operator token", () => {56 chai_1.expect(binaryExpression.Operator).to.not.be.an("undefined");57 chai_1.expect(binaryExpression.Operator).to.have.property("Type");58 chai_1.expect(binaryExpression.Operator).to.have.property("Lexeme");59 chai_1.expect(binaryExpression.Operator).to.have.property("Line");60 chai_1.expect(binaryExpression.Operator).to.have.property("Literal");61 chai_1.expect(binaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.OR);62 });63 })();64 (() => {65 const parser = new Parser_1.Parser("2 + 4;");66 const statements = parser.Parse();67 const binaryExprStatement = statements[0];68 const binaryExpression = binaryExprStatement.Expression;69 it("should produce a binary expression", () => {70 chai_1.expect(binaryExpression).to.not.be.an("undefined");71 chai_1.expect(binaryExpression).to.have.property("Left");72 chai_1.expect(binaryExpression).to.have.property("Right");73 chai_1.expect(binaryExpression).to.have.property("Operator");74 });75 it("should have the left evaluate to 2 and right to 4", () => {76 chai_1.expect(binaryExpression.Left).to.not.be.an("undefined");77 chai_1.expect(binaryExpression.Right).to.not.be.an("undefined");78 chai_1.expect(binaryExpression.Left).to.have.property("Value");79 chai_1.expect(binaryExpression.Right).to.have.property("Value");80 chai_1.expect(binaryExpression.Left.Value).to.equal(2);81 chai_1.expect(binaryExpression.Right.Value).to.equal(4);82 });83 it("should have a + operator token", () => {84 chai_1.expect(binaryExpression.Operator).to.not.be.an("undefined");85 chai_1.expect(binaryExpression.Operator).to.have.property("Type");86 chai_1.expect(binaryExpression.Operator).to.have.property("Lexeme");87 chai_1.expect(binaryExpression.Operator).to.have.property("Line");88 chai_1.expect(binaryExpression.Operator).to.have.property("Literal");89 chai_1.expect(binaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.PLUS);90 });91 })();92 (() => {93 const parser = new Parser_1.Parser("6 - 3 * 2;");94 const statements = parser.Parse();95 const binaryExprStatement = statements[0];96 const binaryExpression = binaryExprStatement.Expression;97 it("should produce a binary expression", () => {98 chai_1.expect(binaryExpression).to.not.be.an("undefined");99 chai_1.expect(binaryExpression).to.have.property("Left");100 chai_1.expect(binaryExpression).to.have.property("Right");101 chai_1.expect(binaryExpression).to.have.property("Operator");102 });103 it("should have the left evaluate to 6 and right to binary(3 * 2)", () => {104 chai_1.expect(binaryExpression.Left).to.not.be.an("undefined");105 chai_1.expect(binaryExpression.Right).to.not.be.an("undefined");106 chai_1.expect(binaryExpression.Left).to.have.property("Value");107 chai_1.expect(binaryExpression.Right).to.have.property("Left");108 chai_1.expect(binaryExpression.Right).to.have.property("Right");109 chai_1.expect(binaryExpression.Right).to.have.property("Operator");110 chai_1.expect(binaryExpression.Left.Value).to.equal(6);111 chai_1.expect(binaryExpression.Right.Left.Value).to.equal(3);112 chai_1.expect(binaryExpression.Right.Right.Value).to.equal(2);113 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Type");114 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Lexeme");115 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Line");116 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Literal");117 chai_1.expect(binaryExpression.Right.Operator.Type).to.equal(SyntaxType_1.SyntaxType.STAR);118 });119 it("should have a - operator token", () => {120 chai_1.expect(binaryExpression.Operator).to.not.be.an("undefined");121 chai_1.expect(binaryExpression.Operator).to.have.property("Type");122 chai_1.expect(binaryExpression.Operator).to.have.property("Lexeme");123 chai_1.expect(binaryExpression.Operator).to.have.property("Line");124 chai_1.expect(binaryExpression.Operator).to.have.property("Literal");125 chai_1.expect(binaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.MINUS);126 });127 })();128 (() => {129 const parser = new Parser_1.Parser("4 % 2 ^ 2;");130 const statements = parser.Parse();131 const binaryExprStatement = statements[0];132 const binaryExpression = binaryExprStatement.Expression;133 it("should produce a binary expression", () => {134 chai_1.expect(binaryExpression).to.not.be.an("undefined");135 chai_1.expect(binaryExpression).to.have.property("Left");136 chai_1.expect(binaryExpression).to.have.property("Right");137 chai_1.expect(binaryExpression).to.have.property("Operator");138 });139 it("should have the left evaluate to 4 and right to binary(2 ^ 2)", () => {140 chai_1.expect(binaryExpression.Left).to.not.be.an("undefined");141 chai_1.expect(binaryExpression.Right).to.not.be.an("undefined");142 chai_1.expect(binaryExpression.Left).to.have.property("Value");143 chai_1.expect(binaryExpression.Right).to.have.property("Left");144 chai_1.expect(binaryExpression.Right).to.have.property("Right");145 chai_1.expect(binaryExpression.Right).to.have.property("Operator");146 chai_1.expect(binaryExpression.Left.Value).to.equal(4);147 chai_1.expect(binaryExpression.Right.Left.Value).to.equal(2);148 chai_1.expect(binaryExpression.Right.Right.Value).to.equal(2);149 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Type");150 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Lexeme");151 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Line");152 chai_1.expect(binaryExpression.Right.Operator).to.have.property("Literal");153 chai_1.expect(binaryExpression.Right.Operator.Type).to.equal(SyntaxType_1.SyntaxType.CARAT);154 });155 it("should have a % operator token", () => {156 chai_1.expect(binaryExpression.Operator).to.not.be.an("undefined");157 chai_1.expect(binaryExpression.Operator).to.have.property("Type");158 chai_1.expect(binaryExpression.Operator).to.have.property("Lexeme");159 chai_1.expect(binaryExpression.Operator).to.have.property("Line");160 chai_1.expect(binaryExpression.Operator).to.have.property("Literal");161 chai_1.expect(binaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.PERCENT);162 });163 })();164 });165 describe("Unary operator test", () => {166 (() => {167 const parser = new Parser_1.Parser("!true;");168 const statements = parser.Parse();169 const unaryExprStatement = statements[0];170 const unaryExpression = unaryExprStatement.Expression;171 it("should produce a unary expression", () => {172 chai_1.expect(unaryExpression).to.not.be.an("undefined");173 chai_1.expect(unaryExpression).to.have.property("Right");174 chai_1.expect(unaryExpression).to.have.property("Operator");175 });176 it("should have the operand evaluate to true", () => {177 chai_1.expect(unaryExpression.Right).to.not.be.an("undefined");178 chai_1.expect(unaryExpression.Right).to.have.property("Value");179 chai_1.expect(unaryExpression.Right.Value).to.equal(true);180 });181 it("should have a ! operator token", () => {182 chai_1.expect(unaryExpression.Operator).to.not.be.an("undefined");183 chai_1.expect(unaryExpression.Operator).to.have.property("Type");184 chai_1.expect(unaryExpression.Operator).to.have.property("Lexeme");185 chai_1.expect(unaryExpression.Operator).to.have.property("Line");186 chai_1.expect(unaryExpression.Operator).to.have.property("Literal");187 chai_1.expect(unaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.BANG);188 });189 })();190 (() => {191 const parser = new Parser_1.Parser("-42;");192 const statements = parser.Parse();193 const unaryExprStatement = statements[0];194 const unaryExpression = unaryExprStatement.Expression;195 it("should produce a unary expression", () => {196 chai_1.expect(unaryExpression).to.not.be.an("undefined");197 chai_1.expect(unaryExpression).to.have.property("Right");198 chai_1.expect(unaryExpression).to.have.property("Operator");199 });200 it("should have the operand evaluate to 42", () => {201 chai_1.expect(unaryExpression.Right).to.not.be.an("undefined");202 chai_1.expect(unaryExpression.Right).to.have.property("Value");203 chai_1.expect(unaryExpression.Right.Value).to.equal(42);204 });205 it("should have a - operator token", () => {206 chai_1.expect(unaryExpression.Operator).to.not.be.an("undefined");207 chai_1.expect(unaryExpression.Operator).to.have.property("Type");208 chai_1.expect(unaryExpression.Operator).to.have.property("Lexeme");209 chai_1.expect(unaryExpression.Operator).to.have.property("Line");210 chai_1.expect(unaryExpression.Operator).to.have.property("Literal");211 chai_1.expect(unaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.MINUS);212 });213 })();214 (() => {215 const parser = new Parser_1.Parser("+76;");216 const statements = parser.Parse();217 const unaryExprStatement = statements[0];218 const unaryExpression = unaryExprStatement.Expression;219 it("should produce a unary expression", () => {220 chai_1.expect(unaryExpression).to.not.be.an("undefined");221 chai_1.expect(unaryExpression).to.have.property("Right");222 chai_1.expect(unaryExpression).to.have.property("Operator");223 });224 it("should have the operand evaluate to 76", () => {225 chai_1.expect(unaryExpression.Right).to.not.be.an("undefined");226 chai_1.expect(unaryExpression.Right).to.have.property("Value");227 chai_1.expect(unaryExpression.Right.Value).to.equal(76);228 });229 it("should have a + operator token", () => {230 chai_1.expect(unaryExpression.Operator).to.not.be.an("undefined");231 chai_1.expect(unaryExpression.Operator).to.have.property("Type");232 chai_1.expect(unaryExpression.Operator).to.have.property("Lexeme");233 chai_1.expect(unaryExpression.Operator).to.have.property("Line");234 chai_1.expect(unaryExpression.Operator).to.have.property("Literal");235 chai_1.expect(unaryExpression.Operator.Type).to.equal(SyntaxType_1.SyntaxType.PLUS);236 });237 })();238 });239 describe("Error reporting test", () => {240 (() => {241 const parser = new Parser_1.Parser("print 5"); // Missing semicolon242 it("should raise an expected ';' error", () => chai_1.expect(parser.Parse).to.throw());243 })();244 (() => {245 const parser = new Parser_1.Parser("raise 'Raised error';");246 it("should raise a 'Raised error' error", () => chai_1.expect(parser.Parse).to.throw());247 })();248 (() => {249 const parser = new Parser_1.Parser("if (true)");250 it("should raise an expected '{' error", () => chai_1.expect(parser.Parse).to.throw());251 })();252 (() => {253 const parser = new Parser_1.Parser("-false;");254 it("should raise a runtime error", () => chai_1.expect(parser.Parse).to.throw());255 })();256 (() => {257 const parser = new Parser_1.Parser("return;");258 it("should raise a runtime error", () => chai_1.expect(parser.Parse).to.throw());259 })();260 (() => {261 const parser = new Parser_1.Parser("method hello(name) { print 'hello ' + name ");262 it("should raise an expected '}' error", () => chai_1.expect(parser.Parse).to.throw());263 })();264 (() => {265 const parser = new Parser_1.Parser("for (let i; i < 2) {}");266 it("should raise an expected ';' error", () => chai_1.expect(parser.Parse).to.throw());267 })();268 });...
parenthesizing.ts
Source:parenthesizing.ts
1test(BinaryExpression('+',2 IntegerLiteral(1),3 BinaryExpression('*',4 IntegerLiteral(2),5 IntegerLiteral(3))6), [7 '1 + 2 * 3',8]);9test(BinaryExpression('*',10 IntegerLiteral(1),11 BinaryExpression('+',12 IntegerLiteral(2),13 IntegerLiteral(3))14), [15 '1 * (2 + 3)',16]);17test(CallExpression(18 Identifier('foo'),19 [SequenceExpression([20 IntegerLiteral(2),21 IntegerLiteral(3)])]22), [23 'foo((2, 3))',24]);25test(CallExpression(26 AssignmentExpression('=',27 Identifier('foo'),28 IntegerLiteral(2)),29 [IntegerLiteral(3)]30), [31 '(foo = 2)(3)',32]);33test(MemberExpression('.',34 AssignmentExpression('=',35 Identifier('foo'),36 IntegerLiteral(2)),37 Identifier('foo')38), [39 '(foo = 2).foo',40]);41test(BinaryExpression('->*',42 MemberExpression('.',43 Identifier('a'),44 Identifier('b')),45 MemberExpression('.',46 Identifier('c'),47 Identifier('d'))48), [49 'a.b->*c.d',50]);51test(UnaryExpression('-', true,52 BinaryExpression('+',53 IntegerLiteral(1),54 IntegerLiteral(2))55), [56 '-(1 + 2)',57]);58test(UnaryExpression('-', true,59 UnaryExpression('-', true,60 IntegerLiteral(1))61), [62 '- -1',63]);64test(UnaryExpression('+', true,65 UnaryExpression('+', true,66 IntegerLiteral(1))67), [68 '+ +1',69]);70test(UnaryExpression('+', true,71 UnaryExpression('-', true,72 IntegerLiteral(1))73), [74 '+-1',75]);76test(UnaryExpression('-', true,77 UnaryExpression('+', true,78 IntegerLiteral(1))79), [80 '-+1',81]);82test(UnaryExpression('sizeof', true,83 Identifier('foo')84), [85 'sizeof foo',86]);87test(UnaryExpression('sizeof', true,88 MemberExpression('::',89 Identifier('foo'),90 Identifier('bar'))91), [92 'sizeof foo::bar',93]);94test(MemberExpression('::',95 UnaryExpression('sizeof', true, Identifier('foo')),96 Identifier('bar')97), [98 '(sizeof foo)::bar',99]);100test(UnaryExpression('++', true,101 UnaryExpression('--', false,102 Identifier('foo'))103), [104 '++foo--',105]);106test(UnaryExpression('--', false,107 UnaryExpression('++', true,108 Identifier('foo'))109), [110 '(++foo)--',111]);112test(UnaryExpression('--', true,113 UnaryExpression('--', true,114 Identifier('foo'))115), [116 '-- --foo',117]);118test(UnaryExpression('++', false,119 UnaryExpression('++', false,120 Identifier('foo'))121), [122 'foo++ ++',123]);124test(CallExpression(125 BinaryExpression('.*',126 Identifier('a'),127 Identifier('b')), [128 IntegerLiteral(1)]129), [130 '(a.*b)(1)',131]);132test(CallExpression(133 BinaryExpression('->*',134 Identifier('a'),135 Identifier('b')), [136 IntegerLiteral(1)]137), [138 '(a->*b)(1)',139]);140test(BinaryExpression('.*',141 Identifier('a'),142 CallExpression(Identifier('b'), [])143), [144 'a.*b()',145]);146test(BinaryExpression('->*',147 Identifier('a'),148 CallExpression(Identifier('b'), [])149), [150 'a->*b()',151]);152test(SpecializeTemplate(153 Identifier('a'), [154 BinaryExpression('>',155 Identifier('b'),156 Identifier('c'))]157), [158 'a<(b > c)>',159]);160test(SpecializeTemplate(161 Identifier('a'), [162 BinaryExpression('>=',163 Identifier('b'),164 Identifier('c'))]165), [166 'a<b >= c>',167]);168test(SpecializeTemplate(169 Identifier('a'), [170 SpecializeTemplate(171 Identifier('b'), [172 BinaryExpression('>',173 Identifier('c'),174 Identifier('d'))])]175), [176 'a<b<(c > d)> >',177]);178test(SpecializeTemplate(179 Identifier('a'), [180 BinaryExpression('&',181 Identifier('b'),182 BinaryExpression('>',183 Identifier('c'),184 Identifier('d')))]185), [186 'a<(b & c > d)>',187]);188test(SpecializeTemplate(189 Identifier('a'), [190 BinaryExpression('[]',191 Identifier('b'),192 BinaryExpression('>',193 Identifier('c'),194 Identifier('d')))]195), [196 'a<b[c > d]>',197]);198test(SpecializeTemplate(199 Identifier('a'), [200 BinaryExpression('*',201 Identifier('b'),202 BinaryExpression('+',203 Identifier('c'),204 BinaryExpression('>',205 Identifier('d'),206 Identifier('e'))))]207), [208 'a<b * (c + (d > e))>',209]);210test(SpecializeTemplate(211 Identifier('a'), [212 BinaryExpression('&',213 StringLiteral('('),214 BinaryExpression('>',215 Identifier('b'),216 Identifier('c')))]217), [218 'a<("(" & b > c)>',219]);220test(BinaryExpression('||',221 BooleanLiteral(false),222 BinaryExpression('&&',223 BooleanLiteral(true),224 BooleanLiteral(false))225), [226 'false || true && false',227]);228test(BinaryExpression('&&',229 BooleanLiteral(false),230 BinaryExpression('||',231 BooleanLiteral(true),232 BooleanLiteral(false))233), [234 'false && (true || false)',235]);236test(BinaryExpression('||',237 BinaryExpression('&&',238 BooleanLiteral(true),239 BooleanLiteral(false)),240 BooleanLiteral(false)241), [242 'true && false || false',243]);244test(BinaryExpression('&&',245 BinaryExpression('||',246 BooleanLiteral(true),247 BooleanLiteral(false)),248 BooleanLiteral(false)249), [250 '(true || false) && false',251]);252// Turn on flag for subsequent tests253parenthesizeAndInsideOr = true;254test(BinaryExpression('||',255 BooleanLiteral(false),256 BinaryExpression('&&',257 BooleanLiteral(true),258 BooleanLiteral(false))259), [260 'false || (true && false)',261]);262test(BinaryExpression('&&',263 BooleanLiteral(false),264 BinaryExpression('||',265 BooleanLiteral(true),266 BooleanLiteral(false))267), [268 'false && (true || false)',269]);270test(BinaryExpression('||',271 BinaryExpression('&&',272 BooleanLiteral(true),273 BooleanLiteral(false)),274 BooleanLiteral(false)275), [276 '(true && false) || false',277]);278test(BinaryExpression('&&',279 BinaryExpression('||',280 BooleanLiteral(true),281 BooleanLiteral(false)),282 BooleanLiteral(false)283), [284 '(true || false) && false',285]);286// Reset flag for subsequent tests...
Using AI Code Generation
1const { openBrowser, goto, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12const { openBrowser, goto, closeBrowser } = require('taiko');13(async () => {14 try {15 await openBrowser();16 await goto("google.com");17 } catch (e) {18 console.error(e);19 } finally {20 await closeBrowser();21 }22})();23const { openBrowser, goto, closeBrowser } = require('taiko');24(async () => {25 try {26 await openBrowser();27 await goto("google.com");28 } catch (e) {29 console.error(e);30 } finally {31 await closeBrowser();32 }33})();34const { openBrowser, goto, closeBrowser } = require('taiko');35(async () => {36 try {37 await openBrowser();38 await goto("google.com");39 } catch (e) {40 console.error(e);41 } finally {42 await closeBrowser();43 }44})();45const { openBrowser, goto, closeBrowser } = require('taiko');46(async () => {47 try {48 await openBrowser();49 await goto("google.com");50 } catch (e) {51 console.error(e);52 } finally {53 await closeBrowser();54 }55})();56const { openBrowser, goto, closeBrowser } = require('taiko');57(async () => {58 try {59 await openBrowser();60 await goto("google.com");61 } catch (e) {62 console.error(e);63 } finally {64 await closeBrowser();65 }66})();67const { openBrowser, goto, closeBrowser } = require('taiko');68(async () => {69 try {70 await openBrowser();71 await goto("google.com");72 } catch (e) {
Using AI Code Generation
1let { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await write("Taiko", into(textBox()));7 await closeBrowser();8 } catch (e) {9 console.error(e);10 } finally {11 }12})();13let { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 await write("Taiko", into(textBox()));19 await closeBrowser();20 } catch (e) {21 console.error(e);22 } finally {23 }24})();25let { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await goto("google.com");30 await write("Taiko", into(textBox()));31 await closeBrowser();32 } catch (e) {33 console.error(e);34 } finally {35 }36})();37let { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');38(async () => {39 try {40 await openBrowser();41 await goto("google.com");42 await write("Taiko", into(textBox()));43 await closeBrowser();44 } catch (e)
Using AI Code Generation
1const { openBrowser, goto, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await write("taiko");6 await press('Enter');7 await click(link("Taiko API Docs"));8 await click(link("click"));
Using AI Code Generation
1const { openBrowser, goto, closeBrowser, button, $, toRightOf } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await button($(toRightOf('Google Search'))).exists();6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();12const { openBrowser, goto, closeBrowser, button, $, toRightOf } = require('taiko');13(async () => {14 try {15 await openBrowser();16 await button($(toRightOf('Google Search'))).exists();17 await closeBrowser();18 } catch (e) {19 console.error(e);20 } finally {21 }22})();23const { openBrowser, goto, closeBrowser, button, $, toRightOf } = require('taiko');24(async () => {25 try {26 await openBrowser();27 await button($(toRightOf('Google Search'))).exists();28 await closeBrowser();29 } catch (e) {30 console.error(e);31 } finally {32 }33})();34const { openBrowser, goto, closeBrowser, button, $, toRightOf } = require('taiko');35(async () => {36 try {37 await openBrowser();38 await button($(toRightOf('Google Search'))).exists();39 await closeBrowser();40 } catch (e) {41 console.error(e);42 } finally {43 }44})();45const { openBrowser, goto, closeBrowser, button, $, toRightOf } = require('taiko');46(async () => {47 try {48 await openBrowser();49 await button($(toRightOf('Google Search'))).exists();50 await closeBrowser();51 } catch (e) {52 console.error(e);53 } finally {54 }55})();56const { openBrowser, goto, closeBrowser, button, $, toRightOf } = require('taiko
Using AI Code Generation
1BinaryExpression ( left , operator , right )2BinaryExpression ( Identifier ( 'a' ), '===' , Identifier ( 'b' ))3BinaryExpression ( Identifier ( 'a' ), '===' , Identifier ( 'b' ), true )4BinaryExpression ( Identifier ( 'a' ), '===' , Identifier ( 'b' ), true , true )5BinaryExpression ( Identifier ( 'a' ), '===' , Identifier ( 'b' ), true , true , true )6Identifier ( name )7Identifier ( 'a' )8Identifier ( 'a' , true )9Identifier ( 'a' , true , true )10Identifier ( 'a' , true , true , true )11Literal ( value )12Literal ( 'a' )13Literal ( 'a' , true )14Literal ( 'a' , true , true )15Literal ( 'a' , true , true , true )16MemberExpression ( object , property )17MemberExpression ( Identifier ( 'a' ), Identifier ( 'b' ))18MemberExpression ( Identifier ( 'a' ), Identifier ( 'b' ), true )19MemberExpression ( Identifier ( 'a' ), Identifier ( 'b' ), true , true )20MemberExpression ( Identifier ( 'a' ), Identifier ( 'b' ), true , true , true )21ObjectExpression ( properties )
Using AI Code Generation
1const { openBrowser, goto, $, closeBrowser, evaluate } = require('taiko');2(async () => {3 try {4 await openBrowser();5 let expression = $("input[title='Search']").exists;6 let result = await evaluate(expression);7 console.log(result);8 } catch (error) {9 console.error(error);10 } finally {11 await closeBrowser();12 }13})();14The evaluate() method can be used to evaluate the text of an element. The following example demonstrates the usage of the evaluate() method to evaluate the text of an element:15const { openBrowser, goto, $, closeBrowser, evaluate, Text } = require('taiko');16(async () => {17 try {18 await openBrowser();19 let expression = Text($("input[title='Search']"));20 let result = await evaluate(expression);21 console.log(result);22 } catch (error) {23 console.error(error);24 } finally {25 await closeBrowser();26 }27})();28The evaluate() method can be used to perform arithmetic operations. The following example demonstrates the usage of the evaluate() method to perform arithmetic operations:29const { openBrowser, goto, $, closeBrowser, evaluate, Text } = require('taiko
Using AI Code Generation
1await click("button", below("Text"));2await click("button", above("Text"));3await click("button", rightOf("Text"));4await click("button", leftOf("Text"));5await click("button", near("Text"));6await click("button", toRightOf("Text"));7await click("button", toLeftOf("Text"));8await click(link("Text"));9await click(link("Text", "Text"));10await click(link("Text", "Text", "Text"));11await click(link("Text", "Text", "Text", "Text"));12await click(link("Text", "Text", "Text", "Text", "Text"));13await click(image("Text"));14await click(image("Text", "Text"));15await click(image("Text", "Text", "Text"));16await click(image("Text", "Text", "Text", "Text"));17await click(image("Text", "Text", "Text", "Text", "Text"));18await click(text("Text"));19await click(text("Text", "Text"));20await click(text("Text", "Text", "Text"));21await click(text("Text", "Text", "Text", "Text"));22await click(text("Text", "Text", "Text", "Text", "Text"));23await click(inputField("Text"));24await click(inputField("Text", "Text"));25await click(inputField("Text", "Text", "Text"));26await click(inputField("Text", "Text", "Text", "Text"));27await click(inputField("Text", "Text", "Text", "Text", "Text"));28await click(button("Text"));29await click(button("Text", "Text"));30await click(button("Text", "Text", "Text"));31await click(button("Text", "Text", "Text", "Text"));32await click(button("Text", "Text", "Text", "Text", "Text"));33await click(checkBox("Text"));34await click(checkBox("Text", "Text"));35await click(checkBox("Text", "Text", "Text"));36await click(checkBox("Text", "Text", "Text", "Text"));37await click(checkBox("Text", "Text", "Text", "Text", "
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!