[librsvg: 12/28] path_parser: Test that we detect broken/incomplete numbers when parsing
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 12/28] path_parser: Test that we detect broken/incomplete numbers when parsing
- Date: Tue, 23 Jan 2018 18:00:14 +0000 (UTC)
commit 1b871fd28d4efd8b8912545426a561150e612fe2
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jan 23 10:16:21 2018 -0600
path_parser: Test that we detect broken/incomplete numbers when parsing
rust/src/path_parser.rs | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
---
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index 7251244..10cecfd 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -254,8 +254,10 @@ impl<'b> PathParser<'b> {
assert! (self.match_char (c));
}
- } else {
+ } else if self.lookahead.is_some() {
return Err(self.error(ErrorKind::UnexpectedToken));
+ } else {
+ return Err(self.error(ErrorKind::UnexpectedEof));
}
}
@@ -1053,6 +1055,45 @@ mod tests {
None);
}
+ #[test]
+ fn detects_bogus_numbers() {
+ test_parser("M+",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedEof));
+
+ test_parser("M-",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedEof));
+
+ test_parser("M+x",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedToken));
+
+ test_parser("M10e",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedEof));
+
+ test_parser("M10ex",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedToken));
+
+ test_parser("M10e-",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedEof));
+
+ test_parser("M10e+x",
+ " ^",
+ &vec![],
+ Some(ErrorKind::UnexpectedToken));
+
+ }
+
#[test]
fn handles_numbers_with_comma () {
test_parser ("M 10, 20",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]