Skip to content

Commit 696dfb8

Browse files
Merge pull request google#663 from google:test_reference_type
PiperOrigin-RevId: 779109808
2 parents cb856f3 + d3202de commit 696dfb8

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 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+
#[derive(Debug)]
16+
struct ArenaHolder<'a, T: ?Sized> {
17+
value: &'a T,
18+
}
19+
20+
impl<'a, T: PartialEq + ?Sized> PartialEq<T> for ArenaHolder<'a, T> {
21+
fn eq(&self, other: &T) -> bool {
22+
self.value == other
23+
}
24+
}
25+
26+
struct Strukt {
27+
a_field: String,
28+
}
29+
30+
impl<'a> ArenaHolder<'a, Strukt> {
31+
fn get_a_field(&self) -> ArenaHolder<'_, str> {
32+
ArenaHolder { value: &self.value.a_field }
33+
}
34+
}
35+
36+
#[cfg(test)]
37+
mod tests {
38+
use super::*;
39+
use googletest::prelude::*;
40+
41+
#[gtest]
42+
fn test() {
43+
let arena = [Strukt { a_field: "hello".into() }];
44+
45+
let holder = ArenaHolder { value: &arena[0] };
46+
47+
let inner_holder = holder.get_a_field();
48+
49+
expect_that!(inner_holder, eq("hello"));
50+
}
51+
}

0 commit comments

Comments
 (0)