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 <string_view> 6 7 #include "base/strings/string_view_rust.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 namespace base { 11 namespace { 12 TEST(BaseStringViewRustTest,StrRoundTrip)13TEST(BaseStringViewRustTest, StrRoundTrip) { 14 std::string data = "hello"; 15 std::string_view data_piece(data); 16 rust::Str rust_str = StringViewToRustStrUTF8(data_piece); 17 EXPECT_EQ(5ul, rust_str.length()); 18 std::string_view data_piece2 = RustStrToStringView(rust_str); 19 EXPECT_EQ(data_piece, data_piece2); 20 } 21 TEST(BaseStringViewRustTest,StrToSlice)22TEST(BaseStringViewRustTest, StrToSlice) { 23 std::string data = "hello"; 24 std::string_view data_piece(data); 25 rust::Slice<const uint8_t> rust_slice = StringViewToRustSlice(data_piece); 26 EXPECT_EQ(5ul, rust_slice.length()); 27 EXPECT_EQ('e', rust_slice[1]); 28 } 29 30 } // namespace 31 } // namespace base 32