Skip to content

Commit

Permalink
Fixed print semi-colon behavior (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral authored Apr 17, 2024
1 parent 44e5acc commit 75440ab
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 37 deletions.
7 changes: 0 additions & 7 deletions src/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,6 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
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(
Expand Down
8 changes: 4 additions & 4 deletions test/cli/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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, {
Expand All @@ -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, {
Expand All @@ -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"),
Expand Down
20 changes: 0 additions & 20 deletions test/e2e/BrsComponents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,67 +112,51 @@ 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",
"c",
"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",
"c",
"d",
"c",
"isNext = ",
" ",
"true",
"a",
"b",
"c",
"d",
"testing AA ifEnum",
"isNext before Reset:",
" ",
"true",
"isNext after Reset:",
" ",
"true",
"a",
"b",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/Syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/resources/stdlib/json.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))
8 changes: 4 additions & 4 deletions test/interpreter/PrintStatements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ";"),
Expand All @@ -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", () => {
Expand Down Expand Up @@ -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`", () => {
Expand All @@ -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`", () => {
Expand Down

0 comments on commit 75440ab

Please sign in to comment.