From 32a369118cf881900f92d828a208364c43a0a382 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Thu, 30 Apr 2020 18:54:28 +0100 Subject: [PATCH] quote/unquote functions --- README.md | 1 - src/lib.rs | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f6a1b2d..60d8ae2 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ some more practical uses would be things like: * implement Result return types on ::from functions so we can handle errors * handle old out-of-bounds editor errors (extra image pixels, exits/endings with position -1,-0 etc.) * it's ok if the output of these does not match the input as we're fixing it -* "unquote" function for dialogues, game title, anything else that supports """ * add Bitsy HD and Bitsy 7.0 test data * fix variables/endings becoming "DLG DLG"? * replace Image with Vec or something. seems like a pointless abstraction diff --git a/src/lib.rs b/src/lib.rs index de71adc..514b4ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,7 +176,7 @@ impl Unquote for String { #[cfg(test)] mod test { - use crate::{from_base36, ToBase36, optional_data_line, mock, segments_from_string}; + use crate::{from_base36, ToBase36, optional_data_line, mock, segments_from_string, Quote, Unquote}; #[test] fn test_from_base36() { @@ -211,4 +211,18 @@ mod test { assert_eq!(output, expected); } + + #[test] + fn test_quote() { + let output = "this is a string.\nIt has 2 lines".to_string().quote(); + let expected = "\"\"\"\nthis is a string.\nIt has 2 lines\n\"\"\"".to_string(); + assert_eq!(output, expected); + } + + #[test] + fn test_unquote() { + let output = "\"\"\"\nwho the fuck is scraeming \"LOG OFF\" at my house.\nshow yourself, coward.\ni will never log off\n\"\"\"".to_string().unquote(); + let expected = "who the fuck is scraeming \"LOG OFF\" at my house.\nshow yourself, coward.\ni will never log off".to_string(); + assert_eq!(output, expected); + } }