• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 use googletest::prelude::*;
9 
10 // Tests that an proto file that declares edition="2023" works. Note that this
11 // is _not_ a test for Rust Edition 2023 (which doesn't exist) but instead
12 // Protobuf Edition 2023 (which exists).
13 
14 #[gtest]
check_edition2023_works()15 fn check_edition2023_works() {
16     let msg = edition2023_rust_proto::EditionsMessage::new();
17     assert_that!(msg.plain_field_opt().into_inner(), eq(0));
18     assert_that!(msg.implicit_presence_field(), eq(0));
19 }
20 
21 #[gtest]
string_view_works()22 fn string_view_works() {
23     let mut msg = edition2023_rust_proto::EditionsMessage::new();
24     assert_that!(msg.str_view(), eq(""));
25     assert_that!(msg.has_str_view(), eq(false));
26     msg.set_str_view("hello");
27     assert_that!(msg.str_view(), eq("hello"));
28     assert_that!(msg.has_str_view(), eq(true));
29 }
30 
31 #[gtest]
repeated_string_view_works()32 fn repeated_string_view_works() {
33     let mut msg = edition2023_rust_proto::EditionsMessage::new();
34     assert_that!(msg.repeated_str_view().len(), eq(0));
35     msg.repeated_str_view_mut().push("first");
36     assert_that!(msg.repeated_str_view().len(), eq(1));
37     assert_that!(msg.repeated_str_view().get(0), some(eq("first")));
38 }
39