diff options
author | Anhad Singh <62820092+Andy-Python-Programmer@users.noreply.github.com> | 2023-05-18 17:50:18 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 07:50:18 +0000 |
commit | d41e868a0a0d8f305990d6ba59aea05c9a456b66 (patch) | |
tree | bd9d93def2bde95e69db183cc368eeb86a88ae57 | |
parent | d5036ab2c20dfb0853cb1c7b9bc41a58c24c5bf2 (diff) | |
download | r-alacritty-vte-d41e868a0a0d8f305990d6ba59aea05c9a456b66.tar.gz r-alacritty-vte-d41e868a0a0d8f305990d6ba59aea05c9a456b66.tar.bz2 r-alacritty-vte-d41e868a0a0d8f305990d6ba59aea05c9a456b66.zip |
Add ansi color contrast tests for
-rw-r--r-- | .builds/linux.yml | 1 | ||||
-rw-r--r-- | src/ansi.rs | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/.builds/linux.yml b/.builds/linux.yml index 502f5fb..eadc34e 100644 --- a/.builds/linux.yml +++ b/.builds/linux.yml @@ -8,6 +8,7 @@ tasks: cd vte $HOME/.cargo/bin/cargo +stable test $HOME/.cargo/bin/cargo +stable test --features=ansi + $HOME/.cargo/bin/cargo +stable test --features=ansi --no-default-features - clippy: | cd vte $HOME/.cargo/bin/cargo +stable clippy diff --git a/src/ansi.rs b/src/ansi.rs index 282be0f..2024164 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -2085,4 +2085,23 @@ mod tests { let expected: Vec<usize> = (0..256).collect(); assert_eq!(handler.reset_colors, expected); } + + #[test] + #[cfg(not(feature = "no_std"))] + fn contrast() { + let rgb1 = Rgb { r: 0xff, g: 0xff, b: 0xff }; + let rgb2 = Rgb { r: 0x00, g: 0x00, b: 0x00 }; + assert!((rgb1.contrast(rgb2) - 21.).abs() < f64::EPSILON); + + let rgb1 = Rgb { r: 0xff, g: 0xff, b: 0xff }; + assert!((rgb1.contrast(rgb1) - 1.).abs() < f64::EPSILON); + + let rgb1 = Rgb { r: 0xff, g: 0x00, b: 0xff }; + let rgb2 = Rgb { r: 0x00, g: 0xff, b: 0x00 }; + assert!((rgb1.contrast(rgb2) - 2.285_543_608_124_253_3).abs() < f64::EPSILON); + + let rgb1 = Rgb { r: 0x12, g: 0x34, b: 0x56 }; + let rgb2 = Rgb { r: 0xfe, g: 0xdc, b: 0xba }; + assert!((rgb1.contrast(rgb2) - 9.786_558_997_257_74).abs() < f64::EPSILON); + } } |