#![cfg(test)]
use docstr::docstr;
const AGE: u32 = 19;
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}
#[test]
fn empty() {
const A: &str = docstr!(
);
assert_eq!(A, "");
}
#[test]
fn full_path() {
assert_eq!(
docstr!(std::format!
),
"foo\nbar"
);
assert_eq!(
docstr!(::std::concat!
"hello"
),
"foo\nbarhello"
);
}
#[test]
fn constant() {
const A: &str = docstr!(
);
assert_eq!(A, "foo\nbar", "join with newline");
const B: &str = docstr!(
);
assert_eq!(B, "foo\nbar\n", "newline at end");
}
#[test]
fn format() {
assert_eq!(
docstr!(format!
"Bob"
),
format!("Hello, my name is Bob\nand I am {AGE} years old")
);
}
#[test]
fn fake_interpolation() {
assert_eq!(
docstr!(
),
"I am {AGE} years old"
);
}
#[test]
fn formatln() {
macro_rules! formatln {
($($tt:tt)*) => {
format!($($tt)*) + "\n"
};
}
assert_eq!(
docstr!(
formatln!
"Bob"
),
format!("Hello, my name is Bob\nand I am {AGE} years old\n")
);
}
#[test]
fn writeln() {
let name = "dave";
use std::fmt::Write as _;
let mut s = String::new();
docstr!(writeln! s
)
.unwrap();
assert_eq!(s, "hello\ndave\n");
let mut s = String::new();
docstr!(writeln! s,
name, name
)
.unwrap();
assert_eq!(s, "hello\ndave dave\n");
}
#[test]
fn escape() {
assert_eq!(
docstr!(
),
"hello \"world\" ' \\ ! ()\n///\\\\/\\// \\u{0032}"
);
}