diff options
author | iximeow <me@iximeow.net> | 2024-06-23 17:07:22 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2024-06-23 17:07:22 -0700 |
commit | 1fb5a7903bb44d44e298959d2637d858b2ea8e38 (patch) | |
tree | 15ae7bb8f58eba0966b28448f563276c3df70455 /tests | |
parent | a8ec2d655ca59d7118ca1ea47dada705183b5442 (diff) |
document new AnsiDisplaySink, add more -arch tests for sinks
Diffstat (limited to 'tests')
-rw-r--r-- | tests/display.rs | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/tests/display.rs b/tests/display.rs index 887db53..a6d6eb1 100644 --- a/tests/display.rs +++ b/tests/display.rs @@ -1,27 +1,5 @@ -/* -#[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() }, - }; - } -} -*/ +// this was something of a misfeature for these formatters.. #[test] #[allow(deprecated)] fn formatters_are_not_feature_gated() { @@ -86,3 +64,51 @@ fn display_sink_write_hex_helpers() { assert_eq!(buf, expected); } } + +#[cfg(feature="alloc")] +#[test] +fn sinks_are_equivalent() { + use yaxpeax_arch::display::{DisplaySink, FmtSink}; + use yaxpeax_arch::testkit::DisplaySinkWriteComparator; + + let mut bare = String::new(); + let mut through_sink = String::new(); + for i in 0..u16::MAX { + bare.clear(); + through_sink.clear(); + let mut out = FmtSink::new(&mut through_sink); + let mut comparator = DisplaySinkWriteComparator::new( + &mut out, + |sink| { sink.inner_ref().as_str() }, + &mut bare, + |sink| { sink.as_str() }, + ); + comparator.write_u16(i).expect("write succeeds"); + comparator.write_prefixed_u16(i).expect("write succeeds"); + comparator.write_prefixed_i16(i as i16).expect("write succeeds"); + } +} + +#[cfg(all(feature="alloc", feature="color-new"))] +#[test] +fn ansi_sink_works() { + use yaxpeax_arch::color_new::ansi::AnsiDisplaySink; + use yaxpeax_arch::display::DisplaySink; + + let mut buf = String::new(); + + let mut ansi_sink = AnsiDisplaySink::new(&mut buf, yaxpeax_arch::color_new::DefaultColors); + + ansi_sink.span_start_immediate(); + ansi_sink.write_prefixed_u8(0x80).expect("write succeeds"); + ansi_sink.span_end_immediate(); + ansi_sink.write_fixed_size("(").expect("write succeeds"); + ansi_sink.span_start_register(); + ansi_sink.write_fixed_size("rbp").expect("write succeeds"); + ansi_sink.span_end_register(); + ansi_sink.write_fixed_size(")").expect("write succeeds"); + + drop(ansi_sink); + + assert_eq!(buf, "\x1b[37m0x80\x1b[39m(\x1b[38;5;6mrbp\x1b[39m)"); +} |