summaryrefslogtreecommitdiffstats
path: root/vendor/indoc/tests/test_indoc.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/indoc/tests/test_indoc.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/indoc/tests/test_indoc.rs')
-rw-r--r--vendor/indoc/tests/test_indoc.rs166
1 files changed, 166 insertions, 0 deletions
diff --git a/vendor/indoc/tests/test_indoc.rs b/vendor/indoc/tests/test_indoc.rs
new file mode 100644
index 000000000..e0ead11b6
--- /dev/null
+++ b/vendor/indoc/tests/test_indoc.rs
@@ -0,0 +1,166 @@
+use indoc::indoc;
+
+#[test]
+fn byte_string() {
+ let indoc = indoc! {b"
+ a
+
+ \\b
+ c"
+ };
+ let expected = b"a\n\n \\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn carriage_return() {
+ // Every line in the string ends with \r\n
+ let indoc = indoc! {"
+ a
+
+ \\b
+ c"
+ };
+ let expected = "a\n\n \\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn trailing_comma() {
+ let indoc = indoc! {
+ "
+ test
+ ",
+ };
+ let expected = "test\n";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn empty_string() {
+ let indoc = indoc! {""};
+ let expected = "";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn joined_first_line() {
+ let indoc = indoc! {"\
+ a"
+ };
+ let expected = "a";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn joined_lines() {
+ let indoc = indoc! {"
+ a\
+ b
+ c\
+ d
+ e"
+ };
+ let expected = "ab\ncd\ne";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn no_leading_newline() {
+ let indoc = indoc! {"a
+ b
+ c"};
+ let expected = "a\nb\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn one_line() {
+ let indoc = indoc! {"a"};
+ let expected = "a";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn raw_byte_string() {
+ let indoc = indoc! {br#"
+ "a"
+
+ \\b
+ c"#
+ };
+ let expected = b"\"a\"\n\n \\\\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn raw_string() {
+ let indoc = indoc! {r#"
+ "a"
+
+ \\b
+ c"#
+ };
+ let expected = "\"a\"\n\n \\\\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn string() {
+ let indoc = indoc! {"
+ a
+
+ \\b
+ c"
+ };
+ let expected = "a\n\n \\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn string_trailing_newline() {
+ let indoc = indoc! {"
+ a
+
+ \\b
+ c
+ "};
+ let expected = "a\n\n \\b\nc\n";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn trailing_whitespace() {
+ let indoc = indoc! {"
+ 2 below
+
+ 0 below
+
+ -2 below
+
+ end"
+ };
+ let expected = "2 below\n \n0 below\n\n-2 below\n\nend";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn indoc_as_format_string() {
+ let s = format!(indoc! {"{}"}, true);
+ assert_eq!(s, "true");
+}
+
+#[test]
+fn test_metavariable() {
+ macro_rules! indoc_wrapper {
+ ($e:expr) => {
+ indoc!($e)
+ };
+ }
+
+ let indoc = indoc_wrapper! {"
+ macros, how do they work
+ "};
+ let expected = "macros, how do they work\n";
+ assert_eq!(indoc, expected);
+}