1 // Copyright 2023 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 use googletest::prelude::*;
16
17 #[test]
all_matcher_works_as_inner_matcher() -> Result<()>18 fn all_matcher_works_as_inner_matcher() -> Result<()> {
19 let value = vec![1];
20 verify_that!(value, contains_each![all!(gt(0), lt(2))])
21 }
22
23 #[test]
matches_pattern_works_as_inner_matcher() -> Result<()>24 fn matches_pattern_works_as_inner_matcher() -> Result<()> {
25 #[derive(Debug)]
26 struct AStruct(i32);
27 verify_that!(vec![AStruct(123)], contains_each![matches_pattern!(AStruct(eq(123)))])
28 }
29
30 #[test]
matches_pattern_works_with_property_as_inner_matcher() -> Result<()>31 fn matches_pattern_works_with_property_as_inner_matcher() -> Result<()> {
32 #[derive(Debug)]
33 struct AStruct(i32);
34 impl AStruct {
35 fn get_value(&self) -> i32 {
36 self.0
37 }
38 }
39 verify_that!(
40 vec![AStruct(123)],
41 contains_each![matches_pattern!(AStruct {
42 get_value(): eq(123)
43 })]
44 )
45 }
46
47 #[test]
contains_each_works_as_inner_matcher() -> Result<()>48 fn contains_each_works_as_inner_matcher() -> Result<()> {
49 #[derive(Debug)]
50 struct AStruct(Vec<i32>);
51 verify_that!(AStruct(vec![123]), matches_pattern!(AStruct(contains_each![eq(123)])))
52 }
53
54 #[test]
pointwise_works_as_inner_matcher() -> Result<()>55 fn pointwise_works_as_inner_matcher() -> Result<()> {
56 #[derive(Debug)]
57 struct AStruct(Vec<i32>);
58 verify_that!(AStruct(vec![123]), matches_pattern!(AStruct(pointwise!(eq, [123]))))
59 }
60
61 #[test]
elements_are_works_as_inner_matcher() -> Result<()>62 fn elements_are_works_as_inner_matcher() -> Result<()> {
63 #[derive(Debug)]
64 struct AStruct(Vec<i32>);
65 verify_that!(AStruct(vec![123]), matches_pattern!(AStruct(elements_are![eq(123)])))
66 }
67
68 #[test]
tuple_works_as_inner_matcher() -> Result<()>69 fn tuple_works_as_inner_matcher() -> Result<()> {
70 verify_that!(vec![(123,)], elements_are![(eq(123),)])
71 }
72