xref: /aosp_15_r20/external/cronet/base/strings/string_piece_rust_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/strings/string_piece_rust.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 
9 namespace base {
10 namespace {
11 
TEST(BaseStringPieceRustTest,StrRoundTrip)12 TEST(BaseStringPieceRustTest, StrRoundTrip) {
13   std::string data = "hello";
14   StringPiece data_piece(data);
15   rust::Str rust_str = StringPieceToRustStrUTF8(data_piece);
16   EXPECT_EQ(5ul, rust_str.length());
17   StringPiece data_piece2 = RustStrToStringPiece(rust_str);
18   EXPECT_EQ(data_piece, data_piece2);
19 }
20 
TEST(BaseStringPieceRustTest,StrToSlice)21 TEST(BaseStringPieceRustTest, StrToSlice) {
22   std::string data = "hello";
23   StringPiece data_piece(data);
24   rust::Slice<const uint8_t> rust_slice = StringPieceToRustSlice(data_piece);
25   EXPECT_EQ(5ul, rust_slice.length());
26   EXPECT_EQ('e', rust_slice[1]);
27 }
28 
29 }  // namespace
30 }  // namespace base
31