1 use crate::read2
::{ProcOutput, FILTERED_PATHS_PLACEHOLDER_LEN, HEAD_LEN, TAIL_LEN}
;
4 fn test_abbreviate_short_string() {
5 let mut out
= ProcOutput
::new();
6 out
.extend(b
"Hello world!", &[]);
7 assert_eq
!(b
"Hello world!", &*out
.into_bytes());
11 fn test_abbreviate_short_string_multiple_steps() {
12 let mut out
= ProcOutput
::new();
14 out
.extend(b
"Hello ", &[]);
15 out
.extend(b
"world!", &[]);
17 assert_eq
!(b
"Hello world!", &*out
.into_bytes());
21 fn test_abbreviate_long_string() {
22 let mut out
= ProcOutput
::new();
24 let data
= vec
![b'
.'
; HEAD_LEN
+ TAIL_LEN
+ 16];
25 out
.extend(&data
, &[]);
27 let mut expected
= vec
![b'
.'
; HEAD_LEN
];
28 expected
.extend_from_slice(b
"\n\n<<<<<< SKIPPED 16 BYTES >>>>>>\n\n");
29 expected
.extend_from_slice(&vec
![b'
.'
; TAIL_LEN
]);
31 // We first check the length to avoid endless terminal output if the length differs, since
32 // `out` is hundreds of KBs in size.
33 let out
= out
.into_bytes();
34 assert_eq
!(expected
.len(), out
.len());
35 assert_eq
!(expected
, out
);
39 fn test_abbreviate_long_string_multiple_steps() {
40 let mut out
= ProcOutput
::new();
42 out
.extend(&vec
![b'
.'
; HEAD_LEN
], &[]);
43 out
.extend(&vec
![b'
.'
; TAIL_LEN
], &[]);
44 // Also test whether the rotation works
45 out
.extend(&vec
![b'
!'
; 16], &[]);
46 out
.extend(&vec
![b'?'
; 16], &[]);
48 let mut expected
= vec
![b'
.'
; HEAD_LEN
];
49 expected
.extend_from_slice(b
"\n\n<<<<<< SKIPPED 32 BYTES >>>>>>\n\n");
50 expected
.extend_from_slice(&vec
![b'
.'
; TAIL_LEN
- 32]);
51 expected
.extend_from_slice(&vec
![b'
!'
; 16]);
52 expected
.extend_from_slice(&vec
![b'?'
; 16]);
54 // We first check the length to avoid endless terminal output if the length differs, since
55 // `out` is hundreds of KBs in size.
56 let out
= out
.into_bytes();
57 assert_eq
!(expected
.len(), out
.len());
58 assert_eq
!(expected
, out
);
62 fn test_abbreviate_filterss_are_detected() {
63 let mut out
= ProcOutput
::new();
64 let filters
= &["foo".to_string(), "quux".to_string()];
66 out
.extend(b
"Hello foo", filters
);
67 // Check items from a previous extension are not double-counted.
68 out
.extend(b
"! This is a qu", filters
);
69 // Check items are detected across extensions.
70 out
.extend(b
"ux.", filters
);
73 ProcOutput
::Full { bytes, filtered_len }
=> assert_eq
!(
75 bytes
.len() + FILTERED_PATHS_PLACEHOLDER_LEN
* filters
.len()
76 - filters
.iter().map(|i
| i
.len()).sum
::<usize>()
78 ProcOutput
::Abbreviated { .. }
=> panic
!("out should not be abbreviated"),
81 assert_eq
!(b
"Hello foo! This is a quux.", &*out
.into_bytes());
85 fn test_abbreviate_filters_avoid_abbreviations() {
86 let mut out
= ProcOutput
::new();
87 let filters
= &[std
::iter
::repeat('a'
).take(64).collect
::<String
>()];
89 let mut expected
= vec
![b'
.'
; HEAD_LEN
- FILTERED_PATHS_PLACEHOLDER_LEN
as usize];
90 expected
.extend_from_slice(filters
[0].as_bytes());
91 expected
.extend_from_slice(&vec
![b'
.'
; TAIL_LEN
]);
93 out
.extend(&expected
, filters
);
95 // We first check the length to avoid endless terminal output if the length differs, since
96 // `out` is hundreds of KBs in size.
97 let out
= out
.into_bytes();
98 assert_eq
!(expected
.len(), out
.len());
99 assert_eq
!(expected
, out
);
103 fn test_abbreviate_filters_can_still_cause_abbreviations() {
104 let mut out
= ProcOutput
::new();
105 let filters
= &[std
::iter
::repeat('a'
).take(64).collect
::<String
>()];
107 let mut input
= vec
![b'
.'
; HEAD_LEN
];
108 input
.extend_from_slice(&vec
![b'
.'
; TAIL_LEN
]);
109 input
.extend_from_slice(filters
[0].as_bytes());
111 let mut expected
= vec
![b'
.'
; HEAD_LEN
];
112 expected
.extend_from_slice(b
"\n\n<<<<<< SKIPPED 64 BYTES >>>>>>\n\n");
113 expected
.extend_from_slice(&vec
![b'
.'
; TAIL_LEN
- 64]);
114 expected
.extend_from_slice(&vec
![b'a'
; 64]);
116 out
.extend(&input
, filters
);
118 // We first check the length to avoid endless terminal output if the length differs, since
119 // `out` is hundreds of KBs in size.
120 let out
= out
.into_bytes();
121 assert_eq
!(expected
.len(), out
.len());
122 assert_eq
!(expected
, out
);