@@ -87,36 +87,26 @@ impl PartialEq for AttrValue<'_> {
87
87
#[ cfg( test) ]
88
88
mod tests {
89
89
use super :: AttrValue ;
90
- use std:: ffi:: CStr ;
91
- use std:: os:: raw:: c_char;
92
-
93
- extern "C" {
94
- // libgit2 defines them as mutable, so they are also declared mutable here.
95
- // However, libgit2 never mutates them, thus it's always safe to access them in Rust.
96
- static mut git_attr__true: * const c_char ;
97
- static mut git_attr__false: * const c_char ;
98
- static mut git_attr__unset: * const c_char ;
99
- }
100
90
101
91
macro_rules! test_attr_value {
102
92
( $function: ident, $variant: ident) => {
103
- let attr_true = unsafe { CStr :: from_ptr ( git_attr__true ) } . to_str ( ) . unwrap ( ) ;
104
- let attr_false = unsafe { CStr :: from_ptr ( git_attr__false ) } . to_str ( ) . unwrap ( ) ;
105
- let attr_unset = unsafe { CStr :: from_ptr ( git_attr__unset ) } . to_str ( ) . unwrap ( ) ;
93
+ const ATTR_TRUE : & str = "[internal]__TRUE__" ;
94
+ const ATTR_FALSE : & str = "[internal]__FALSE__" ;
95
+ const ATTR_UNSET : & str = "[internal]__UNSET__" ;
106
96
let as_bytes = AsRef :: <[ u8 ] >:: as_ref;
107
97
// Use `matches!` here since the `PartialEq` implementation does not differentiate
108
98
// between `String` and `Bytes`.
109
99
assert!( matches!(
110
- AttrValue :: $function( Some ( attr_true . to_owned ( ) . as_ref( ) ) ) ,
111
- AttrValue :: $variant( s) if as_bytes( s) == attr_true . as_bytes( )
100
+ AttrValue :: $function( Some ( ATTR_TRUE . as_ref( ) ) ) ,
101
+ AttrValue :: $variant( s) if as_bytes( s) == ATTR_TRUE . as_bytes( )
112
102
) ) ;
113
103
assert!( matches!(
114
- AttrValue :: $function( Some ( attr_false . to_owned ( ) . as_ref( ) ) ) ,
115
- AttrValue :: $variant( s) if as_bytes( s) == attr_false . as_bytes( )
104
+ AttrValue :: $function( Some ( ATTR_FALSE . as_ref( ) ) ) ,
105
+ AttrValue :: $variant( s) if as_bytes( s) == ATTR_FALSE . as_bytes( )
116
106
) ) ;
117
107
assert!( matches!(
118
- AttrValue :: $function( Some ( attr_unset . to_owned ( ) . as_ref( ) ) ) ,
119
- AttrValue :: $variant( s) if as_bytes( s) == attr_unset . as_bytes( )
108
+ AttrValue :: $function( Some ( ATTR_UNSET . as_ref( ) ) ) ,
109
+ AttrValue :: $variant( s) if as_bytes( s) == ATTR_UNSET . as_bytes( )
120
110
) ) ;
121
111
assert!( matches!(
122
112
AttrValue :: $function( Some ( "foo" . as_ref( ) ) ) ,
@@ -126,18 +116,6 @@ mod tests {
126
116
AttrValue :: $function( Some ( "bar" . as_ref( ) ) ) ,
127
117
AttrValue :: $variant( s) if as_bytes( s) == b"bar"
128
118
) ) ;
129
- assert_eq!(
130
- AttrValue :: $function( Some ( attr_true. as_ref( ) ) ) ,
131
- AttrValue :: True
132
- ) ;
133
- assert_eq!(
134
- AttrValue :: $function( Some ( attr_false. as_ref( ) ) ) ,
135
- AttrValue :: False
136
- ) ;
137
- assert_eq!(
138
- AttrValue :: $function( Some ( attr_unset. as_ref( ) ) ) ,
139
- AttrValue :: Unspecified
140
- ) ;
141
119
assert_eq!( AttrValue :: $function( None ) , AttrValue :: Unspecified ) ;
142
120
} ;
143
121
}
0 commit comments