1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

add some more tests

This commit is contained in:
mat 2022-01-09 15:13:08 -06:00
parent 4626bd45cd
commit c7554b40d5
2 changed files with 84 additions and 0 deletions

View file

@ -4,6 +4,7 @@ use crate::{immutable_string_reader::ImmutableStringReader, message::Message};
use super::command_syntax_exception::CommandSyntaxException;
#[derive(Clone, PartialEq)]
pub enum BuiltInExceptions {
DoubleTooSmall { found: usize, min: usize },
DoubleTooBig { found: usize, max: usize },

View file

@ -421,4 +421,87 @@ mod test {
assert_eq!(reader.get_read(), "\"hello world\"");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_single_quoted_string() {
let mut reader = StringReader::from("'hello world'");
assert_eq!(reader.read_quoted_string().unwrap(), "hello world");
assert_eq!(reader.get_read(), "'hello world'");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_mixed_quoted_string_double_inside_single() {
let mut reader = StringReader::from("'hello \"world\"'");
assert_eq!(reader.read_quoted_string().unwrap(), "hello \"world\"");
assert_eq!(reader.get_read(), "'hello \"world\"'");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_mixed_quoted_string_single_inside_double() {
let mut reader = StringReader::from("\"hello 'world'\"");
assert_eq!(reader.read_quoted_string().unwrap(), "hello 'world'");
assert_eq!(reader.get_read(), "\"hello 'world'\"");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_quoted_string_empty_quoted() {
let mut reader = StringReader::from("");
assert_eq!(reader.read_quoted_string().unwrap(), "");
assert_eq!(reader.get_read(), "");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_quoted_string_empty_quoted_with_remaining() {
let mut reader = StringReader::from("\"\" hello world");
assert_eq!(reader.read_quoted_string().unwrap(), "");
assert_eq!(reader.get_read(), "\"\"");
assert_eq!(reader.remaining(), " hello world");
}
#[test]
fn read_quoted_string_with_escaped_quote() {
let mut reader = StringReader::from("\"hello \\\"world\\\"\"");
assert_eq!(reader.read_quoted_string().unwrap(), "hello \"world\"");
assert_eq!(reader.get_read(), "\"hello \\\"world\\\"\"");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_quoted_string_with_escaped_escapes() {
let mut reader = StringReader::from("\"\\\\o/\"");
assert_eq!(reader.read_quoted_string().unwrap(), "\\o/");
assert_eq!(reader.get_read(), "\"\\\\o/\"");
assert_eq!(reader.remaining(), "");
}
#[test]
fn read_quoted_string_with_remaining() {
let mut reader = StringReader::from("\"hello world\" foo bar");
assert_eq!(reader.read_quoted_string().unwrap(), "hello world");
assert_eq!(reader.get_read(), "\"hello world\"");
assert_eq!(reader.remaining(), " foo bar");
}
#[test]
fn read_quoted_string_with_immediate_remaining() {
let mut reader = StringReader::from("\"hello world\"foo bar");
assert_eq!(reader.read_quoted_string().unwrap(), "hello world");
assert_eq!(reader.get_read(), "\"hello world\"");
assert_eq!(reader.remaining(), "foo bar");
}
#[test]
fn read_quoted_string_no_open() {
let mut reader = StringReader::from("hello world\"");
let result = reader.read_quoted_string();
assert!(result.is_err());
if let Err(e) = result {
assert_eq!(e.get_type(), &BuiltInExceptions::ReaderExpectedStartOfQuote);
assert_eq!(e.cursor(), Some(0));
}
}
}