1 // Copyright 2024 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 mod write_expr_value { 16 use googletest::prelude::*; 17 18 // Converts the formatting call to a `String` for testing. 19 macro_rules! write_expr_value { 20 ($expr_str:expr, $expr: expr $(,)?) => {{ 21 let mut s = String::new(); 22 ::googletest::fmt::internal::__googletest__write_expr_value!(s, $expr_str, $expr); 23 s 24 }}; 25 } 26 27 #[test] test_with_debug_value_references() -> Result<()>28 fn test_with_debug_value_references() -> Result<()> { 29 #[derive(Debug)] 30 struct Foo; 31 let mut val = Foo; 32 33 verify_that!(write_expr_value!("val", val), eq("\n val = Foo,"))?; 34 verify_that!(write_expr_value!("val", &val), eq("\n val = Foo,"))?; 35 verify_that!(write_expr_value!("val", &&val), eq("\n val = Foo,"))?; 36 verify_that!(write_expr_value!("val", &mut val), eq("\n val = Foo,"))?; 37 verify_that!(write_expr_value!("val", &mut &mut val), eq("\n val = Foo,"))?; 38 39 Ok(()) 40 } 41 42 #[test] test_with_non_debug_value_references() -> Result<()>43 fn test_with_non_debug_value_references() -> Result<()> { 44 struct Foo; 45 let mut val = Foo; 46 47 verify_that!(write_expr_value!("val", val), eq("\n val does not implement Debug,"))?; 48 verify_that!(write_expr_value!("val", &val), eq("\n val does not implement Debug,"))?; 49 verify_that!(write_expr_value!("val", &&val), eq("\n val does not implement Debug,"))?; 50 verify_that!(write_expr_value!("val", &mut val), eq("\n val does not implement Debug,"))?; 51 verify_that!( 52 write_expr_value!("val", &mut &mut val), 53 eq("\n val does not implement Debug,") 54 )?; 55 56 Ok(()) 57 } 58 } 59