Skip to content

Commit edecf70

Browse files
committed
Use star instead of ref in the property matchers.
1 parent cc5d3e7 commit edecf70

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

googletest/src/matchers/matches_pattern.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
/// # .unwrap();
163163
/// ```
164164
///
165-
/// If the method returns a reference, precede it with the keyword `ref`:
165+
/// If the method returns a reference, precede it with a `*`:
166166
///
167167
/// ```
168168
/// # use googletest::prelude::*;
@@ -177,7 +177,7 @@
177177
///
178178
/// # let my_struct = MyStruct { a_field: "Something to believe in".into() };
179179
/// verify_that!(my_struct, matches_pattern!(MyStruct {
180-
/// ref get_a_field_ref(): starts_with("Something"),
180+
/// *get_a_field_ref(): starts_with("Something"),
181181
/// }))
182182
/// # .unwrap();
183183
/// ```
@@ -277,11 +277,11 @@ macro_rules! matches_pattern_internal {
277277

278278
(
279279
[$($struct_name:tt)*],
280-
{ ref $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
280+
{ * $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
281281
) => {
282282
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(
283283
stringify!($($struct_name)*),
284-
all!(property!(ref $($struct_name)*.$property_name($($argument),*), $matcher))
284+
all!(property!(* $($struct_name)*.$property_name($($argument),*), $matcher))
285285
)
286286
};
287287

@@ -309,10 +309,10 @@ macro_rules! matches_pattern_internal {
309309

310310
(
311311
[$($struct_name:tt)*],
312-
{ ref $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr, $($rest:tt)* }
312+
{ * $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr, $($rest:tt)* }
313313
) => {
314314
$crate::matches_pattern_internal!(
315-
all!(property!(ref $($struct_name)*.$property_name($($argument),*), $matcher)),
315+
all!(property!(* $($struct_name)*.$property_name($($argument),*), $matcher)),
316316
[$($struct_name)*],
317317
{ $($rest)* }
318318
)
@@ -343,11 +343,11 @@ macro_rules! matches_pattern_internal {
343343
(
344344
all!($($processed:tt)*),
345345
[$($struct_name:tt)*],
346-
{ ref $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
346+
{ * $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
347347
) => {
348348
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(stringify!($($struct_name)*), all!(
349349
$($processed)*,
350-
property!(ref $($struct_name)*.$property_name($($argument),*), $matcher)
350+
property!(* $($struct_name)*.$property_name($($argument),*), $matcher)
351351
))
352352
};
353353

@@ -384,12 +384,12 @@ macro_rules! matches_pattern_internal {
384384
(
385385
all!($($processed:tt)*),
386386
[$($struct_name:tt)*],
387-
{ ref $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr, $($rest:tt)* }
387+
{ * $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr, $($rest:tt)* }
388388
) => {
389389
$crate::matches_pattern_internal!(
390390
all!(
391391
$($processed)*,
392-
property!(ref $($struct_name)*.$property_name($($argument),*), $matcher)
392+
property!(* $($struct_name)*.$property_name($($argument),*), $matcher)
393393
),
394394
[$($struct_name)*],
395395
{ $($rest)* }

googletest/src/matchers/property_matcher.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
/// failure, it will be invoked a second time, with the assertion failure output
4545
/// reflecting the *second* invocation.
4646
///
47-
/// If the method returns a *reference*, then it must be preceded by the keyword
48-
/// `ref`:
47+
/// If the method returns a *reference*, then it must be preceded by a `*`:
4948
///
5049
/// ```
5150
/// # use googletest::prelude::*;
@@ -58,7 +57,7 @@
5857
/// }
5958
///
6059
/// # let value = vec![MyStruct { a_field: 100 }];
61-
/// verify_that!(value, contains(property!(ref MyStruct.get_a_field(), eq(100))))
60+
/// verify_that!(value, contains(property!(*MyStruct.get_a_field(), eq(100))))
6261
/// # .unwrap();
6362
/// ```
6463
///
@@ -93,7 +92,7 @@
9392
/// }
9493
///
9594
/// let value = MyStruct { a_string: "A string".into() };
96-
/// verify_that!(value, property!(ref MyStruct.get_a_string(), eq("A string"))) // Does not compile
95+
/// verify_that!(value, property!(*MyStruct.get_a_string(), eq("A string"))) // Does not compile
9796
/// # .unwrap();
9897
/// ```
9998
///
@@ -120,7 +119,7 @@ macro_rules! property_internal {
120119
$m)
121120
}};
122121

123-
(ref $($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{
122+
(* $($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{
124123
use $crate::matchers::__internal_unstable_do_not_depend_on_these::property_ref_matcher;
125124
property_ref_matcher(
126125
|o: &$($t)::+| o.$method($($argument),*),

googletest/tests/matches_pattern_test.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ fn includes_struct_name_in_description_with_ref_property() -> Result<()> {
594594
}
595595
let actual = AStruct { field: 123 };
596596

597-
let result = verify_that!(actual, matches_pattern!(AStruct { ref get_field(): eq(234) }));
597+
let result = verify_that!(actual, matches_pattern!(AStruct { *get_field(): eq(234) }));
598598

599599
verify_that!(
600600
result,
@@ -641,10 +641,8 @@ fn includes_struct_name_in_description_with_ref_property_after_field() -> Result
641641
}
642642
let actual = AStruct { field: 123 };
643643

644-
let result = verify_that!(
645-
actual,
646-
matches_pattern!(AStruct { field: eq(123), ref get_field(): eq(234) })
647-
);
644+
let result =
645+
verify_that!(actual, matches_pattern!(AStruct { field: eq(123), *get_field(): eq(234) }));
648646

649647
verify_that!(
650648
result,
@@ -781,7 +779,7 @@ fn matches_struct_with_a_method_returning_a_reference() -> Result<()> {
781779

782780
let actual = AStruct { a_field: 123 };
783781

784-
verify_that!(actual, matches_pattern!(AStruct { ref get_field_ref(): eq(123) }))
782+
verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(): eq(123) }))
785783
}
786784

787785
#[test]
@@ -799,7 +797,7 @@ fn matches_struct_with_a_method_returning_a_reference_with_trailing_comma() -> R
799797

800798
let actual = AStruct { a_field: 123 };
801799

802-
verify_that!(actual, matches_pattern!(AStruct { ref get_field_ref(): eq(123), }))
800+
verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(): eq(123), }))
803801
}
804802

805803
#[test]
@@ -817,7 +815,7 @@ fn matches_struct_with_a_method_taking_two_parameters_ret_ref() -> Result<()> {
817815

818816
let actual = AStruct { a_field: 1 };
819817

820-
verify_that!(actual, matches_pattern!(AStruct { ref get_field_ref(2, 3): eq(1) }))
818+
verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(2, 3): eq(1) }))
821819
}
822820

823821
#[test]
@@ -839,7 +837,7 @@ fn matches_struct_with_a_method_returning_reference_taking_enum_value_parameter(
839837

840838
let actual = AStruct { a_field: 1 };
841839

842-
verify_that!(actual, matches_pattern!(AStruct { ref get_field_ref(AnEnum::AVariant): eq(1) }))
840+
verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(AnEnum::AVariant): eq(1) }))
843841
}
844842

845843
#[test]
@@ -857,7 +855,7 @@ fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_re
857855

858856
let actual = AStruct { a_field: 1 };
859857

860-
verify_that!(actual, matches_pattern!(AStruct { ref get_field_ref(2, 3,): eq(1) }))
858+
verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(2, 3,): eq(1) }))
861859
}
862860

863861
#[test]
@@ -990,7 +988,7 @@ fn matches_struct_with_a_method_returning_reference_followed_by_a_field() -> Res
990988

991989
verify_that!(
992990
actual,
993-
matches_pattern!(AStruct { ref get_field_ref(): eq(123), another_field: eq(234) })
991+
matches_pattern!(AStruct { *get_field_ref(): eq(123), another_field: eq(234) })
994992
)
995993
}
996994

@@ -1013,7 +1011,7 @@ fn matches_struct_with_a_method_returning_reference_followed_by_a_field_with_tra
10131011

10141012
verify_that!(
10151013
actual,
1016-
matches_pattern!(AStruct { ref get_field_ref(): eq(123), another_field: eq(234), })
1014+
matches_pattern!(AStruct { *get_field_ref(): eq(123), another_field: eq(234), })
10171015
)
10181016
}
10191017

@@ -1035,7 +1033,7 @@ fn matches_struct_with_a_method_taking_two_parameters_ret_ref_and_field() -> Res
10351033

10361034
verify_that!(
10371035
actual,
1038-
matches_pattern!(AStruct { ref get_field_ref(2, 3): eq(1), another_field: eq(123) })
1036+
matches_pattern!(AStruct { *get_field_ref(2, 3): eq(1), another_field: eq(123) })
10391037
)
10401038
}
10411039

@@ -1061,7 +1059,7 @@ fn matches_struct_with_a_method_taking_enum_value_param_ret_ref_followed_by_fiel
10611059

10621060
verify_that!(
10631061
actual,
1064-
matches_pattern!(AStruct { ref get_field_ref(AnEnum::AVariant): eq(1), another_field: eq(2) })
1062+
matches_pattern!(AStruct { *get_field_ref(AnEnum::AVariant): eq(1), another_field: eq(2) })
10651063
)
10661064
}
10671065

@@ -1084,7 +1082,7 @@ fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_re
10841082

10851083
verify_that!(
10861084
actual,
1087-
matches_pattern!(AStruct { ref get_field_ref(2, 3,): eq(1), another_field: eq(123) })
1085+
matches_pattern!(AStruct { *get_field_ref(2, 3,): eq(1), another_field: eq(123) })
10881086
)
10891087
}
10901088

@@ -1217,7 +1215,7 @@ fn matches_struct_with_a_field_followed_by_a_method_returning_reference() -> Res
12171215

12181216
verify_that!(
12191217
actual,
1220-
matches_pattern!(AStruct { another_field: eq(234), ref get_field_ref(): eq(123) })
1218+
matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(): eq(123) })
12211219
)
12221220
}
12231221

@@ -1240,7 +1238,7 @@ fn matches_struct_with_a_field_followed_by_a_method_returning_ref_and_trailing_c
12401238

12411239
verify_that!(
12421240
actual,
1243-
matches_pattern!(AStruct { another_field: eq(234), ref get_field_ref(): eq(123), })
1241+
matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(): eq(123), })
12441242
)
12451243
}
12461244

@@ -1262,7 +1260,7 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref() -> Res
12621260

12631261
verify_that!(
12641262
actual,
1265-
matches_pattern!(AStruct { another_field: eq(234), ref get_field_ref(2, 3): eq(123) })
1263+
matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(2, 3): eq(123) })
12661264
)
12671265
}
12681266

@@ -1288,7 +1286,7 @@ fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref(
12881286

12891287
verify_that!(
12901288
actual,
1291-
matches_pattern!(AStruct { another_field: eq(2), ref get_field_ref(AnEnum::AVariant): eq(1) })
1289+
matches_pattern!(AStruct { another_field: eq(2), *get_field_ref(AnEnum::AVariant): eq(1) })
12921290
)
12931291
}
12941292

@@ -1311,7 +1309,7 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_com
13111309

13121310
verify_that!(
13131311
actual,
1314-
matches_pattern!(AStruct { another_field: eq(234), ref get_field_ref(2, 3,): eq(123) })
1312+
matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(2, 3,): eq(123) })
13151313
)
13161314
}
13171315

@@ -1479,7 +1477,7 @@ fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field(
14791477
actual,
14801478
matches_pattern!(AStruct {
14811479
another_field: eq(234),
1482-
ref get_field_ref(): eq(123),
1480+
*get_field_ref(): eq(123),
14831481
a_third_field: eq(345)
14841482
})
14851483
)
@@ -1507,7 +1505,7 @@ fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field_
15071505
actual,
15081506
matches_pattern!(AStruct {
15091507
another_field: eq(234),
1510-
ref get_field_ref(): eq(123),
1508+
*get_field_ref(): eq(123),
15111509
a_third_field: eq(345),
15121510
})
15131511
)
@@ -1535,7 +1533,7 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref_followed
15351533
actual,
15361534
matches_pattern!(AStruct {
15371535
another_field: eq(234),
1538-
ref get_field_ref(2, 3): eq(123),
1536+
*get_field_ref(2, 3): eq(123),
15391537
a_third_field: eq(345),
15401538
})
15411539
)
@@ -1567,7 +1565,7 @@ fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref_
15671565
actual,
15681566
matches_pattern!(AStruct {
15691567
another_field: eq(2),
1570-
ref get_field_ref(AnEnum::AVariant): eq(1),
1568+
*get_field_ref(AnEnum::AVariant): eq(1),
15711569
a_third_field: eq(3),
15721570
})
15731571
)
@@ -1595,7 +1593,7 @@ fn matches_struct_with_a_field_followed_by_a_method_with_params_trailing_comma_r
15951593
actual,
15961594
matches_pattern!(AStruct {
15971595
another_field: eq(234),
1598-
ref get_field_ref(2, 3,): eq(123),
1596+
*get_field_ref(2, 3,): eq(123),
15991597
a_third_field: eq(345),
16001598
})
16011599
)

googletest/tests/property_matcher_test.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn matches_struct_with_matching_property_with_parameters_with_trailing_comma() -
6767
#[test]
6868
fn matches_struct_with_matching_property_ref() -> Result<()> {
6969
let value = SomeStruct { a_property: 10 };
70-
verify_that!(value, property!(ref SomeStruct.get_property_ref(), eq(10)))
70+
verify_that!(value, property!(*SomeStruct.get_property_ref(), eq(10)))
7171
}
7272

7373
#[test]
@@ -82,7 +82,7 @@ fn matches_struct_with_matching_string_reference_property() -> Result<()> {
8282
}
8383
}
8484
let value = StructWithString { property: "Something".into() };
85-
verify_that!(value, property!(ref StructWithString.get_property_ref(), eq("Something")))
85+
verify_that!(value, property!(*StructWithString.get_property_ref(), eq("Something")))
8686
}
8787

8888
#[test]
@@ -97,19 +97,19 @@ fn matches_struct_with_matching_slice_property() -> Result<()> {
9797
}
9898
}
9999
let value = StructWithVec { property: vec![1, 2, 3] };
100-
verify_that!(value, property!(ref StructWithVec.get_property_ref(), eq([1, 2, 3])))
100+
verify_that!(value, property!(*StructWithVec.get_property_ref(), eq([1, 2, 3])))
101101
}
102102

103103
#[test]
104104
fn matches_struct_with_matching_property_ref_with_parameters() -> Result<()> {
105105
let value = SomeStruct { a_property: 10 };
106-
verify_that!(value, property!(ref SomeStruct.get_property_ref_with_params(2, 3), eq(10)))
106+
verify_that!(value, property!(*SomeStruct.get_property_ref_with_params(2, 3), eq(10)))
107107
}
108108

109109
#[test]
110110
fn matches_struct_with_matching_property_ref_with_parameters_and_trailing_comma() -> Result<()> {
111111
let value = SomeStruct { a_property: 10 };
112-
verify_that!(value, property!(ref SomeStruct.get_property_ref_with_params(2, 3,), eq(10)))
112+
verify_that!(value, property!(*SomeStruct.get_property_ref_with_params(2, 3,), eq(10)))
113113
}
114114

115115
#[test]
@@ -155,15 +155,15 @@ fn explains_mismatch_referencing_explanation_of_inner_matcher() -> Result<()> {
155155
#[test]
156156
fn describes_itself_in_matching_case_for_ref() -> Result<()> {
157157
verify_that!(
158-
property!(ref SomeStruct.get_property_ref(), eq(1)).describe(MatcherResult::Match),
158+
property!(*SomeStruct.get_property_ref(), eq(1)).describe(MatcherResult::Match),
159159
eq("has property `get_property_ref()`, which is equal to 1")
160160
)
161161
}
162162

163163
#[test]
164164
fn describes_itself_in_not_matching_case_for_ref() -> Result<()> {
165165
verify_that!(
166-
property!(ref SomeStruct.get_property_ref(), eq(1)).describe(MatcherResult::NoMatch),
166+
property!(*SomeStruct.get_property_ref(), eq(1)).describe(MatcherResult::NoMatch),
167167
eq("has property `get_property_ref()`, which isn't equal to 1")
168168
)
169169
}
@@ -178,7 +178,7 @@ fn explains_mismatch_referencing_explanation_of_inner_matcher_for_ref() -> Resul
178178
}
179179
let value = SomeStruct { a_property: 2 };
180180
let result =
181-
verify_that!(value, property!(ref SomeStruct.get_a_collection_ref(), container_eq([1])));
181+
verify_that!(value, property!(*SomeStruct.get_a_collection_ref(), container_eq([1])));
182182

183183
verify_that!(
184184
result,

0 commit comments

Comments
 (0)