|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include <string> |
| 19 | +#include <tuple> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "common/config.h" |
| 23 | +#include "common/string_util.h" |
| 24 | +#include "glog/logging.h" |
| 25 | +#include "gtest/gtest.h" |
| 26 | + |
| 27 | +int main(int argc, char** argv) { |
| 28 | + doris::cloud::config::init(nullptr, true); |
| 29 | + ::testing::InitGoogleTest(&argc, argv); |
| 30 | + return RUN_ALL_TESTS(); |
| 31 | +} |
| 32 | + |
| 33 | +TEST(StringUtilTest, test_string_strip) { |
| 34 | + // clang-format off |
| 35 | + // str expect to_drop |
| 36 | + std::vector<std::tuple<std::string, std::string, std::string>> leading_inputs { |
| 37 | + {"" , "" , "" }, |
| 38 | + {"" , "" , "/" }, |
| 39 | + {"/" , "" , "/" }, |
| 40 | + {"\t////" , "" , "/ \t"}, |
| 41 | + {"/a///" , "a///" , "/" }, |
| 42 | + {"/a/b/c/", "a/b/c/", "/" }, |
| 43 | + {"a/b/c/" , "a/b/c/", "/" }, |
| 44 | + {"a/b/c/" , "/b/c/" , "a" }, |
| 45 | + }; |
| 46 | + int idx = 0; |
| 47 | + for (auto&& i : leading_inputs) { |
| 48 | + doris::cloud::strip_leading(std::get<0>(i), std::get<2>(i)); |
| 49 | + EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx; |
| 50 | + ++idx; |
| 51 | + } |
| 52 | + |
| 53 | + idx = 0; |
| 54 | + std::vector<std::tuple<std::string, std::string, std::string>> trailing_inputs { |
| 55 | + {"" , "" , "" }, |
| 56 | + {"/" , "" , "/" }, |
| 57 | + {"////\t" , "" , "/ \t"}, |
| 58 | + {"/a///" , "/a" , "/" }, |
| 59 | + {"/a/b/c/", "/a/b/c", "/" }, |
| 60 | + {"a/b/c/" , "a/b/c" , "/" }, |
| 61 | + {"a/b/c" , "a/b/c" , "/" }, |
| 62 | + {"a/b/c" , "a/b/" , "c" }, |
| 63 | + }; |
| 64 | + for (auto&& i : trailing_inputs) { |
| 65 | + doris::cloud::strip_trailing(std::get<0>(i), std::get<2>(i)); |
| 66 | + EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx; |
| 67 | + ++idx; |
| 68 | + } |
| 69 | + |
| 70 | + idx = 0; |
| 71 | + std::vector<std::tuple<std::string, std::string>> trim_inputs { |
| 72 | + {"" , "" }, |
| 73 | + {"" , "" }, |
| 74 | + {"/" , "" }, |
| 75 | + {"\t////" , "" }, |
| 76 | + {"/a ///" , "a" }, |
| 77 | + {"/a/b/c/" , "a/b/c"}, |
| 78 | + {"a/b/c/" , "a/b/c"}, |
| 79 | + {"a/b/c" , "a/b/c"}, |
| 80 | + {"\t/bbc///" , "bbc" }, |
| 81 | + {"ab c" , "ab c" }, |
| 82 | + {"\t /a/b/c \t/", "a/b/c"}, |
| 83 | + }; |
| 84 | + for (auto&& i : trim_inputs) { |
| 85 | + doris::cloud::trim(std::get<0>(i)); |
| 86 | + EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx; |
| 87 | + ++idx; |
| 88 | + } |
| 89 | + |
| 90 | + // clang-format on |
| 91 | +} |
0 commit comments