Skip to content

Commit 2107449

Browse files
committed
Add tests implicit_command_after_newline and two_commands_in_a_row
Both fail, and are the basis for a new bug report.
1 parent 8ec331c commit 2107449

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

gcode/src/parser.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ where
130130
word.span,
131131
B::Arguments::default(),
132132
));
133+
133134
return;
134135
}
135136

@@ -413,23 +414,6 @@ mod tests {
413414
assert_eq!(got[1].gcodes().len(), 1);
414415
}
415416

416-
/// I wasn't sure if the `#[derive(Serialize)]` would work given we use
417-
/// `B::Comments`, which would borrow from the original source.
418-
#[test]
419-
#[cfg(feature = "serde-1")]
420-
fn you_can_actually_serialize_lines() {
421-
let src = "G01 X5 G90 (comment) G91 M10\nG01\n";
422-
let line = parse(src).next().unwrap();
423-
424-
fn assert_serializable<S: serde::Serialize>(_: &S) {}
425-
fn assert_deserializable<'de, D: serde::Deserialize<'de>>() {}
426-
427-
assert_serializable(&line);
428-
assert_deserializable::<Line<'_>>();
429-
}
430-
431-
/// For some reason we were parsing the G90, then an empty G01 and the
432-
/// actual G01.
433417
#[test]
434418
fn funny_bug_in_crate_example() {
435419
let src = "G90 \n G01 X50.0 Y-10";
@@ -441,7 +425,43 @@ mod tests {
441425
];
442426

443427
let got: Vec<_> = crate::parse(src).collect();
428+
assert_eq!(got, expected);
429+
}
430+
431+
#[test]
432+
#[ignore]
433+
fn implicit_command_after_newline() {
434+
let src = "G01 X1.0 Y2.0\n X3.0 Y4.0";
435+
let expected = vec![
436+
GCode::new(Mnemonic::General, 1.0, Span::PLACEHOLDER)
437+
.with_argument(Word::new('X', 1.0, Span::PLACEHOLDER))
438+
.with_argument(Word::new('Y', 2.0, Span::PLACEHOLDER)),
439+
GCode::new(Mnemonic::General, 1.0, Span::PLACEHOLDER)
440+
.with_argument(Word::new('X', 3.0, Span::PLACEHOLDER))
441+
.with_argument(Word::new('Y', 4.0, Span::PLACEHOLDER)),
442+
];
444443

444+
let got: Vec<_> = crate::parse(src).collect();
445+
assert_eq!(got, expected);
446+
}
447+
448+
#[test]
449+
#[ignore]
450+
// This test focuses on the G90 and M7 on the same line.
451+
fn two_commands_in_a_row() {
452+
let src = "G90 M7\nG01 X1.0 Y2.0\nX3.0 Y4.0";
453+
let expected = vec![
454+
GCode::new(Mnemonic::General, 90.0, Span::PLACEHOLDER),
455+
GCode::new(Mnemonic::Miscellaneous, 7.0, Span::PLACEHOLDER),
456+
GCode::new(Mnemonic::General, 1.0, Span::PLACEHOLDER)
457+
.with_argument(Word::new('X', 1.0, Span::PLACEHOLDER))
458+
.with_argument(Word::new('Y', 2.0, Span::PLACEHOLDER)),
459+
GCode::new(Mnemonic::General, 1.0, Span::PLACEHOLDER)
460+
.with_argument(Word::new('X', 3.0, Span::PLACEHOLDER))
461+
.with_argument(Word::new('Y', 4.0, Span::PLACEHOLDER)),
462+
];
463+
464+
let got: Vec<_> = crate::parse(src).collect();
445465
assert_eq!(got, expected);
446466
}
447467
}

0 commit comments

Comments
 (0)