@@ -4,6 +4,7 @@ use core::panic::Location;
4
4
const RED : & str = "\x1b [31m" ;
5
5
const YELLOW : & str = "\x1b [33m" ;
6
6
const BLUE : & str = "\x1b [34m" ;
7
+ const MAGENTA : & str = "\x1b [35m" ;
7
8
const CYAN : & str = "\x1b [36m" ;
8
9
const BOLD : & str = "\x1b [1m" ;
9
10
const RESET : & str = "\x1b [0m" ;
@@ -13,20 +14,21 @@ const RESET: &str = "\x1b[0m";
13
14
/// If `ansi_colors` is true, this function unconditionally prints ANSI color codes.
14
15
/// It should only be set to true only if it is known that the terminal supports it.
15
16
pub fn pretty_print_assertion ( assert : & AssertInfo < ' _ > , loc : Location < ' _ > , ansi_colors : bool ) {
17
+ let macro_name = assert. macro_name ;
16
18
if ansi_colors {
17
19
print_pretty_header ( loc) ;
18
20
match & assert. assertion {
19
- Assertion :: Bool ( assert) => print_pretty_bool_assertion ( assert) ,
20
- Assertion :: Binary ( assert) => print_pretty_binary_assertion ( assert) ,
21
+ Assertion :: Bool ( assert) => print_pretty_bool_assertion ( macro_name , assert) ,
22
+ Assertion :: Binary ( assert) => print_pretty_binary_assertion ( macro_name , assert) ,
21
23
}
22
24
if let Some ( msg) = & assert. message {
23
25
print_pretty_message ( msg) ;
24
26
}
25
27
} else {
26
28
print_plain_header ( loc) ;
27
29
match & assert. assertion {
28
- Assertion :: Bool ( assert) => print_plain_bool_assertion ( assert) ,
29
- Assertion :: Binary ( assert) => print_plain_binary_assertion ( assert) ,
30
+ Assertion :: Bool ( assert) => print_plain_bool_assertion ( macro_name , assert) ,
31
+ Assertion :: Binary ( assert) => print_plain_binary_assertion ( macro_name , assert) ,
30
32
}
31
33
if let Some ( msg) = & assert. message {
32
34
print_plain_message ( msg) ;
@@ -50,55 +52,111 @@ fn print_pretty_header(loc: Location<'_>) {
50
52
) ;
51
53
}
52
54
53
- fn print_plain_bool_assertion ( assert : & BoolAssertion ) {
54
- eprintln ! ( "Assertion:\n {}" , assert. expr) ;
55
- eprintln ! ( "Expansion:\n false" ) ;
55
+ fn print_plain_bool_assertion ( macro_name : & ' static str , assert : & BoolAssertion ) {
56
+ eprint ! (
57
+ concat!(
58
+ "Assertion:\n " ,
59
+ " {macro_name}!( {expr} )\n " ,
60
+ "Expansion:\n " ,
61
+ " {macro_name}!( false )\n " ,
62
+ ) ,
63
+ macro_name = macro_name,
64
+ expr = assert. expr,
65
+ )
56
66
}
57
67
58
- fn print_pretty_bool_assertion ( assert : & BoolAssertion ) {
59
- eprintln ! (
60
- "{bold}Assertion:{reset}\n {cyan}{expr}{reset}" ,
68
+ fn print_pretty_bool_assertion ( macro_name : & ' static str , assert : & BoolAssertion ) {
69
+ eprint ! (
70
+ concat!(
71
+ "{bold}Assertion:{reset}\n " ,
72
+ " {magenta}{macro_name}!( {cyan}{expr} {magenta}){reset}\n " ,
73
+ "{bold}Expansion:{reset}\n " ,
74
+ " {magenta}{macro_name}!( {cyan}false {magenta}){reset}\n " ,
75
+ ) ,
76
+ magenta = MAGENTA ,
61
77
cyan = CYAN ,
62
78
reset = RESET ,
63
79
bold = BOLD ,
80
+ macro_name = macro_name,
64
81
expr = assert. expr,
65
82
) ;
66
- eprintln ! (
67
- "{bold}Expansion:{reset}\n {cyan}false{reset}" ,
68
- cyan = CYAN ,
69
- bold = BOLD ,
70
- reset = RESET ,
71
- ) ;
72
83
}
73
84
74
- fn print_plain_binary_assertion ( assert : & BinaryAssertion < ' _ > ) {
75
- eprintln ! ( "Assertion:\n {} {} {}" , assert. left_expr, assert. op, assert. right_expr) ;
76
- eprintln ! ( "Expansion:\n {:?} {} {:?}" , assert. left_val, assert. op, assert. right_val) ;
85
+ fn print_plain_binary_assertion ( macro_name : & ' static str , assert : & BinaryAssertion < ' _ > ) {
86
+ if macro_name == "assert_eq" || macro_name == "assert_ne" {
87
+ eprint ! (
88
+ concat!(
89
+ "Assertion:\n " ,
90
+ " {macro_name}!( {left_expr}, {right_expr} )\n " ,
91
+ "Expansion:\n " ,
92
+ " {macro_name}!( {left_val:?}, {right_val:?} )\n " ,
93
+ ) ,
94
+ macro_name = macro_name,
95
+ left_expr = assert. left_expr,
96
+ right_expr = assert. right_expr,
97
+ left_val = assert. left_val,
98
+ right_val = assert. right_val,
99
+ ) ;
100
+ } else {
101
+ eprint ! (
102
+ concat!(
103
+ "Assertion:\n " ,
104
+ " {macro_name}!( {left_expr} {op} {right_expr} )\n " ,
105
+ "Expansion:\n " ,
106
+ " {macro_name}!( {left_val:?} {op} {right_val:?} )\n " ,
107
+ ) ,
108
+ macro_name = macro_name,
109
+ op = assert. op,
110
+ left_expr = assert. left_expr,
111
+ right_expr = assert. right_expr,
112
+ left_val = assert. left_val,
113
+ right_val = assert. right_val,
114
+ ) ;
115
+ } ;
77
116
}
78
117
79
- fn print_pretty_binary_assertion ( assert : & BinaryAssertion < ' _ > ) {
80
- eprintln ! (
81
- "{bold}Assertion:{reset}\n {cyan}{left} {bold}{blue}{op}{reset} {yellow}{right}{reset}" ,
82
- cyan = CYAN ,
83
- blue = BLUE ,
84
- yellow = YELLOW ,
85
- bold = BOLD ,
86
- reset = RESET ,
87
- left = assert. left_expr,
88
- op = assert. op,
89
- right = assert. right_expr,
90
- ) ;
91
- eprintln ! (
92
- "{bold}Expansion:{reset}\n {cyan}{left:?} {bold}{blue}{op}{reset} {yellow}{right:?}{reset}" ,
93
- cyan = CYAN ,
94
- blue = BLUE ,
95
- yellow = YELLOW ,
96
- bold = BOLD ,
97
- reset = RESET ,
98
- left = assert. left_val,
99
- op = assert. op,
100
- right = assert. right_val,
101
- ) ;
118
+ fn print_pretty_binary_assertion ( macro_name : & ' static str , assert : & BinaryAssertion < ' _ > ) {
119
+ if macro_name == "assert_eq" || macro_name == "assert_ne" {
120
+ eprint ! (
121
+ concat!(
122
+ "{bold}Assertion:{reset}\n " ,
123
+ " {magenta}{macro_name}!( {cyan}{left_expr}{magenta}, {yellow}{right_expr} {magenta}){reset}\n " ,
124
+ "{bold}Expansion:{reset}\n " ,
125
+ " {magenta}{macro_name}!( {cyan}{left_val:?}{magenta}, {yellow}{right_val:?} {magenta}){reset}\n " ,
126
+ ) ,
127
+ cyan = CYAN ,
128
+ magenta = MAGENTA ,
129
+ yellow = YELLOW ,
130
+ bold = BOLD ,
131
+ reset = RESET ,
132
+ macro_name = macro_name,
133
+ left_expr = assert. left_expr,
134
+ right_expr = assert. right_expr,
135
+ left_val = assert. left_val,
136
+ right_val = assert. right_val,
137
+ ) ;
138
+ } else {
139
+ eprint ! (
140
+ concat!(
141
+ "{bold}Assertion:{reset}\n " ,
142
+ " {magenta}{macro_name}!( {cyan}{left_expr} {bold}{blue}{op}{reset} {yellow}{right_expr} {magenta}){reset}\n " ,
143
+ "{bold}Expansion:{reset}\n " ,
144
+ " {magenta}{macro_name}!( {cyan}{left_val:?} {bold}{blue}{op}{reset} {yellow}{right_val:?} {magenta}){reset}\n " ,
145
+ ) ,
146
+ blue = BLUE ,
147
+ cyan = CYAN ,
148
+ magenta = MAGENTA ,
149
+ yellow = YELLOW ,
150
+ bold = BOLD ,
151
+ reset = RESET ,
152
+ macro_name = macro_name,
153
+ op = assert. op,
154
+ left_expr = assert. left_expr,
155
+ right_expr = assert. right_expr,
156
+ left_val = assert. left_val,
157
+ right_val = assert. right_val,
158
+ ) ;
159
+ } ;
102
160
}
103
161
104
162
fn print_plain_message ( message : & std:: fmt:: Arguments < ' _ > ) {
0 commit comments