use lb::buf; use lb::buf::Buffer; use lb::color; use lb::glyph; // const BLACK: color::Rgb = color::Rgb::new(0, 0, 0); const WHITE: color::Rgb = color::Rgb::new(255, 255, 255); const RED: color::Rgb = color::Rgb::new(255, 0, 0); const GREEN: color::Rgb = color::Rgb::new(0, 255, 0); const BLUE: color::Rgb = color::Rgb::new(0, 0, 255); // const CYAN: color::Rgb = color::Rgb::new(0, 255, 255); // const MAGENTA: color::Rgb = color::Rgb::new(255, 0, 255); // const YELLOW: color::Rgb = color::Rgb::new(255, 255, 0); #[test] fn buffer_render() { let mut buffer = buf::SimpleBuffer::new((2, 2).into()); buffer[(0, 0)] = glyph::Glyph::new('A', RED, GREEN); buffer[(1, 0)] = glyph::Glyph::new('B', BLUE, GREEN); buffer[(0, 1)] = glyph::Glyph::new('C', BLUE, GREEN); buffer[(1, 1)] = glyph::Glyph::new('D', BLUE, WHITE); let actual = buffer.render(); let expected = "\x1b[38;2;255;0;0m\x1b[48;2;0;255;0mA\ \x1b[38;2;0;0;255mB\ \x1b[0m\r\n\ \x1b[38;2;0;0;255m\x1b[48;2;0;255;0mC\ \x1b[48;2;255;255;255mD\ \x1b[0m\r\n"; assert_eq!(actual, expected); } #[test] fn double_buffer_render() { let mut buffer = buf::DoubleBuffer::new((2, 2).into()); buffer[(0, 0)] = glyph::Glyph::new('A', RED, GREEN); buffer[(1, 0)] = glyph::Glyph::new('B', BLUE, GREEN); buffer[(0, 1)] = glyph::Glyph::new('C', BLUE, GREEN); buffer[(1, 1)] = glyph::Glyph::new('D', BLUE, WHITE); let actual0 = buffer.render(); let expected0 = "\x1b[38;2;255;0;0m\x1b[48;2;0;255;0mA\ \x1b[38;2;0;0;255mB\ \x1b[0m\x1b[2D\x1b[B\ \x1b[38;2;0;0;255m\x1b[48;2;0;255;0mC\ \x1b[48;2;255;255;255mD\ \x1b[0m"; assert_eq!(actual0, expected0); buffer[(0, 0)] = glyph::Glyph::new('A', RED, GREEN); buffer[(1, 0)] = glyph::Glyph::new('X', BLUE, GREEN); buffer[(0, 1)] = glyph::Glyph::new('C', BLUE, RED); buffer[(1, 1)] = glyph::Glyph::new('D', BLUE, WHITE); let actual1 = buffer.render(); let expected1 = "\x1b[1C\ \x1b[38;2;0;0;255m\x1b[48;2;0;255;0mX\ \x1b[0m\x1b[2D\x1b[B\ \x1b[38;2;0;0;255m\x1b[48;2;255;0;0mC\ \x1b[1C"; assert_eq!(actual1, expected1); } #[test] fn double_buffer_render_same_content_twice() { let mut buffer = buf::DoubleBuffer::new((2, 2).into()); buffer[(0, 0)] = glyph::Glyph::new('A', RED, GREEN); buffer[(1, 0)] = glyph::Glyph::new('B', BLUE, GREEN); buffer[(0, 1)] = glyph::Glyph::new('C', BLUE, GREEN); buffer[(1, 1)] = glyph::Glyph::new('D', BLUE, WHITE); let actual0 = buffer.render(); let expected0 = "\x1b[38;2;255;0;0m\x1b[48;2;0;255;0mA\ \x1b[38;2;0;0;255mB\ \x1b[0m\x1b[2D\x1b[B\ \x1b[38;2;0;0;255m\x1b[48;2;0;255;0mC\ \x1b[48;2;255;255;255mD\ \x1b[0m"; assert_eq!(actual0, expected0); buffer[(0, 0)] = glyph::Glyph::new('A', RED, GREEN); buffer[(1, 0)] = glyph::Glyph::new('B', BLUE, GREEN); buffer[(0, 1)] = glyph::Glyph::new('C', BLUE, GREEN); buffer[(1, 1)] = glyph::Glyph::new('D', BLUE, WHITE); let actual1 = buffer.render(); let expected1 = "\x1b[1B\x1b[2C"; assert_eq!(actual1, expected1); }