Files
appRobotDriver/test/GCode.containsMCode.test.js
2026-06-08 19:04:31 +02:00

26 lines
920 B
JavaScript

const GCode = require('../robot/GCode');
// Bug 6: containsMCode previously used indexOf('M1') == 0, which also matched
// M10, M11, M114, ... It must only match the standalone M1 motor command.
describe('GCode.containsMCode', () => {
test('matches the exact M1 command', () => {
expect(GCode.containsMCode('M1')).toBe(true);
});
test('matches M1 with parameters', () => {
expect(GCode.containsMCode('M1 X10 Y20 Z30')).toBe(true);
});
test('does NOT match higher M-codes that start with M1', () => {
expect(GCode.containsMCode('M10')).toBe(false);
expect(GCode.containsMCode('M11 X1')).toBe(false);
expect(GCode.containsMCode('M12')).toBe(false);
expect(GCode.containsMCode('M114')).toBe(false);
});
test('does NOT match unrelated commands or empty input', () => {
expect(GCode.containsMCode('G1 X1')).toBe(false);
expect(GCode.containsMCode('')).toBe(false);
});
});