2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_default_80_column_wrap() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg("lorem_ipsum.txt")
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_80_column.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_40_column_hard_cutoff() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-08-13 21:59:21 +00:00
|
|
|
.args(&["-w", "40", "lorem_ipsum.txt"])
|
2016-07-29 21:26:32 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_40_column_hard.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_40_column_word_boundary() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-08-13 21:59:21 +00:00
|
|
|
.args(&["-s", "-w", "40", "lorem_ipsum.txt"])
|
2016-07-29 21:26:32 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_40_column_word.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2021-01-05 08:10:01 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-04-02 13:13:25 +00:00
|
|
|
fn test_default_wrap_with_newlines() {
|
2021-01-05 08:10:01 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("lorem_ipsum_new_line.txt")
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_new_line_80_column.expected");
|
|
|
|
}
|
2021-04-02 13:13:25 +00:00
|
|
|
|
2021-04-02 12:47:04 +00:00
|
|
|
#[test]
|
|
|
|
fn test_should_preserve_empty_line_without_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("12\n\n34")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n\n34");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_preserve_empty_line_and_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("12\n\n34\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n\n34\n");
|
|
|
|
}
|
|
|
|
|
2021-04-02 13:13:25 +00:00
|
|
|
#[test]
|
|
|
|
fn test_should_preserve_empty_lines() {
|
|
|
|
new_ucmd!().pipe_in("\n").succeeds().stdout_is("\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w1")
|
|
|
|
.pipe_in("0\n1\n\n2\n\n\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("0\n1\n\n2\n\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_word_boundary_split_should_preserve_empty_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-s")
|
|
|
|
.pipe_in("\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w1", "-s"])
|
|
|
|
.pipe_in("0\n1\n\n2\n\n\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("0\n1\n\n2\n\n\n");
|
|
|
|
}
|
2021-04-02 12:47:04 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_not_add_newline_when_line_less_than_fold() {
|
|
|
|
new_ucmd!().pipe_in("1234").succeeds().stdout_is("1234");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_not_add_newline_when_line_longer_than_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("1234")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n34");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_not_add_newline_when_line_equal_to_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w1")
|
|
|
|
.pipe_in(" ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_preserve_final_newline_when_line_less_than_fold() {
|
|
|
|
new_ucmd!().pipe_in("1234\n").succeeds().stdout_is("1234\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_preserve_final_newline_when_line_longer_than_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("1234\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n34\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_should_preserve_final_newline_when_line_equal_to_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("1\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_tab_should_not_add_extra_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w1")
|
|
|
|
.pipe_in("\t")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\t");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-04-05 04:16:21 +00:00
|
|
|
fn test_initial_tab_counts_as_8_columns() {
|
2021-04-02 12:47:04 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w8")
|
|
|
|
.pipe_in("\t1")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\t\n1");
|
|
|
|
}
|
|
|
|
|
2021-04-05 04:16:21 +00:00
|
|
|
#[test]
|
|
|
|
fn test_tab_should_advance_to_next_tab_stop() {
|
|
|
|
// tab advances the column count to the next tab stop, i.e. the width
|
|
|
|
// of the tab varies based on the leading text
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w8", "tab_stops.input"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is_fixture("tab_stops_w8.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_all_tabs_should_advance_to_next_tab_stops() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w16", "tab_stops.input"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is_fixture("tab_stops_w16.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_before_tab_with_narrow_width() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w7")
|
|
|
|
.pipe_in("a\t1")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\n\t\n1");
|
|
|
|
}
|
|
|
|
|
2021-04-02 12:47:04 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fold_at_word_boundary() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w4", "-s"])
|
|
|
|
.pipe_in("one two")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("one \ntwo");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_at_leading_word_boundary() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w3", "-s"])
|
|
|
|
.pipe_in(" aaa")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" \naaa");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_at_word_boundary_preserve_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w4", "-s"])
|
|
|
|
.pipe_in("one two\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("one \ntwo\n");
|
|
|
|
}
|
|
|
|
|
2021-04-05 04:16:21 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fold_at_tab() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w8")
|
|
|
|
.pipe_in("a\tbbb\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\t\nbbb\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_after_tab() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w10")
|
|
|
|
.pipe_in("a\tbbb\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\tbb\nb\n");
|
|
|
|
}
|
|
|
|
|
2021-04-02 12:47:04 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fold_at_tab_as_word_boundary() {
|
2021-04-05 04:16:21 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w8", "-s"])
|
|
|
|
.pipe_in("a\tbbb\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\t\nbbb\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_after_tab_as_word_boundary() {
|
2021-04-02 12:47:04 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w10", "-s"])
|
|
|
|
.pipe_in("a\tbbb\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\t\nbbb\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_at_word_boundary_only_whitespace() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-s"])
|
|
|
|
.pipe_in(" ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" \n ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fold_at_word_boundary_only_whitespace_preserve_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-s"])
|
|
|
|
.pipe_in(" \n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" \n \n");
|
|
|
|
}
|
|
|
|
|
2021-04-06 00:39:43 +00:00
|
|
|
#[test]
|
|
|
|
fn test_backspace_should_be_preserved() {
|
|
|
|
new_ucmd!().pipe_in("\x08").succeeds().stdout_is("\x08");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_backspaced_char_should_be_preserved() {
|
|
|
|
new_ucmd!().pipe_in("x\x08").succeeds().stdout_is("x\x08");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_backspace_should_decrease_column_count() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("1\x08345")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1\x0834\n5");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_backspace_should_not_decrease_column_count_past_zero() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-w2")
|
|
|
|
.pipe_in("1\x08\x083456")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1\x08\x0834\n56");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_backspace_is_not_word_boundary() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w10", "-s"])
|
|
|
|
.pipe_in("foobar\x086789abcdef")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("foobar\x086789a\nbcdef");
|
|
|
|
}
|
|
|
|
|
2021-04-02 12:47:04 +00:00
|
|
|
//
|
|
|
|
// bytewise tests
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_preserve_empty_line_without_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("123\n\n45")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n3\n\n45");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_preserve_empty_line_and_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("12\n\n34\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n\n34\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_preserve_empty_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-b")
|
|
|
|
.pipe_in("\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w1", "-b"])
|
|
|
|
.pipe_in("0\n1\n\n2\n\n\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("0\n1\n\n2\n\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_word_boundary_split_should_preserve_empty_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "-b"])
|
|
|
|
.pipe_in("\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w1", "-s", "-b"])
|
|
|
|
.pipe_in("0\n1\n\n2\n\n\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("0\n1\n\n2\n\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_not_add_newline_when_line_less_than_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-b")
|
|
|
|
.pipe_in("1234")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1234");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_not_add_newline_when_line_longer_than_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("1234")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n34");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_not_add_newline_when_line_equal_to_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w1", "-b"])
|
|
|
|
.pipe_in(" ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_preserve_final_newline_when_line_less_than_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-b")
|
|
|
|
.pipe_in("1234\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1234\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_preserve_final_newline_when_line_longer_than_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("1234\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("12\n34\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_should_preserve_final_newline_when_line_equal_to_fold() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("1\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_single_tab_should_not_add_extra_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w1", "-b"])
|
|
|
|
.pipe_in("\t")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\t");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tab_counts_as_one_byte() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("1\t2\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1\t\n2\n");
|
|
|
|
}
|
|
|
|
|
2021-04-05 04:16:21 +00:00
|
|
|
#[test]
|
|
|
|
fn test_bytewise_fold_before_tab_with_narrow_width() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w7", "-b"])
|
|
|
|
.pipe_in("a\t1")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\t1");
|
|
|
|
}
|
|
|
|
|
2021-04-02 12:47:04 +00:00
|
|
|
#[test]
|
|
|
|
fn test_bytewise_fold_at_word_boundary_only_whitespace() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-s", "-b"])
|
|
|
|
.pipe_in(" ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" \n ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_fold_at_word_boundary_only_whitespace_preserve_final_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-s", "-b"])
|
|
|
|
.pipe_in(" \n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" \n \n");
|
|
|
|
}
|
2021-04-06 00:39:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_backspace_should_be_preserved() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-b")
|
|
|
|
.pipe_in("\x08")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\x08");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_backspaced_char_should_be_preserved() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-b")
|
|
|
|
.pipe_in("x\x08")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("x\x08");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_backspace_should_not_decrease_column_count() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w2", "-b"])
|
|
|
|
.pipe_in("1\x08345")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1\x08\n34\n5");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bytewise_backspace_is_not_word_boundary() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-w10", "-s", "-b"])
|
|
|
|
.pipe_in("foobar\x0889abcdef")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("foobar\x0889a\nbcdef");
|
|
|
|
}
|