aboutsummaryrefslogtreecommitdiff
path: root/tests/display.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-22 11:03:43 -0700
committeriximeow <me@iximeow.net>2024-06-22 11:03:59 -0700
commita66be66c22bc31526ac35c1cffdb28992a392ccf (patch)
tree6f49a2e49114256121d3239c2d7223cf635d3c9e /tests/display.rs
parentc21a5f2956d8e0fa3eace14661a8aed124c6e995 (diff)
move DisplaySink code out from yaxpeax-x86
it was built in-place around yaxpeax-x86, hoisted out once it seemed suitable and could be generalized. yay! also include a Makefile in yaxpeax-arch now to test that various crate feature flag combinations.. work.
Diffstat (limited to 'tests/display.rs')
-rw-r--r--tests/display.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/display.rs b/tests/display.rs
new file mode 100644
index 0000000..9a8ef2e
--- /dev/null
+++ b/tests/display.rs
@@ -0,0 +1,71 @@
+/*
+#[test]
+fn sinks_are_equivalent() {
+ use yaxpeax_arch::display::NoColorsSink;
+ use yaxpeax_arch::testkit::DisplaySinkWriteComparator;
+
+ let mut bare = String::new();
+ let mut through_sink = String::new();
+ for i in 0..u64::MAX {
+ bare.clear();
+ through_sink.clear();
+ let mut out = NoColorsSink {
+ out: &mut through_sink
+ };
+ let mut comparator = DisplaySinkWriteComparator {
+ sink1: &mut out,
+ sink1_check: |sink| { sink.out.as_str() },
+ sink2: &mut bare,
+ sink2_check: |sink| { sink.as_str() },
+ };
+ }
+}
+*/
+
+#[cfg(feature="alloc")]
+#[test]
+fn display_sink_write_hex_helpers() {
+ use yaxpeax_arch::display::{DisplaySink};
+
+ // for u8/i8/u16/i16 we can exhaustively test. we'll leave the rest for fuzzers.
+ let mut buf = String::new();
+ for i in 0..=u8::MAX {
+ buf.clear();
+ buf.write_u8(i).expect("write succeeds");
+ assert_eq!(buf, format!("{:x}", i));
+
+ buf.clear();
+ buf.write_prefixed_u8(i).expect("write succeeds");
+ assert_eq!(buf, format!("0x{:x}", i));
+
+ let expected = if (i as i8) < 0 {
+ format!("-0x{:x}", (i as i8).unsigned_abs())
+ } else {
+ format!("0x{:x}", i)
+ };
+
+ buf.clear();
+ buf.write_prefixed_i8(i as i8).expect("write succeeds");
+ assert_eq!(buf, expected);
+ }
+
+ for i in 0..=u16::MAX {
+ buf.clear();
+ buf.write_u16(i).expect("write succeeds");
+ assert_eq!(buf, format!("{:x}", i));
+
+ buf.clear();
+ buf.write_prefixed_u16(i).expect("write succeeds");
+ assert_eq!(buf, format!("0x{:x}", i));
+
+ let expected = if (i as i16) < 0 {
+ format!("-0x{:x}", (i as i16).unsigned_abs())
+ } else {
+ format!("0x{:x}", i)
+ };
+
+ buf.clear();
+ buf.write_prefixed_i16(i as i16).expect("write succeeds");
+ assert_eq!(buf, expected);
+ }
+}