Skip to content

Commit

Permalink
Add tests for the some elementry parsing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
remcoder committed Oct 19, 2019
1 parent bdeda9d commit d02bf7b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/__tests__/gcode-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parser } from "../gcode-parser";

test('a single gcode cmd should result in 1 layer', () => {
test('a single gcode cmd should result in 1 layer with 1 command', () => {
const parser = new Parser();
const gcode =`G1 X0 Y0 Z1`;
const parsed = parser.parseGcode(gcode);
Expand All @@ -10,3 +10,27 @@ test('a single gcode cmd should result in 1 layer', () => {
expect(parsed.layers[0].commands).not.toBeNull();
expect(parsed.layers[0].commands.length).toEqual(1);
});

test('2 horizontal moves should result in 1 layer with 2 commands', () => {
const parser = new Parser();
const gcode =`G1 X0 Y0 Z1
G1 X10 Y10 Z1`;
const parsed = parser.parseGcode(gcode);
expect(parsed).not.toBeNull();
expect(parsed.layers).not.toBeNull();
expect(parsed.layers.length).toEqual(1)
expect(parsed.layers[0].commands).not.toBeNull();
expect(parsed.layers[0].commands.length).toEqual(2);
});

test('2 vertical moves should result in 2 layers with 1 command', () => {
const parser = new Parser();
const gcode =`G1 X0 Y0 Z1
G1 X0 Y0 Z2`;
const parsed = parser.parseGcode(gcode);
expect(parsed).not.toBeNull();
expect(parsed.layers).not.toBeNull();
expect(parsed.layers.length).toEqual(2)
expect(parsed.layers[0].commands).not.toBeNull();
expect(parsed.layers[0].commands.length).toEqual(1);
});

0 comments on commit d02bf7b

Please sign in to comment.