diff --git a/src/pr/pr.rs b/src/pr/pr.rs index 20db63d1b..afcc54164 100644 --- a/src/pr/pr.rs +++ b/src/pr/pr.rs @@ -37,6 +37,7 @@ static NUMBERING_MODE_DEFAULT_WIDTH: usize = 5; static STRING_HEADER_OPTION: &str = "h"; static DOUBLE_SPACE_OPTION: &str = "d"; static NUMBERING_MODE_OPTION: &str = "n"; +static FIRST_LINE_NUMBER_OPTION: &str = "N"; static PAGE_RANGE_OPTION: &str = "pages"; static NO_HEADER_TRAILER_OPTION: &str = "t"; static PAGE_LENGTH_OPTION: &str = "l"; @@ -101,6 +102,7 @@ struct NumberingMode { /// Line numbering mode width: usize, separator: String, + first_number: usize, } impl Default for NumberingMode { @@ -108,6 +110,7 @@ impl Default for NumberingMode { NumberingMode { width: NUMBERING_MODE_DEFAULT_WIDTH, separator: NUMBERING_MODE_DEFAULT_SEPARATOR.to_string(), + first_number: 1, } } } @@ -189,7 +192,7 @@ pub fn uumain(args: Vec) -> i32 { opts.opt( NUMBERING_MODE_OPTION, - "--number-lines", + "number-lines", "Provide width digit line numbering. The default for width, if not specified, is 5. The number occupies the first width column positions of each text column or each line of -m output. If char (any nondigit character) is given, it is appended to the line number to separate it from whatever follows. The default @@ -199,6 +202,15 @@ pub fn uumain(args: Vec) -> i32 { Occur::Optional, ); + opts.opt( + FIRST_LINE_NUMBER_OPTION, + "first-line-number", + "start counting with NUMBER at 1st line of first page printed", + "NUMBER", + HasArg::Yes, + Occur::Optional, + ); + opts.opt( NO_HEADER_TRAILER_OPTION, "omit-header", @@ -279,12 +291,13 @@ pub fn uumain(args: Vec) -> i32 { if files.is_empty() { // -n value is optional if -n is given the opts gets confused if matches.opt_present(NUMBERING_MODE_OPTION) { - let is_afile = is_a_file(&matches, &mut files); - if is_afile.is_err() { - writeln!(&mut stderr(), "{}", is_afile.err().unwrap()); + let maybe_file = matches.opt_str(NUMBERING_MODE_OPTION).unwrap(); + let is_afile = is_a_file(&maybe_file); + if !is_afile { + writeln!(&mut stderr(), "{}", PrError::NotExists(maybe_file)); return 1; } else { - files.push(is_afile.unwrap()); + files.push(maybe_file); } } else { //For stdin @@ -320,12 +333,8 @@ pub fn uumain(args: Vec) -> i32 { return 0; } -fn is_a_file(matches: &Matches, files: &mut Vec) -> Result { - let could_be_file = matches.opt_str(NUMBERING_MODE_OPTION).unwrap(); - match File::open(&could_be_file) { - Ok(f) => Ok(could_be_file), - Err(e) => Err(PrError::NotExists(could_be_file)) - } +fn is_a_file(could_be_file: &String) -> bool { + File::open(could_be_file).is_ok() } fn print_usage(opts: &mut Options, matches: &Matches) -> i32 { @@ -365,10 +374,39 @@ fn print_usage(opts: &mut Options, matches: &Matches) -> i32 { fn build_options(matches: &Matches, path: &String) -> Result { let header: String = matches.opt_str(STRING_HEADER_OPTION).unwrap_or(path.to_string()); + + let default_first_number = NumberingMode::default().first_number; + let first_number = matches.opt_str(FIRST_LINE_NUMBER_OPTION).map(|n| { + n.parse::().unwrap_or(default_first_number) + }).unwrap_or(default_first_number); + let numbering_options: Option = matches.opt_str(NUMBERING_MODE_OPTION).map(|i| { + let parse_result = i.parse::(); + + let separator = if parse_result.is_err() { + if is_a_file(&i) { + NumberingMode::default().separator + } else { + i[0..1].to_string() + } + } else { + NumberingMode::default().separator + }; + + let width = if parse_result.is_err() { + if is_a_file(&i) { + NumberingMode::default().width + } else { + i[1..].parse::().unwrap_or(NumberingMode::default().width) + } + } else { + parse_result.unwrap() + }; + NumberingMode { - width: i.parse::().unwrap_or(NumberingMode::default().width), - separator: NumberingMode::default().separator, + width, + separator, + first_number, } }).or_else(|| { if matches.opt_present(NUMBERING_MODE_OPTION) { @@ -510,7 +548,11 @@ fn pr(path: &str, options: &OutputOptions) -> Result { let mut page: usize = 0; let mut buffered_content: Vec = Vec::new(); let read_lines_per_page = options.lines_to_read_for_page(); - let mut line_number = 0; + let mut line_number = options.as_ref() + .number + .as_ref() + .map(|i| i.first_number) + .unwrap_or(1) - 1; for line in BufReader::with_capacity(READ_BUFFER_SIZE, open(path)?).lines() { if i == read_lines_per_page { page = page + 1; diff --git a/tests/fixtures/pr/test_num_page_char.log.expected b/tests/fixtures/pr/test_num_page_char.log.expected new file mode 100644 index 000000000..169dbd844 --- /dev/null +++ b/tests/fixtures/pr/test_num_page_char.log.expected @@ -0,0 +1,132 @@ + + +{last_modified_time} test_num_page.log Page 1 + + + 1cntation processAirPortStateChanges]: pppConnectionState 0 + 2cMon Dec 10 11:42:56.558 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 3cMon Dec 10 11:42:56.705 Info: 802.1X changed + 4cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 5cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 6cMon Dec 10 11:42:56.854 Info: 802.1X changed + 7cMon Dec 10 11:42:56.855 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 8cMon Dec 10 11:42:56.856 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 9cMon Dec 10 11:42:57.002 Info: 802.1X changed + 10cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 11cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 12cMon Dec 10 11:42:57.152 Info: 802.1X changed + 13cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 14cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 15cMon Dec 10 11:42:57.302 Info: 802.1X changed + 16cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 17cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 18cMon Dec 10 11:42:57.449 Info: 802.1X changed + 19cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 20cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 21cMon Dec 10 11:42:57.600 Info: 802.1X changed + 22cMon Dec 10 11:42:57.601 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 23cMon Dec 10 11:42:57.602 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 24cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 25cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 26cMon Dec 10 11:42:57.749 Info: 802.1X changed + 27cMon Dec 10 11:42:57.750 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 28cMon Dec 10 11:42:57.751 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 29cMon Dec 10 11:42:57.896 Info: 802.1X changed + 30cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 31cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 32cMon Dec 10 11:42:58.045 Info: 802.1X changed + 33cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 34cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 35cMon Dec 10 11:42:58.193 Info: 802.1X changed + 36cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 37cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 38cMon Dec 10 11:42:58.342 Info: 802.1X changed + 39cMon Dec 10 11:42:58.343 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 40cMon Dec 10 11:42:58.344 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 41cMon Dec 10 11:42:58.491 Info: 802.1X changed + 42cMon Dec 10 11:42:58.493 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 43cMon Dec 10 11:42:58.494 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 44cMon Dec 10 11:42:58.640 Info: 802.1X changed + 45cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 46cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 47cMon Dec 10 11:42:58.805 Info: 802.1X changed + 48cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 49cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 50cMon Dec 10 11:42:58.958 Info: 802.1X changed + 51cMon Dec 10 11:42:58.959 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 52cMon Dec 10 11:42:58.960 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 53cMon Dec 10 11:42:59.155 Info: 802.1X changed + 54cMon Dec 10 11:42:59.157 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 55cMon Dec 10 11:42:59.159 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 56cMon Dec 10 11:42:59.352 Info: 802.1X changed + + + + + + + +{last_modified_time} test_num_page.log Page 2 + + + 57cntation processAirPortStateChanges]: pppConnectionState 0 + 58cMon Dec 10 11:42:56.558 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 59cMon Dec 10 11:42:56.705 Info: 802.1X changed + 60cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 61cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 62cMon Dec 10 11:42:56.854 Info: 802.1X changed + 63cMon Dec 10 11:42:56.855 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 64cMon Dec 10 11:42:56.856 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 65cMon Dec 10 11:42:57.002 Info: 802.1X changed + 66cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 67cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 68cMon Dec 10 11:42:57.152 Info: 802.1X changed + 69cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 70cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 71cMon Dec 10 11:42:57.302 Info: 802.1X changed + 72cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 73cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 74cMon Dec 10 11:42:57.449 Info: 802.1X changed + 75cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 76cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 77cMon Dec 10 11:42:57.600 Info: 802.1X changed + 78cMon Dec 10 11:42:57.601 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 79cMon Dec 10 11:42:57.602 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 80cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 81cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 82cMon Dec 10 11:42:57.749 Info: 802.1X changed + 83cMon Dec 10 11:42:57.750 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 84cMon Dec 10 11:42:57.751 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 85cMon Dec 10 11:42:57.896 Info: 802.1X changed + 86cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 87cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 88cMon Dec 10 11:42:58.045 Info: 802.1X changed + 89cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 90cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 91cMon Dec 10 11:42:58.193 Info: 802.1X changed + 92cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 93cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 94cMon Dec 10 11:42:58.342 Info: 802.1X changed + 95cMon Dec 10 11:42:58.343 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 96cMon Dec 10 11:42:58.344 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 97cMon Dec 10 11:42:58.491 Info: 802.1X changed + 98cMon Dec 10 11:42:58.493 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 99cMon Dec 10 11:42:58.494 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 100cMon Dec 10 11:42:58.640 Info: 802.1X changed + 101cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 102cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 103cMon Dec 10 11:42:58.805 Info: 802.1X changed + 104cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 105cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 106cMon Dec 10 11:42:58.958 Info: 802.1X changed + 107cMon Dec 10 11:42:58.959 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 108cMon Dec 10 11:42:58.960 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 109cMon Dec 10 11:42:59.155 Info: 802.1X changed + 110cMon Dec 10 11:42:59.157 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 111cMon Dec 10 11:42:59.159 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 112cMon Dec 10 11:42:59.352 Info: 802.1X changed + + + + + diff --git a/tests/fixtures/pr/test_num_page_char_one.log.expected b/tests/fixtures/pr/test_num_page_char_one.log.expected new file mode 100644 index 000000000..dd7813192 --- /dev/null +++ b/tests/fixtures/pr/test_num_page_char_one.log.expected @@ -0,0 +1,132 @@ + + +{last_modified_time} test_num_page.log Page 1 + + +1cntation processAirPortStateChanges]: pppConnectionState 0 +2cMon Dec 10 11:42:56.558 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +3cMon Dec 10 11:42:56.705 Info: 802.1X changed +4cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +5cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +6cMon Dec 10 11:42:56.854 Info: 802.1X changed +7cMon Dec 10 11:42:56.855 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +8cMon Dec 10 11:42:56.856 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +9cMon Dec 10 11:42:57.002 Info: 802.1X changed +0cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +1cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +2cMon Dec 10 11:42:57.152 Info: 802.1X changed +3cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +4cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +5cMon Dec 10 11:42:57.302 Info: 802.1X changed +6cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +7cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +8cMon Dec 10 11:42:57.449 Info: 802.1X changed +9cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +0cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +1cMon Dec 10 11:42:57.600 Info: 802.1X changed +2cMon Dec 10 11:42:57.601 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +3cMon Dec 10 11:42:57.602 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +4cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +5cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +6cMon Dec 10 11:42:57.749 Info: 802.1X changed +7cMon Dec 10 11:42:57.750 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +8cMon Dec 10 11:42:57.751 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +9cMon Dec 10 11:42:57.896 Info: 802.1X changed +0cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +1cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +2cMon Dec 10 11:42:58.045 Info: 802.1X changed +3cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +4cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +5cMon Dec 10 11:42:58.193 Info: 802.1X changed +6cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +7cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +8cMon Dec 10 11:42:58.342 Info: 802.1X changed +9cMon Dec 10 11:42:58.343 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +0cMon Dec 10 11:42:58.344 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +1cMon Dec 10 11:42:58.491 Info: 802.1X changed +2cMon Dec 10 11:42:58.493 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +3cMon Dec 10 11:42:58.494 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +4cMon Dec 10 11:42:58.640 Info: 802.1X changed +5cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +6cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +7cMon Dec 10 11:42:58.805 Info: 802.1X changed +8cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +9cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +0cMon Dec 10 11:42:58.958 Info: 802.1X changed +1cMon Dec 10 11:42:58.959 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +2cMon Dec 10 11:42:58.960 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +3cMon Dec 10 11:42:59.155 Info: 802.1X changed +4cMon Dec 10 11:42:59.157 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +5cMon Dec 10 11:42:59.159 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +6cMon Dec 10 11:42:59.352 Info: 802.1X changed + + + + + + + +{last_modified_time} test_num_page.log Page 2 + + +7cntation processAirPortStateChanges]: pppConnectionState 0 +8cMon Dec 10 11:42:56.558 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +9cMon Dec 10 11:42:56.705 Info: 802.1X changed +0cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +1cMon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +2cMon Dec 10 11:42:56.854 Info: 802.1X changed +3cMon Dec 10 11:42:56.855 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +4cMon Dec 10 11:42:56.856 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +5cMon Dec 10 11:42:57.002 Info: 802.1X changed +6cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +7cMon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +8cMon Dec 10 11:42:57.152 Info: 802.1X changed +9cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +0cMon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +1cMon Dec 10 11:42:57.302 Info: 802.1X changed +2cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +3cMon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +4cMon Dec 10 11:42:57.449 Info: 802.1X changed +5cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +6cMon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +7cMon Dec 10 11:42:57.600 Info: 802.1X changed +8cMon Dec 10 11:42:57.601 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +9cMon Dec 10 11:42:57.602 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +0cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +1cMon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +2cMon Dec 10 11:42:57.749 Info: 802.1X changed +3cMon Dec 10 11:42:57.750 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +4cMon Dec 10 11:42:57.751 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +5cMon Dec 10 11:42:57.896 Info: 802.1X changed +6cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +7cMon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +8cMon Dec 10 11:42:58.045 Info: 802.1X changed +9cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +0cMon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +1cMon Dec 10 11:42:58.193 Info: 802.1X changed +2cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +3cMon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +4cMon Dec 10 11:42:58.342 Info: 802.1X changed +5cMon Dec 10 11:42:58.343 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +6cMon Dec 10 11:42:58.344 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +7cMon Dec 10 11:42:58.491 Info: 802.1X changed +8cMon Dec 10 11:42:58.493 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +9cMon Dec 10 11:42:58.494 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +0cMon Dec 10 11:42:58.640 Info: 802.1X changed +1cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +2cMon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +3cMon Dec 10 11:42:58.805 Info: 802.1X changed +4cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +5cMon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +6cMon Dec 10 11:42:58.958 Info: 802.1X changed +7cMon Dec 10 11:42:58.959 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +8cMon Dec 10 11:42:58.960 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +9cMon Dec 10 11:42:59.155 Info: 802.1X changed +0cMon Dec 10 11:42:59.157 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 +1cMon Dec 10 11:42:59.159 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars +2cMon Dec 10 11:42:59.352 Info: 802.1X changed + + + + + diff --git a/tests/fixtures/pr/test_one_page_first_line.log.expected b/tests/fixtures/pr/test_one_page_first_line.log.expected new file mode 100644 index 000000000..303f01c73 --- /dev/null +++ b/tests/fixtures/pr/test_one_page_first_line.log.expected @@ -0,0 +1,66 @@ + + +{last_modified_time} test_one_page.log Page 1 + + + 5 ntation processAirPortStateChanges]: pppConnectionState 0 + 6 Mon Dec 10 11:42:56.558 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 7 Mon Dec 10 11:42:56.705 Info: 802.1X changed + 8 Mon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 9 Mon Dec 10 11:42:56.706 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 10 Mon Dec 10 11:42:56.854 Info: 802.1X changed + 11 Mon Dec 10 11:42:56.855 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 12 Mon Dec 10 11:42:56.856 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 13 Mon Dec 10 11:42:57.002 Info: 802.1X changed + 14 Mon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 15 Mon Dec 10 11:42:57.003 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 16 Mon Dec 10 11:42:57.152 Info: 802.1X changed + 17 Mon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 18 Mon Dec 10 11:42:57.154 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 19 Mon Dec 10 11:42:57.302 Info: 802.1X changed + 20 Mon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 21 Mon Dec 10 11:42:57.304 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 22 Mon Dec 10 11:42:57.449 Info: 802.1X changed + 23 Mon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 24 Mon Dec 10 11:42:57.451 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 25 Mon Dec 10 11:42:57.600 Info: 802.1X changed + 26 Mon Dec 10 11:42:57.601 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 27 Mon Dec 10 11:42:57.602 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 28 Mon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 29 Mon Dec 10 11:42:57.624 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 30 Mon Dec 10 11:42:57.749 Info: 802.1X changed + 31 Mon Dec 10 11:42:57.750 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 32 Mon Dec 10 11:42:57.751 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 33 Mon Dec 10 11:42:57.896 Info: 802.1X changed + 34 Mon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 35 Mon Dec 10 11:42:57.897 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 36 Mon Dec 10 11:42:58.045 Info: 802.1X changed + 37 Mon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 38 Mon Dec 10 11:42:58.047 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 39 Mon Dec 10 11:42:58.193 Info: 802.1X changed + 40 Mon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 41 Mon Dec 10 11:42:58.195 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 42 Mon Dec 10 11:42:58.342 Info: 802.1X changed + 43 Mon Dec 10 11:42:58.343 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 44 Mon Dec 10 11:42:58.344 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 45 Mon Dec 10 11:42:58.491 Info: 802.1X changed + 46 Mon Dec 10 11:42:58.493 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 47 Mon Dec 10 11:42:58.494 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 48 Mon Dec 10 11:42:58.640 Info: 802.1X changed + 49 Mon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 50 Mon Dec 10 11:42:58.642 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 51 Mon Dec 10 11:42:58.805 Info: 802.1X changed + 52 Mon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 53 Mon Dec 10 11:42:58.806 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 54 Mon Dec 10 11:42:58.958 Info: 802.1X changed + 55 Mon Dec 10 11:42:58.959 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 56 Mon Dec 10 11:42:58.960 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 57 Mon Dec 10 11:42:59.155 Info: 802.1X changed + 58 Mon Dec 10 11:42:59.157 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 + 59 Mon Dec 10 11:42:59.159 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars + 60 Mon Dec 10 11:42:59.352 Info: 802.1X changed + + + + + diff --git a/tests/test_pr.rs b/tests/test_pr.rs index bb068181d..fb4523c0c 100644 --- a/tests/test_pr.rs +++ b/tests/test_pr.rs @@ -123,4 +123,60 @@ fn test_with_long_double_space_option() { .stdout_is_templated_fixture(expected_test_file_path, vec![ ("{last_modified_time}".to_string(), value), ]); +} + +#[test] +fn test_with_first_line_number_option() { + let test_file_path = "test_one_page.log"; + let expected_test_file_path = "test_one_page_first_line.log.expected"; + let mut scenario = new_ucmd!(); + let value = file_last_modified_time(&scenario, test_file_path); + scenario + .args(&["-N", "5", "-n", test_file_path]) + .succeeds() + .stdout_is_templated_fixture(expected_test_file_path, vec![ + ("{last_modified_time}".to_string(), value), + ]); +} + +#[test] +fn test_with_first_line_number_long_option() { + let test_file_path = "test_one_page.log"; + let expected_test_file_path = "test_one_page_first_line.log.expected"; + let mut scenario = new_ucmd!(); + let value = file_last_modified_time(&scenario, test_file_path); + scenario + .args(&["--first-line-number=5", "-n", test_file_path]) + .succeeds() + .stdout_is_templated_fixture(expected_test_file_path, vec![ + ("{last_modified_time}".to_string(), value), + ]); +} + +#[test] +fn test_with_number_option_with_custom_separator_char() { + let test_file_path = "test_num_page.log"; + let expected_test_file_path = "test_num_page_char.log.expected"; + let mut scenario = new_ucmd!(); + let value = file_last_modified_time(&scenario, test_file_path); + scenario + .args(&["-nc", test_file_path]) + .succeeds() + .stdout_is_templated_fixture(expected_test_file_path, vec![ + ("{last_modified_time}".to_string(), value), + ]); +} + +#[test] +fn test_with_number_option_with_custom_separator_char_and_width() { + let test_file_path = "test_num_page.log"; + let expected_test_file_path = "test_num_page_char_one.log.expected"; + let mut scenario = new_ucmd!(); + let value = file_last_modified_time(&scenario, test_file_path); + scenario + .args(&["-nc1", test_file_path]) + .succeeds() + .stdout_is_templated_fixture(expected_test_file_path, vec![ + ("{last_modified_time}".to_string(), value), + ]); } \ No newline at end of file