Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add style from #691 to ide menu #722

Merged
merged 16 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
maxomatic458 committed Jan 19, 2024
commit b53ebc84468799ea9af2fc30f6359086717c4736
73 changes: 73 additions & 0 deletions src/painting/prompt_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,76 @@ impl<'prompt> PromptLines<'prompt> {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use rstest::rstest;

#[rstest]
#[case(
"~/path/",
"❯ ",
"",
100,
(9, 0)
)]
#[case(
"~/longer/path/\n",
"❯ ",
"test",
100,
(6, 0)
)]
#[case(
"~/longer/path/",
"\n❯ ",
"test",
100,
(6, 0)
)]
#[case(
"~/longer/path/\n",
"\n❯ ",
"test",
100,
(6, 0)
)]
#[case(
"~/path/",
"❯ ",
"very long input that does not fit in a single line",
40,
(19, 1)
)]
#[case(
"~/path/\n",
"\n❯\n ",
"very long input that does not fit in a single line",
10,
(1, 5)
)]

fn test_cursor_pos(
#[case] prompt_str_left: &str,
#[case] prompt_indicator: &str,
#[case] before_cursor: &str,
#[case] terminal_columns: u16,
#[case] expected: (u16, u16),
) {
let prompt_lines = PromptLines {
prompt_str_left: Cow::Borrowed(prompt_str_left),
prompt_str_right: Cow::Borrowed(""),
prompt_indicator: Cow::Borrowed(prompt_indicator),
before_cursor: Cow::Borrowed(before_cursor),
after_cursor: Cow::Borrowed(""),
hint: Cow::Borrowed(""),
right_prompt_on_last_line: false,
};

let pos = prompt_lines.cursor_pos(terminal_columns);

assert_eq!(pos, expected);
}
}
Loading