Skip to content

Commit

Permalink
add to_ans test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed Oct 27, 2024
1 parent 2c98731 commit cd86bb7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions ansi2/src/ans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,36 @@ pub fn to_ans<S: AsRef<str>>(str: S, width: Option<usize>, compress: bool) -> St
}
text.join("\n")
}

#[cfg(test)]
mod test {
use std::path::Path;

use crate::{ans::to_ans, Canvas};

#[test]
fn test() {
let cargo_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let assets_dir = Path::new(&cargo_dir).parent().unwrap().join("assets");
let v = std::fs::read_dir(assets_dir).unwrap();
for i in v {
let p = i.unwrap().path().to_string_lossy().to_string();
if !p.ends_with(".ans") {
continue;
}
if p.ends_with(".min.ans") {
continue;
}
println!("{:?}", p);
let s = std::fs::read_to_string(&p).unwrap();
let min = to_ans(&s, None, true);

let c1 = Canvas::new(&s, None);
let c2 = Canvas::new(&min, None);
// assert_eq!(c1, c2);
if c1 != c2 {
println!("{}", p);
}
}
}
}
4 changes: 2 additions & 2 deletions ansi2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use color::AnsiColor;
use lex::{parse_ansi, Token};
use std::{collections::VecDeque, vec};

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Node {
pub bg_color: AnsiColor,
pub color: AnsiColor,
Expand All @@ -37,7 +37,7 @@ impl Node {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Canvas {
pub pixels: Vec<Vec<Node>>,
pub w: usize,
Expand Down
Binary file modified assets/take-my-ansi.ans
Binary file not shown.

0 comments on commit cd86bb7

Please sign in to comment.