]>
git.proxmox.com Git - cargo.git/blob - vendor/textwrap/tests/indent.rs
1 /// tests cases ported over from python standard library
2 use textwrap
::{dedent, indent}
;
4 const ROUNDTRIP_CASES
: [&str; 3] = [
6 "Hi.\nThis is a test.\nTesting.",
7 // include a blank line
8 "Hi.\nThis is a test.\n\nTesting.",
9 // include leading and trailing blank lines
10 "\nHi.\nThis is a test.\nTesting.\n",
13 const WINDOWS_CASES
: [&str; 2] = [
14 // use windows line endings
15 "Hi.\r\nThis is a test.\r\nTesting.",
17 "Hi.\r\nThis is a test.\n\r\nTesting.\r\n\n",
21 fn test_indent_nomargin_default() {
22 // indent should do nothing if 'prefix' is empty.
23 for text
in ROUNDTRIP_CASES
.iter() {
24 assert_eq
!(&indent(text
, ""), text
);
26 for text
in WINDOWS_CASES
.iter() {
27 assert_eq
!(&indent(text
, ""), text
);
32 fn test_roundtrip_spaces() {
33 // A whitespace prefix should roundtrip with dedent
34 for text
in ROUNDTRIP_CASES
.iter() {
35 assert_eq
!(&dedent(&indent(text
, " ")), text
);
40 fn test_roundtrip_tabs() {
41 // A whitespace prefix should roundtrip with dedent
42 for text
in ROUNDTRIP_CASES
.iter() {
43 assert_eq
!(&dedent(&indent(text
, "\t\t")), text
);
48 fn test_roundtrip_mixed() {
49 // A whitespace prefix should roundtrip with dedent
50 for text
in ROUNDTRIP_CASES
.iter() {
51 assert_eq
!(&dedent(&indent(text
, " \t \t ")), text
);
56 fn test_indent_default() {
57 // Test default indenting of lines that are not whitespace only
61 " Hi.\n This is a test.\n Testing.",
62 // Include a blank line
63 " Hi.\n This is a test.\n\n Testing.",
64 // Include leading and trailing blank lines
65 "\n Hi.\n This is a test.\n Testing.\n",
67 for (text
, expect
) in ROUNDTRIP_CASES
.iter().zip(expected
.iter()) {
68 assert_eq
!(&indent(text
, prefix
), expect
)
71 // Use Windows line endings
72 " Hi.\r\n This is a test.\r\n Testing.",
74 " Hi.\r\n This is a test.\n\r\n Testing.\r\n\n",
76 for (text
, expect
) in WINDOWS_CASES
.iter().zip(expected
.iter()) {
77 assert_eq
!(&indent(text
, prefix
), expect
)
82 fn indented_text_should_have_the_same_number_of_lines_as_the_original_text() {
83 let texts
= ["foo\nbar", "foo\nbar\n", "foo\nbar\nbaz"];
84 for original
in texts
.iter() {
85 let indented
= indent(original
, "");
86 assert_eq
!(&indented
, original
);