string_util_test.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "Firestore/Port/string_util.h"
  17. #include <gtest/gtest.h>
  18. #include <leveldb/db.h>
  19. using Firestore::PrefixSuccessor;
  20. using Firestore::ImmediateSuccessor;
  21. using leveldb::Slice;
  22. TEST(Util, PrefixSuccessor) {
  23. EXPECT_EQ(PrefixSuccessor("a"), "b");
  24. EXPECT_EQ(PrefixSuccessor("aaAA"), "aaAB");
  25. EXPECT_EQ(PrefixSuccessor("aaa\xff"), "aab");
  26. EXPECT_EQ(PrefixSuccessor(std::string("\x00", 1)), "\x01");
  27. EXPECT_EQ(PrefixSuccessor("az\xe0"), "az\xe1");
  28. EXPECT_EQ(PrefixSuccessor("\xff\xff\xff"), "");
  29. EXPECT_EQ(PrefixSuccessor(""), "");
  30. }
  31. TEST(Util, ImmediateSuccessor) {
  32. EXPECT_EQ(ImmediateSuccessor("hello"), Slice("hello\0", 6));
  33. EXPECT_EQ(ImmediateSuccessor(""), Slice("\0", 1));
  34. }