Skip to content

Commit cb8bab1

Browse files
yogiraj99craftybones
authored andcommitted
Added the ability to ignore numbered lines that are empty by treating them as nonExecutable
* Fixed issue of InvalidInstructionException when instruction has only line number and spaces. * Extracted checks of NonExecutable lines into function named isNonExecutable.
1 parent b437523 commit cb8bab1

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/parse.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
const InvalidInstructionException = require('./commands/invalidInstructionException');
2-
const parse = instruction => {
2+
3+
function isNonExecutable(instruction) {
34
let empty = /^\s*$/;
5+
let onlyNumber = /^\s*([0-9]+)+\s*$/;
46
let comment = /^\s*;.*$/;
7+
return (
8+
instruction.match(empty) ||
9+
instruction.match(comment) ||
10+
instruction.match(onlyNumber)
11+
);
12+
}
13+
14+
const parse = instruction => {
515
let components = /^\s*([0-9]+)\s+([a-zA-Z]+)\s*(.*)*$/;
6-
if (instruction.match(empty) || instruction.match(comment))
7-
return { nonExecutableLine: true };
16+
if (isNonExecutable(instruction)) return { nonExecutableLine: true };
817
let matches = instruction.match(components);
918
try {
1019
let lineNumber = matches[1];

test/testParser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ describe('should parse all legal forms', function() {
4545
let { nonExecutableLine } = parse(` ; this is a comment`);
4646
assert.equal(true, nonExecutableLine);
4747
});
48+
it('should parse line with only line number', function() {
49+
let { nonExecutableLine } = parse(`10`);
50+
assert.equal(true, nonExecutableLine);
51+
});
52+
it('should parse line with only line number with spaces', function() {
53+
let { nonExecutableLine } = parse(`10 `);
54+
assert.equal(true, nonExecutableLine);
55+
});
56+
it('should parse line with only line number with newLine at end', function() {
57+
let { nonExecutableLine } = parse(`10 \n`);
58+
assert.equal(true, nonExecutableLine);
59+
});
4860
});
4961

5062
describe('should not parse illegal forms', function() {

0 commit comments

Comments
 (0)