Skip to content

Commit

Permalink
testCommand() for refactor of test (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra authored and shiffman committed Nov 11, 2018
1 parent 7888068 commit 4ef8325
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ class Parser {
parse() {
let cmdsExecutors = [];
while (this.remainingTokens()) {
let token = this.nextToken();
let cmd = undefined;

// testCommand to refactor
function testCommand(value, data) { return value.test(data) }

if (testCommand(movement, token)) {
cmd = new Command(token, parseFloat(this.nextToken()));
} else if (testCommand(noArgsCalls, token)) {
cmd = new Command(token);
} else if (testCommand(repeat, token)) {
cmd = new Command(token, parseInt(this.nextToken()));
let toRepeat = this.getRepeat();
let parser = new Parser(toRepeat);
cmd.commands = parser.parse();
} else if (testCommand(setxy,token)) {
cmd = new Command(token);
let argX = this.nextToken();
let argY = this.nextToken();
cmd.arg = [parseFloat(argX), parseFloat(argY)];
} else if (testCommand(color, token)) {
cmd = new Command(token, this.nextToken());
} else if (testCommand(setxySingle,token)) {
cmd = new Command(token, parseFloat(this.nextToken()));
}

const actualToken = this.nextToken();
let cmd = commandLookUp.get(actualToken);

Expand Down

1 comment on commit 4ef8325

@Toyz
Copy link
Contributor

@Toyz Toyz commented on 4ef8325 Nov 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually breaks the site, due to testCommand requiring regex that we no longer have

Please sign in to comment.