aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-01-09 15:13:08 -0600
committermat <github@matdoes.dev>2022-01-09 15:13:08 -0600
commitc7554b40d52c33db6a5cc23a5b2e01b96dfe3a59 (patch)
tree148f877790b18cedaf6d2e70286cedd3eeccbd99 /azalea-brigadier
parent4626bd45cd8b3875a0ee006cf8e2c7cfb9f8cbcc (diff)
downloadazalea-drasl-c7554b40d52c33db6a5cc23a5b2e01b96dfe3a59.tar.xz
add some more tests
Diffstat (limited to 'azalea-brigadier')
-rw-r--r--azalea-brigadier/src/exceptions/builtin_exceptions.rs1
-rw-r--r--azalea-brigadier/src/string_reader.rs83
2 files changed, 84 insertions, 0 deletions
diff --git a/azalea-brigadier/src/exceptions/builtin_exceptions.rs b/azalea-brigadier/src/exceptions/builtin_exceptions.rs
index fcca49cd..1533364b 100644
--- a/azalea-brigadier/src/exceptions/builtin_exceptions.rs
+++ b/azalea-brigadier/src/exceptions/builtin_exceptions.rs
@@ -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 },
diff --git a/azalea-brigadier/src/string_reader.rs b/azalea-brigadier/src/string_reader.rs
index 4ef35ac0..28823bce 100644
--- a/azalea-brigadier/src/string_reader.rs
+++ b/azalea-brigadier/src/string_reader.rs
@@ -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));
+ }
+ }
}