Skip to content

Commit fc3d8a1

Browse files
committed
Enforce ASCII size with tests
1 parent 100d770 commit fc3d8a1

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Diff for: Cargo.lock

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ ansi_term = "0.12"
3636
[target.'cfg(target_os = "linux")'.dependencies]
3737
libc = "0.2.76"
3838
base64 = "0.12.3"
39+
40+
[dev-dependencies]
41+
lazy_static = "1.4"
42+
more-asserts = "0.2"
43+
paste = "1"

Diff for: src/language.rs

+37
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,43 @@ macro_rules! define_languages {
5858
fn get_all_language_types() -> Vec<tokei::LanguageType> {
5959
vec![ $( tokei::LanguageType::$name ,)* ]
6060
}
61+
62+
#[cfg(test)]
63+
mod ascii_size {
64+
use lazy_static::lazy_static;
65+
use more_asserts::assert_le;
66+
use paste::paste;
67+
use regex::Regex;
68+
69+
const MAX_WIDTH: usize = 40;
70+
const MAX_HEIGHT: usize = 25;
71+
72+
lazy_static! {
73+
static ref COLOR_INTERPOLATION: Regex = Regex::new(r"\{\d+\}").unwrap();
74+
}
75+
76+
$(
77+
paste! {
78+
#[test]
79+
fn [<$name:lower _width>] () {
80+
const ASCII: &str = include_str!(concat!("../resources/", $ascii));
81+
82+
for (line_number, line) in ASCII.lines().enumerate() {
83+
let line = COLOR_INTERPOLATION.replace_all(line, "");
84+
if (line.len() > MAX_WIDTH) {
85+
panic!("{} is too wide at line {}\n{:?}", $ascii, line_number + 1, line)
86+
}
87+
}
88+
}
89+
90+
#[test]
91+
fn [<$name:lower _height>] () {
92+
const ASCII: &str = include_str!(concat!("../resources/", $ascii));
93+
assert_le!(ASCII.lines().count(), MAX_HEIGHT, concat!($ascii, " is too tall."));
94+
}
95+
}
96+
)*
97+
}
6198
};
6299
}
63100

0 commit comments

Comments
 (0)