summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-10-24 08:44:07 -0700
committerJoe Wilm <joe@jwilm.com>2016-10-24 08:44:07 -0700
commite9304afd36e549b5c330f8a35545ae61808a1553 (patch)
treebd362b1d8a41fc28ff0d713e52a5a86762e47911 /src
parent741a8b3f47117d2d72af29c39627603595402168 (diff)
downloadalacritty-e9304afd36e549b5c330f8a35545ae61808a1553.tar.gz
alacritty-e9304afd36e549b5c330f8a35545ae61808a1553.zip
Expand cell::Color layout tests
The whole enumeration should be well defined for the renderer.
Diffstat (limited to 'src')
-rw-r--r--src/term.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/term.rs b/src/term.rs
index cac260a2..bcd78814 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -122,16 +122,34 @@ pub mod cell {
#[cfg(test)]
mod tests {
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]
- fn color_discriminant_values() {
- let rgb_color = Color::Rgb(::Rgb { r: 0, g: 0, b: 0 });
+ fn color_memory_layout() {
+ let rgb_color = Color::Rgb(::Rgb { r: 1, g: 2, b: 3 });
let ansi_color = Color::Ansi(::ansi::Color::Foreground);
unsafe {
- assert_eq!(discriminant_value(&rgb_color), 0);
- assert_eq!(discriminant_value(&ansi_color), 1);
+ // Color::Rgb
+ // [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);
}
}
}