mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-11 13:51:01 -05:00
Expand cell::Color layout tests
The whole enumeration should be well defined for the renderer.
This commit is contained in:
parent
741a8b3f47
commit
e9304afd36
1 changed files with 23 additions and 5 deletions
28
src/term.rs
28
src/term.rs
|
@ -122,16 +122,34 @@ pub mod cell {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Color;
|
use super::Color;
|
||||||
use std::intrinsics::discriminant_value;
|
use std::mem;
|
||||||
|
|
||||||
|
// Ensure memory layout is well defined so components like renderer
|
||||||
|
// can exploit it.
|
||||||
|
//
|
||||||
|
// Thankfully, everything is just a u8 for now so no endianness
|
||||||
|
// considerations are needed.
|
||||||
#[test]
|
#[test]
|
||||||
fn color_discriminant_values() {
|
fn color_memory_layout() {
|
||||||
let rgb_color = Color::Rgb(::Rgb { r: 0, g: 0, b: 0 });
|
let rgb_color = Color::Rgb(::Rgb { r: 1, g: 2, b: 3 });
|
||||||
let ansi_color = Color::Ansi(::ansi::Color::Foreground);
|
let ansi_color = Color::Ansi(::ansi::Color::Foreground);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
assert_eq!(discriminant_value(&rgb_color), 0);
|
// Color::Rgb
|
||||||
assert_eq!(discriminant_value(&ansi_color), 1);
|
// [discriminant(0), red, green ,blue]
|
||||||
|
let bytes: [u8; 4] = mem::transmute_copy(&rgb_color);
|
||||||
|
assert_eq!(bytes[0], 0);
|
||||||
|
assert_eq!(bytes[1], 1);
|
||||||
|
assert_eq!(bytes[2], 2);
|
||||||
|
assert_eq!(bytes[3], 3);
|
||||||
|
|
||||||
|
// Color::Ansi
|
||||||
|
// [discriminant(1), ansi::Color, 0, 0]
|
||||||
|
let bytes: [u8; 4] = mem::transmute_copy(&ansi_color);
|
||||||
|
assert_eq!(bytes[0], 1);
|
||||||
|
assert_eq!(bytes[1], ::ansi::Color::Foreground as u8);
|
||||||
|
assert_eq!(bytes[2], 0);
|
||||||
|
assert_eq!(bytes[3], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue