Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jan 7, 2017
2 parents 6c06679 + af5a4d8 commit 2e84502
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gcode-interpreter",
"version": "1.1.0",
"version": "1.1.1",
"description": "G-code Interpreter",
"author": "Cheton Wu <[email protected]>",
"homepage": "https://github.com/cheton/gcode-interpreter",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ class GCodeInterpreter {
});
return s;
}
loadFromFileSync(file) {
loadFromFileSync(file, callback = noop) {
const list = parseFileSync(file);
for (let i = 0; i < list.length; ++i) {
interpret(this, list[i]);
callback(list[i], i);
}
return list;
}
Expand All @@ -125,10 +126,11 @@ class GCodeInterpreter {
});
return s;
}
loadFromStringSync(str) {
loadFromStringSync(str, callback = noop) {
const list = parseStringSync(str);
for (let i = 0; i < list.length; ++i) {
interpret(this, list[i]);
callback(list[i], i);
}
return list;
}
Expand Down
12 changes: 10 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,27 @@ describe('G-code Interpreter', () => {
});

it('loadFromFileSync() should return expected result.', (done) => {
let i = 0;
const file = 'test/fixtures/circle.nc';
const runner = new GCodeInterpreter();
const results = runner.loadFromFileSync(file);
const results = runner.loadFromFileSync(file, (data, index) => {
expect(i).to.be.equal(index);
++i;
});
expect(results).to.be.an('array');
expect(results.length).to.be.equal(7);
done();
});

it('loadFromStringSync() should return expected result.', (done) => {
let i = 0;
const file = 'test/fixtures/circle.nc';
const string = fs.readFileSync(file, 'utf8');
const runner = new GCodeInterpreter();
const results = runner.loadFromStringSync(string);
const results = runner.loadFromStringSync(string, (data, index) => {
expect(i).to.be.equal(index);
++i;
});
expect(results).to.be.an('array');
expect(results.length).to.be.equal(7);
done();
Expand Down

0 comments on commit 2e84502

Please sign in to comment.