From 83c4757e3679c094bb5312aee59b61026640f2c7 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Fri, 26 Feb 2021 20:50:52 -0500 Subject: [PATCH] more tests --- src/parser.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 05eb052..f4ba895 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1161,6 +1161,16 @@ mod value_no_continuation { fn garbage_after_continution_is_err() { assert!(value_impl(b"hello \\afwjdls", &mut vec![]).is_err()); } + + #[test] + fn incomplete_quote() { + assert!(value_impl(br#"hello "world"#, &mut vec![]).is_err()); + } + + #[test] + fn incomplete_escape() { + assert!(value_impl(br#"hello world\"#, &mut vec![]).is_err()); + } } #[cfg(test)] @@ -1439,3 +1449,29 @@ mod section { ); } } + +#[cfg(test)] +mod error { + use super::*; + + #[test] + fn line_no_is_one_indexed() { + assert_eq!(parse_from_str("[hello").unwrap_err().line_number(), 1); + } + + #[test] + fn remaining_data_contains_bad_tokens() { + assert_eq!( + parse_from_str("[hello").unwrap_err().remaining_data(), + b"[hello" + ); + } + + #[test] + fn to_string_truncates_extra_values() { + assert_eq!( + parse_from_str("[1234567890").unwrap_err().to_string(), + "Got an unexpected token on line 1 while trying to parse a section header: '[123456789' ... (1 characters omitted)" + ); + } +}