From 75440ab47179d28c50de8eef6f7a1678f1562897 Mon Sep 17 00:00:00 2001 From: Marcelo Lv Cabral Date: Wed, 17 Apr 2024 08:52:12 -0700 Subject: [PATCH] Fixed `print` semi-colon behavior (#67) --- src/interpreter/index.ts | 7 ------- test/cli/cli.test.js | 8 ++++---- test/e2e/BrsComponents.test.js | 20 -------------------- test/e2e/Syntax.test.js | 2 +- test/e2e/resources/stdlib/json.brs | 4 +++- test/interpreter/PrintStatements.test.js | 8 ++++---- 6 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index ac7e1c087..1ae14fdd7 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -413,13 +413,6 @@ export class Interpreter implements Expr.Visitor, Stmt.Visitor this.stdout.write(" ".repeat(16 - (this.stdout.position() % 16))); break; case Lexeme.Semicolon: - if (index === statement.expressions.length - 1) { - // Don't write an extra space for trailing `;` in print lists. - // They're used to suppress trailing newlines in `print` statements - break; - } - - this.stdout.write(" "); break; default: this.addError( diff --git a/test/cli/cli.test.js b/test/cli/cli.test.js index 7d5613bab..53e24ff73 100644 --- a/test/cli/cli.test.js +++ b/test/cli/cli.test.js @@ -9,9 +9,9 @@ describe("cli", () => { let rootDir = path.join(__dirname, "resources"); let command = [ - "FORCE_COLOR=0", "node", path.join(process.cwd(), "bin", "cli.js"), + "--no-color", "--root", rootDir, path.join(rootDir, "requires-manifest.brs"), @@ -23,10 +23,10 @@ describe("cli", () => { it("defaults --root to process.cwd()", async () => { let command = [ - "FORCE_COLOR=0", "node", path.join(process.cwd(), "bin", "cli.js"), "requires-manifest.brs", + "--no-color", ].join(" "); let { stdout } = await exec(command, { @@ -38,10 +38,10 @@ describe("cli", () => { it("prints syntax errors once", async () => { let filename = "errors/syntax-error.brs"; let command = [ - "FORCE_COLOR=0", "node", path.join(process.cwd(), "bin", "cli.js"), filename, + "--no-color", ].join(" "); try { await exec(command, { @@ -57,10 +57,10 @@ describe("cli", () => { it("prints eval errors once", async () => { let filename = "errors/uninitialized-object.brs"; let command = [ - "FORCE_COLOR=0", "node", path.join(process.cwd(), "bin", "cli.js"), filename, + "--no-color", ].join(" "); let { stderr } = await exec(command, { cwd: path.join(__dirname, "resources"), diff --git a/test/e2e/BrsComponents.test.js b/test/e2e/BrsComponents.test.js index 6092eac20..b07719c6d 100644 --- a/test/e2e/BrsComponents.test.js +++ b/test/e2e/BrsComponents.test.js @@ -112,19 +112,14 @@ describe("end to end brightscript functions", () => { expect(allArgs(outputStreams.stdout.write).filter((arg) => arg !== "\n")).toEqual([ "testing roArray ifEnum", "isNext Not Empty:", - " ", "true", "isEmpty:", - " ", "true", "isNext Empty:", - " ", "false", "isNext before Reset:", - " ", "true", "isNext after Reset:", - " ", "true", "a", "b", @@ -132,28 +127,20 @@ describe("end to end brightscript functions", () => { "c", "testing Linked List", "isEmpty = ", - " ", "true", "isNext Empty = ", - " ", "false", "getIndex() ", - " ", "invalid", "next() ", - " ", "invalid", "isEmpty = ", - " ", "false", "isNext before Reset = ", - " ", "false", "isNext after ResetIndex() = ", - " ", "false", "isNext after Reset() = ", - " ", "true", "a", "b", @@ -161,7 +148,6 @@ describe("end to end brightscript functions", () => { "d", "c", "isNext = ", - " ", "true", "a", "b", @@ -169,10 +155,8 @@ describe("end to end brightscript functions", () => { "d", "testing AA ifEnum", "isNext before Reset:", - " ", "true", "isNext after Reset:", - " ", "true", "a", "b", @@ -181,16 +165,12 @@ describe("end to end brightscript functions", () => { "9", "x", "isEmpty:", - " ", "false", "isNext Empty:", - " ", "false", "isNext before Reset:", - " ", "true", "isNext after Reset:", - " ", "true", "a", "b", diff --git a/test/e2e/Syntax.test.js b/test/e2e/Syntax.test.js index be481737f..fb93aa15e 100644 --- a/test/e2e/Syntax.test.js +++ b/test/e2e/Syntax.test.js @@ -216,7 +216,7 @@ describe("end to end syntax", () => { expect(allArgs(outputStreams.stdout.write).join("")).toEqual( "lorem 1psum\n" + - " 9 is equal to 9\n" + + " 9 is equal to 9\n" + // 0 0 0 1 1 2 2 2 3 3 4 4 4 5 5 // 0 4 8 2 6 0 4 8 2 6 0 4 8 2 6 "column a column b column c column d\n" + diff --git a/test/e2e/resources/stdlib/json.brs b/test/e2e/resources/stdlib/json.brs index 05e223b80..09e0b2437 100644 --- a/test/e2e/resources/stdlib/json.brs +++ b/test/e2e/resources/stdlib/json.brs @@ -6,11 +6,13 @@ aa.self = aa print formatJson(aa) print formatJson(parseJson("{""boolean"":false,""float"":3.14,""integer"":2147483647,""longinteger"":2147483650,""null"":null,""string"":""ok""}")) +pi = createObject("roFloat") +pi.setFloat(3.14) print parseJson(formatJson({ string: "ok", null: invalid, longinteger: 2147483650, integer: 2147483647, - float: createObject("roFloat", 3.14), + float: pi, boolean: false })) diff --git a/test/interpreter/PrintStatements.test.js b/test/interpreter/PrintStatements.test.js index efd1063d3..e1071186d 100644 --- a/test/interpreter/PrintStatements.test.js +++ b/test/interpreter/PrintStatements.test.js @@ -43,7 +43,7 @@ describe("interperter print statements", () => { expect(allArgs(stdout.write).join("")).toEqual("foobarbaz\n"); }); - it("prints multiple values with space separators", () => { + it("prints multiple values with semi-colon separators", () => { const ast = new Stmt.Print(tokens, [ new Expr.Literal(new BrsString("foo")), token(Lexeme.Semicolon, ";"), @@ -54,7 +54,7 @@ describe("interperter print statements", () => { const [result] = interpreter.exec([ast]); expect(result).toEqual(BrsInvalid.Instance); - expect(allArgs(stdout.write).join("")).toEqual("foo bar baz\n"); + expect(allArgs(stdout.write).join("")).toEqual("foobarbaz\n"); }); it("aligns values to 16-charcater tab stops", () => { @@ -87,7 +87,7 @@ describe("interperter print statements", () => { const [result] = interpreter.exec([ast]); expect(result).toEqual(BrsInvalid.Instance); - expect(allArgs(stdout.write).join("")).toEqual("foo bar baz"); + expect(allArgs(stdout.write).join("")).toEqual("foobarbaz"); }); it("inserts the current position via `pos`", () => { @@ -101,7 +101,7 @@ describe("interperter print statements", () => { const [result] = interpreter.exec([ast]); expect(result).toEqual(BrsInvalid.Instance); - expect(allArgs(stdout.write).join("")).toEqual("foo 4\n"); + expect(allArgs(stdout.write).join("")).toEqual("foo 3\n"); }); it("indents to an arbitrary position via `tab`", () => {