summaryrefslogtreecommitdiffstats
path: root/vendor/indoc/tests
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
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')
-rw-r--r--vendor/indoc/tests/compiletest.rs7
-rw-r--r--vendor/indoc/tests/test_formatdoc.rs117
-rw-r--r--vendor/indoc/tests/test_indoc.rs166
-rw-r--r--vendor/indoc/tests/test_unindent.rs53
-rw-r--r--vendor/indoc/tests/test_writedoc.rs57
-rw-r--r--vendor/indoc/tests/ui/no-arguments.rs5
-rw-r--r--vendor/indoc/tests/ui/no-arguments.stderr7
-rw-r--r--vendor/indoc/tests/ui/non-lit.rs5
-rw-r--r--vendor/indoc/tests/ui/non-lit.stderr5
-rw-r--r--vendor/indoc/tests/ui/non-string.rs5
-rw-r--r--vendor/indoc/tests/ui/non-string.stderr5
-rw-r--r--vendor/indoc/tests/ui/printdoc-binary.rs5
-rw-r--r--vendor/indoc/tests/ui/printdoc-binary.stderr5
-rw-r--r--vendor/indoc/tests/ui/printdoc-extra-arg.rs5
-rw-r--r--vendor/indoc/tests/ui/printdoc-extra-arg.stderr7
-rw-r--r--vendor/indoc/tests/ui/printdoc-no-arg.rs5
-rw-r--r--vendor/indoc/tests/ui/printdoc-no-arg.stderr5
-rw-r--r--vendor/indoc/tests/ui/printdoc-no-display.rs7
-rw-r--r--vendor/indoc/tests/ui/printdoc-no-display.stderr9
-rw-r--r--vendor/indoc/tests/ui/printdoc-no-named-arg.rs5
-rw-r--r--vendor/indoc/tests/ui/printdoc-no-named-arg.stderr5
-rw-r--r--vendor/indoc/tests/ui/three-arguments.rs9
-rw-r--r--vendor/indoc/tests/ui/three-arguments.stderr5
-rw-r--r--vendor/indoc/tests/ui/two-arguments.rs9
-rw-r--r--vendor/indoc/tests/ui/two-arguments.stderr5
25 files changed, 518 insertions, 0 deletions
diff --git a/vendor/indoc/tests/compiletest.rs b/vendor/indoc/tests/compiletest.rs
new file mode 100644
index 000000000..7974a6249
--- /dev/null
+++ b/vendor/indoc/tests/compiletest.rs
@@ -0,0 +1,7 @@
+#[rustversion::attr(not(nightly), ignore)]
+#[cfg_attr(miri, ignore)]
+#[test]
+fn ui() {
+ let t = trybuild::TestCases::new();
+ t.compile_fail("tests/ui/*.rs");
+}
diff --git a/vendor/indoc/tests/test_formatdoc.rs b/vendor/indoc/tests/test_formatdoc.rs
new file mode 100644
index 000000000..5e4779504
--- /dev/null
+++ b/vendor/indoc/tests/test_formatdoc.rs
@@ -0,0 +1,117 @@
+use indoc::formatdoc;
+
+#[test]
+fn carriage_return() {
+ // Every line in the string ends with \r\n
+ let indoc = formatdoc! {"
+ {}
+
+ \\{}
+ {}",
+ 'a', 'b', 'c'
+ };
+ let expected = "a\n\n \\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn empty_string() {
+ let indoc = formatdoc! {""};
+ let expected = "";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn joined_first_line() {
+ let indoc = formatdoc! {"\
+ {}", 'a'
+ };
+ let expected = "a";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn joined_lines() {
+ let indoc = formatdoc! {"
+ {}\
+ {}
+ {}\
+ {}
+ {}",
+ 'a', 'b', 'c', 'd', 'e'
+ };
+ let expected = "ab\ncd\ne";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn no_leading_newline() {
+ let indoc = formatdoc! {"{}
+ {}
+ {}", 'a', 'b', 'c'};
+ let expected = "a\nb\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn one_line() {
+ let indoc = formatdoc! {"a"};
+ let expected = "a";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn raw_string() {
+ let indoc = formatdoc! {r#"
+ {:?}
+
+ \\{}
+ {}"#,
+ "a", 'b', 'c'
+ };
+ let expected = "\"a\"\n\n \\\\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn string() {
+ let indoc = formatdoc! {"
+ {}
+
+ \\{}
+ {}",
+ 'a', 'b', 'c'
+ };
+ let expected = "a\n\n \\b\nc";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn string_trailing_newline() {
+ let indoc = formatdoc! {"
+ {}
+
+ \\{}
+ {}
+ ",
+ 'a', 'b', 'c'
+ };
+ let expected = "a\n\n \\b\nc\n";
+ assert_eq!(indoc, expected);
+}
+
+#[test]
+fn trailing_whitespace() {
+ let indoc = formatdoc! {"
+ {} {below}
+
+ {} {below}
+
+ {} {below}
+
+ end",
+ 2, 0, -2, below = "below"
+ };
+ let expected = "2 below\n \n0 below\n\n-2 below\n\nend";
+ assert_eq!(indoc, expected);
+}
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);
+}
diff --git a/vendor/indoc/tests/test_unindent.rs b/vendor/indoc/tests/test_unindent.rs
new file mode 100644
index 000000000..798907c5e
--- /dev/null
+++ b/vendor/indoc/tests/test_unindent.rs
@@ -0,0 +1,53 @@
+#![allow(clippy::shadow_unrelated)]
+
+use unindent::{unindent, unindent_bytes, Unindent};
+
+#[test]
+fn fn_unindent_str() {
+ let s = "
+ line one
+ line two";
+ assert_eq!(unindent(s), "line one\nline two");
+
+ let s = "\n\t\t\tline one\n\t\t\tline two";
+ assert_eq!(unindent(s), "line one\nline two");
+}
+
+#[test]
+fn fn_unindent_bytes() {
+ let b = b"
+ line one
+ line two";
+ assert_eq!(unindent_bytes(b), b"line one\nline two");
+
+ let b = b"\n\t\t\tline one\n\t\t\tline two";
+ assert_eq!(unindent_bytes(b), b"line one\nline two");
+}
+
+#[test]
+fn trait_unindent_str() {
+ let s = "
+ line one
+ line two";
+ assert_eq!(s.unindent(), "line one\nline two");
+
+ let s = "\n\t\t\tline one\n\t\t\tline two";
+ assert_eq!(s.unindent(), "line one\nline two");
+}
+
+#[test]
+fn trait_unindent_bytes() {
+ let b = b"
+ line one
+ line two";
+ assert_eq!(b.unindent(), b"line one\nline two");
+
+ let b = b"\n\t\t\tline one\n\t\t\tline two";
+ assert_eq!(b.unindent(), b"line one\nline two");
+}
+
+#[test]
+fn carriage_returns() {
+ let s = "\r\n\tline one\r\n\tline two";
+ assert_eq!(unindent(s), "line one\r\nline two");
+}
diff --git a/vendor/indoc/tests/test_writedoc.rs b/vendor/indoc/tests/test_writedoc.rs
new file mode 100644
index 000000000..8d1946892
--- /dev/null
+++ b/vendor/indoc/tests/test_writedoc.rs
@@ -0,0 +1,57 @@
+#![allow(clippy::if_same_then_else)]
+
+use indoc::writedoc;
+use std::fmt::Write as _;
+
+#[test]
+fn test_write_to_string() {
+ let mut s = String::new();
+ writedoc!(
+ s,
+ "
+ one
+ two
+ ",
+ )
+ .unwrap();
+
+ let expected = "one\ntwo\n";
+ assert_eq!(s, expected);
+}
+
+#[test]
+fn test_format_args() {
+ let mut s = String::new();
+ writedoc!(
+ s,
+ "
+ {}
+ {}
+ ",
+ 0,
+ 0,
+ )
+ .unwrap();
+
+ let expected = "0\n0\n";
+ assert_eq!(s, expected);
+}
+
+#[test]
+fn test_angle_bracket_parsing() {
+ const ZERO: usize = 0;
+
+ struct Pair<A, B>(A, B);
+ impl Pair<(), ()> {
+ const ONE: usize = 1;
+ }
+
+ let mut s = String::new();
+ let _ = writedoc! {
+ if ZERO < Pair::<(), ()>::ONE { &mut s } else { &mut s },
+ "writedoc",
+ };
+
+ let expected = "writedoc";
+ assert_eq!(s, expected);
+}
diff --git a/vendor/indoc/tests/ui/no-arguments.rs b/vendor/indoc/tests/ui/no-arguments.rs
new file mode 100644
index 000000000..ea394d8f2
--- /dev/null
+++ b/vendor/indoc/tests/ui/no-arguments.rs
@@ -0,0 +1,5 @@
+use indoc::indoc;
+
+fn main() {
+ indoc!();
+}
diff --git a/vendor/indoc/tests/ui/no-arguments.stderr b/vendor/indoc/tests/ui/no-arguments.stderr
new file mode 100644
index 000000000..110e44106
--- /dev/null
+++ b/vendor/indoc/tests/ui/no-arguments.stderr
@@ -0,0 +1,7 @@
+error: unexpected end of macro invocation, expected format string
+ --> tests/ui/no-arguments.rs:4:5
+ |
+4 | indoc!();
+ | ^^^^^^^^
+ |
+ = note: this error originates in the macro `indoc` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/vendor/indoc/tests/ui/non-lit.rs b/vendor/indoc/tests/ui/non-lit.rs
new file mode 100644
index 000000000..d51072d88
--- /dev/null
+++ b/vendor/indoc/tests/ui/non-lit.rs
@@ -0,0 +1,5 @@
+use indoc::indoc;
+
+fn main() {
+ indoc!(fail);
+}
diff --git a/vendor/indoc/tests/ui/non-lit.stderr b/vendor/indoc/tests/ui/non-lit.stderr
new file mode 100644
index 000000000..ba1b7466c
--- /dev/null
+++ b/vendor/indoc/tests/ui/non-lit.stderr
@@ -0,0 +1,5 @@
+error: argument must be a single string literal
+ --> tests/ui/non-lit.rs:4:12
+ |
+4 | indoc!(fail);
+ | ^^^^
diff --git a/vendor/indoc/tests/ui/non-string.rs b/vendor/indoc/tests/ui/non-string.rs
new file mode 100644
index 000000000..174ea95a8
--- /dev/null
+++ b/vendor/indoc/tests/ui/non-string.rs
@@ -0,0 +1,5 @@
+use indoc::indoc;
+
+fn main() {
+ indoc!(64);
+}
diff --git a/vendor/indoc/tests/ui/non-string.stderr b/vendor/indoc/tests/ui/non-string.stderr
new file mode 100644
index 000000000..4c1d4279c
--- /dev/null
+++ b/vendor/indoc/tests/ui/non-string.stderr
@@ -0,0 +1,5 @@
+error: argument must be a single string literal
+ --> tests/ui/non-string.rs:4:12
+ |
+4 | indoc!(64);
+ | ^^
diff --git a/vendor/indoc/tests/ui/printdoc-binary.rs b/vendor/indoc/tests/ui/printdoc-binary.rs
new file mode 100644
index 000000000..24e500e66
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-binary.rs
@@ -0,0 +1,5 @@
+use indoc::printdoc;
+
+fn main() {
+ printdoc!(b"");
+}
diff --git a/vendor/indoc/tests/ui/printdoc-binary.stderr b/vendor/indoc/tests/ui/printdoc-binary.stderr
new file mode 100644
index 000000000..a1fb07862
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-binary.stderr
@@ -0,0 +1,5 @@
+error: byte strings are not supported in formatting macros
+ --> tests/ui/printdoc-binary.rs:4:15
+ |
+4 | printdoc!(b"");
+ | ^^^
diff --git a/vendor/indoc/tests/ui/printdoc-extra-arg.rs b/vendor/indoc/tests/ui/printdoc-extra-arg.rs
new file mode 100644
index 000000000..661e3a0b6
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-extra-arg.rs
@@ -0,0 +1,5 @@
+use indoc::printdoc;
+
+fn main() {
+ printdoc!("", 0);
+}
diff --git a/vendor/indoc/tests/ui/printdoc-extra-arg.stderr b/vendor/indoc/tests/ui/printdoc-extra-arg.stderr
new file mode 100644
index 000000000..94aaabe92
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-extra-arg.stderr
@@ -0,0 +1,7 @@
+error: argument never used
+ --> tests/ui/printdoc-extra-arg.rs:4:19
+ |
+4 | printdoc!("", 0);
+ | -- ^ argument never used
+ | |
+ | formatting specifier missing
diff --git a/vendor/indoc/tests/ui/printdoc-no-arg.rs b/vendor/indoc/tests/ui/printdoc-no-arg.rs
new file mode 100644
index 000000000..90ea148a1
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-no-arg.rs
@@ -0,0 +1,5 @@
+use indoc::printdoc;
+
+fn main() {
+ printdoc!("{}");
+}
diff --git a/vendor/indoc/tests/ui/printdoc-no-arg.stderr b/vendor/indoc/tests/ui/printdoc-no-arg.stderr
new file mode 100644
index 000000000..19d0ea543
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-no-arg.stderr
@@ -0,0 +1,5 @@
+error: 1 positional argument in format string, but no arguments were given
+ --> tests/ui/printdoc-no-arg.rs:4:16
+ |
+4 | printdoc!("{}");
+ | ^^
diff --git a/vendor/indoc/tests/ui/printdoc-no-display.rs b/vendor/indoc/tests/ui/printdoc-no-display.rs
new file mode 100644
index 000000000..22c3ebc0e
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-no-display.rs
@@ -0,0 +1,7 @@
+use indoc::printdoc;
+
+struct NoDisplay;
+
+fn main() {
+ printdoc!("{}", NoDisplay);
+}
diff --git a/vendor/indoc/tests/ui/printdoc-no-display.stderr b/vendor/indoc/tests/ui/printdoc-no-display.stderr
new file mode 100644
index 000000000..1e0fee569
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-no-display.stderr
@@ -0,0 +1,9 @@
+error[E0277]: `NoDisplay` doesn't implement `std::fmt::Display`
+ --> tests/ui/printdoc-no-display.rs:6:21
+ |
+6 | printdoc!("{}", NoDisplay);
+ | ^^^^^^^^^ `NoDisplay` cannot be formatted with the default formatter
+ |
+ = help: the trait `std::fmt::Display` is not implemented for `NoDisplay`
+ = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+ = note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/vendor/indoc/tests/ui/printdoc-no-named-arg.rs b/vendor/indoc/tests/ui/printdoc-no-named-arg.rs
new file mode 100644
index 000000000..e4d5d9799
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-no-named-arg.rs
@@ -0,0 +1,5 @@
+use indoc::printdoc;
+
+fn main() {
+ printdoc!("{named}");
+}
diff --git a/vendor/indoc/tests/ui/printdoc-no-named-arg.stderr b/vendor/indoc/tests/ui/printdoc-no-named-arg.stderr
new file mode 100644
index 000000000..bed418d92
--- /dev/null
+++ b/vendor/indoc/tests/ui/printdoc-no-named-arg.stderr
@@ -0,0 +1,5 @@
+error[E0425]: cannot find value `named` in this scope
+ --> tests/ui/printdoc-no-named-arg.rs:4:17
+ |
+4 | printdoc!("{named}");
+ | ^^^^^ not found in this scope
diff --git a/vendor/indoc/tests/ui/three-arguments.rs b/vendor/indoc/tests/ui/three-arguments.rs
new file mode 100644
index 000000000..7bd11e2d2
--- /dev/null
+++ b/vendor/indoc/tests/ui/three-arguments.rs
@@ -0,0 +1,9 @@
+use indoc::indoc;
+
+fn main() {
+ indoc!("
+ a
+ b
+ c
+ " 64 128);
+}
diff --git a/vendor/indoc/tests/ui/three-arguments.stderr b/vendor/indoc/tests/ui/three-arguments.stderr
new file mode 100644
index 000000000..d3e8dbe65
--- /dev/null
+++ b/vendor/indoc/tests/ui/three-arguments.stderr
@@ -0,0 +1,5 @@
+error: unexpected tokens in macro invocation; indoc argument must be a single string literal
+ --> tests/ui/three-arguments.rs:8:11
+ |
+8 | " 64 128);
+ | ^^^^^^
diff --git a/vendor/indoc/tests/ui/two-arguments.rs b/vendor/indoc/tests/ui/two-arguments.rs
new file mode 100644
index 000000000..f979fed42
--- /dev/null
+++ b/vendor/indoc/tests/ui/two-arguments.rs
@@ -0,0 +1,9 @@
+use indoc::indoc;
+
+fn main() {
+ indoc!("
+ a
+ b
+ c
+ " 64);
+}
diff --git a/vendor/indoc/tests/ui/two-arguments.stderr b/vendor/indoc/tests/ui/two-arguments.stderr
new file mode 100644
index 000000000..eccdecfca
--- /dev/null
+++ b/vendor/indoc/tests/ui/two-arguments.stderr
@@ -0,0 +1,5 @@
+error: unexpected token in macro invocation; indoc argument must be a single string literal
+ --> tests/ui/two-arguments.rs:8:11
+ |
+8 | " 64);
+ | ^^