Skip to content

Commit

Permalink
fix: The tests are updated to 0.27
Browse files Browse the repository at this point in the history
  • Loading branch information
uttarayan21 committed Jun 24, 2024
1 parent ca1236d commit f4ee638
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
21 changes: 10 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,16 @@
});
};

devShells.default =
(craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell
({
buildInputs = [];
nativeBuildInputs = [];
packages = with pkgs; [
cargo-nextest
cargo-criterion
];
}
// commonArgs);
devShells.default = (craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell (commonArgs
// {
buildInputs = [];
nativeBuildInputs = [];
packages = with pkgs; [
cargo-nextest
cargo-criterion
cargo-outdated
];
});
}
);
}
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl From<AnsiStates> for tui::style::Style {

pub(crate) fn text(mut s: &[u8]) -> IResult<&[u8], Text<'static>> {
let mut lines = Vec::new();
let mut last = Default::default();
let mut last = Style::new();
while let Ok((_s, (line, style))) = line(last)(s) {
lines.push(line);
last = style;
Expand All @@ -96,7 +96,7 @@ pub(crate) fn text(mut s: &[u8]) -> IResult<&[u8], Text<'static>> {
#[cfg(feature = "zero-copy")]
pub(crate) fn text_fast(mut s: &[u8]) -> IResult<&[u8], Text<'_>> {
let mut lines = Vec::new();
let mut last = Default::default();
let mut last = Style::new();
while let Ok((_s, (line, style))) = line_fast(last)(s) {
lines.push(line);
last = style;
Expand All @@ -119,7 +119,7 @@ fn line(style: Style) -> impl Fn(&[u8]) -> IResult<&[u8], (Line<'static>, Style)
// Since reset now tracks seperately we can skip the reset check
last = last.patch(span.style);

if spans.is_empty() || !span.content.is_empty() {
if !span.content.is_empty() {
spans.push(span);
}
text = s;
Expand All @@ -144,7 +144,7 @@ fn line_fast(style: Style) -> impl Fn(&[u8]) -> IResult<&[u8], (Line<'_>, Style)
last = last.patch(span.style);
// If the spans is empty then it might be possible that the style changes
// but there is no text change
if spans.is_empty() || !span.content.is_empty() {
if !span.content.is_empty() {
spans.push(span);
}
text = s;
Expand Down
11 changes: 6 additions & 5 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,19 @@ fn test_screen_modes() {
#[test]
fn test_cursor_shape_and_color() {
// malformed -> malformed -> empty
let bytes: Vec<u8> = b"\x1b[4 q\x1b]12;#fab1ed\x07".to_vec();
let bytes = b"\x1b[4 q\x1b]12;#fab1ed\x07";
let output = Text::raw("");
test_both(bytes, output);
}

#[test]
fn test_malformed_simple() {
let bytes: Vec<u8> = b"\x1b[".to_vec();
let bytes = b"\x1b[";
let output = Text::raw("");
test_both(bytes, output);
}


#[test]
fn test_malformed_complex() {
let bytes: Vec<u8> = b"\x1b\x1b[0\x1b[m\x1b".to_vec();
Expand All @@ -116,7 +117,7 @@ fn empty_span() {
let bytes: Vec<u8> = b"\x1b[33m\x1b[31m\x1b[32mHello\x1b[0mWorld".to_vec();
let output = Text::from(Line::from(vec![
// Not sure whether to keep this empty span or remove it somehow
Span::styled("", Style::default().fg(Color::Yellow)),
// Span::styled("", Style::default().fg(Color::Yellow)),
// Span::styled("", Style::default().fg(Color::Red)),
Span::styled("Hello", Style::default().fg(Color::Green)),
Span::styled("World", Style::reset()),
Expand Down Expand Up @@ -155,7 +156,7 @@ pub fn test_both(bytes: impl AsRef<[u8]>, other: Text) {
let bytes = bytes.as_ref();
let zero_copy = bytes.to_text().unwrap();
let owned = bytes.into_text().unwrap();
assert_eq!(zero_copy, owned);
assert_eq!(owned, other);
assert_eq!(zero_copy, owned, "zero-copy and owned version of the methods have diverged this is for sure a bug in the library");
assert_eq!(owned, other, "owned and other have diverged this migh be due to a bug in the library or maybe an update to the ratatui crate");
assert_eq!(zero_copy, other);
}

0 comments on commit f4ee638

Please sign in to comment.