string_piece_rust_unittest.cc 892 B

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