ToDo_1 erledigt
This commit is contained in:
46
test/GCodeParser.test.js
Normal file
46
test/GCodeParser.test.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const GCodeParser = require('../robot/GCodeParser');
|
||||
|
||||
describe('GCodeParser', () => {
|
||||
test('parses a simple G1 command with XYZ parameters', () => {
|
||||
const parsed = GCodeParser.parse('G1 X10 Y20 Z30');
|
||||
|
||||
expect(parsed).toEqual([
|
||||
{
|
||||
command: 'G1',
|
||||
params: { X: 10, Y: 20, Z: 30 },
|
||||
raw: 'G1 X10 Y20 Z30'
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test('parses multiple commands in one line', () => {
|
||||
const parsed = GCodeParser.parse('G90 G21 G1 X20 Y30');
|
||||
|
||||
expect(parsed.map(cmd => cmd.command)).toEqual(['G90', 'G21', 'G1']);
|
||||
expect(parsed[2].params).toEqual({ X: 20, Y: 30 });
|
||||
});
|
||||
|
||||
test('parses buffer input as UTF-8', () => {
|
||||
const parsed = GCodeParser.parse(Buffer.from('G90 G1 X12 Y34 Z56', 'utf8'));
|
||||
|
||||
expect(parsed.length).toBe(2);
|
||||
expect(parsed[0].command).toBe('G90');
|
||||
expect(parsed[1].command).toBe('G1');
|
||||
expect(parsed[1].params).toEqual({ X: 12, Y: 34, Z: 56 });
|
||||
});
|
||||
|
||||
test('parses jogging prefix and ignores unsupported G-code', () => {
|
||||
const parsed = GCodeParser.parse('$J=G91 G1 X2 Y3');
|
||||
|
||||
expect(parsed).toEqual([
|
||||
{ command: 'G91', params: {}, raw: 'G91' },
|
||||
{ command: 'G1', params: { X: 2, Y: 3 }, raw: 'G1 X2 Y3' }
|
||||
]);
|
||||
});
|
||||
|
||||
test('returns empty array for invalid input', () => {
|
||||
expect(GCodeParser.parse('X324')).toEqual([]);
|
||||
expect(GCodeParser.parse('')).toEqual([]);
|
||||
expect(GCodeParser.parse(undefined)).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user