Repository: sharkdp/bat
File: src/less.rs (Rust)

Code before:
Home page: http://www.greenwoodsoftware.com/less";

    assert_eq!(Some(LessVersion::Less(551)), parse_less_version(output));
}

#[test]
fn test_parse_less_version_581_2() {
    let output = b"less 581.2 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less";

    assert_eq!(Some(LessVersion::Less(581)), parse_less_version(output));
}

#[test]
fn test_parse_less_version_wrong_program() {
    let output = b"more from util-linux 2.34";

    assert_eq!(None, parse_less_version(output));
}

#[test]
fn test_parse_less_version_busybox() {
    let output = b"pkg/less: unrecognized option '--version'
BusyBox v1.35.0 (2022-04-21 10:38:11 EDT) multi-call binary.

Usage: less [-EFIMmNSRh~] [FILE]...

View FILE (or stdin) one screenful at a time

        -E      Quit once the end of a file is reached
        -F      Quit if entire file fits on first screen
        -I      Ignore case in all searches
        -M,-m   Display status line with line numbers
                and percentage through the file
        -N      Prefix line number to each line
        -S      Truncate long lines
        -R      Remove color escape codes in input
        -~      Suppress ~s displayed past EOF";

    assert_eq!(
        Some(LessVersion::BusyBox),
        parse_less_version_busybox(output)
    );
}


Review comment (bug):
Can you add this test too please? After making the code compile:

```
#[test]
fn test_parse_less_version_invalid_utf_8() {
    let output = b"\xff";

    assert_eq!(None, parse_less_version(output));
    assert_eq!(None, parse_less_version_busybox(output));
}
```

Also please add an assert for `parse_less_version_busybox()` to `test_parse_less_version_wrong_program()`.

Code after:
Home page: http://www.greenwoodsoftware.com/less";

    assert_eq!(Some(LessVersion::Less(551)), parse_less_version(output));
}

#[test]
fn test_parse_less_version_581_2() {
    let output = b"less 581.2 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less";

    assert_eq!(Some(LessVersion::Less(581)), parse_less_version(output));
}

#[test]
fn test_parse_less_version_wrong_program() {
    let output = b"more from util-linux 2.34";

    assert_eq!(None, parse_less_version(output));
    assert_eq!(None, parse_less_version_busybox(output));
}

#[test]
fn test_parse_less_version_busybox() {
    let output = b"pkg/less: unrecognized option '--version'
BusyBox v1.35.0 (2022-04-21 10:38:11 EDT) multi-call binary.

Usage: less [-EFIMmNSRh~] [FILE]...

View FILE (or stdin) one screenful at a time

        -E      Quit once the end of a file is reached
        -F      Quit if entire file fits on first screen
        -I      Ignore case in all searches
        -M,-m   Display status line with line numbers
                and percentage through the file
        -N      Prefix line number to each line
        -S      Truncate long lines
        -R      Remove color escape codes in input
        -~      Suppress ~s displayed past EOF";

    assert_eq!(
        Some(LessVersion::BusyBox),
        parse_less_version_busybox(output)
    );
}