/Users/deen/code/yugabyte-db/src/yb/util/split-test.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include <gmock/gmock.h> |
15 | | |
16 | | #include "yb/util/split.h" |
17 | | #include "yb/util/status.h" |
18 | | #include "yb/util/test_macros.h" |
19 | | |
20 | | |
21 | | namespace yb { |
22 | | namespace util { |
23 | | |
24 | 1 | TEST(TestSplitArgs, Simple) { |
25 | 1 | Slice input("one two three"); |
26 | 1 | std::vector<Slice> result; |
27 | | |
28 | 1 | ASSERT_OK(SplitArgs(input, &result)); |
29 | 1 | ASSERT_EQ(3, result.size()); |
30 | 1 | ASSERT_THAT(result, ::testing::ElementsAre("one", "two", "three")); |
31 | 1 | } |
32 | | |
33 | 1 | TEST(TestSplitArgs, SimpleWithSpaces) { |
34 | 1 | Slice input(" one two three "); |
35 | 1 | std::vector<Slice> result; |
36 | | |
37 | 1 | ASSERT_OK(SplitArgs(input, &result)); |
38 | 1 | ASSERT_EQ(3, result.size()); |
39 | 1 | ASSERT_THAT(result, ::testing::ElementsAre("one", "two", "three")); |
40 | 1 | } |
41 | | |
42 | 1 | TEST(TestSplitArgs, SimpleWithQuotes) { |
43 | 1 | Slice input("one \"2a 2b\" '3a 3b'"); |
44 | 1 | std::vector<Slice> result; |
45 | | |
46 | 1 | ASSERT_OK(SplitArgs(input, &result)); |
47 | 1 | ASSERT_EQ(3, result.size()); |
48 | 1 | ASSERT_THAT(result, ::testing::ElementsAre("one", "2a 2b", "3a 3b")); |
49 | 1 | } |
50 | | |
51 | 1 | TEST(TestSplitArgs, BadWithQuotes) { |
52 | 1 | Slice input("one\"2a 2b\" '3a 3b'"); |
53 | 1 | std::vector<Slice> result; |
54 | | |
55 | 1 | ASSERT_FALSE(SplitArgs(input, &result).ok()); |
56 | 1 | } |
57 | | |
58 | 1 | TEST(TestSplitArgs, Empty) { |
59 | 1 | Slice input(""); |
60 | 1 | std::vector<Slice> result; |
61 | | |
62 | 1 | ASSERT_OK(SplitArgs(input, &result)); |
63 | 1 | ASSERT_EQ(0, result.size()); |
64 | 1 | } |
65 | | |
66 | 1 | TEST(TestSplitArgs, Error) { |
67 | 1 | Slice input("one \"2a 2b\"three"); |
68 | 1 | std::vector<Slice> result; |
69 | | |
70 | 1 | ASSERT_FALSE(SplitArgs(input, &result).ok()); |
71 | 1 | ASSERT_EQ(0, result.size()); |
72 | 1 | } |
73 | | |
74 | 1 | TEST(TestSplitArgs, UnbalancedSingle) { |
75 | 1 | Slice input("one '2a 2b three"); |
76 | 1 | std::vector<Slice> result; |
77 | | |
78 | 1 | ASSERT_FALSE(SplitArgs(input, &result).ok()); |
79 | 1 | ASSERT_EQ(0, result.size()); |
80 | 1 | } |
81 | | |
82 | 1 | TEST(TestSplitArgs, UnbalancedDouble) { |
83 | 1 | Slice input("one \"2a 2b three"); |
84 | 1 | std::vector<Slice> result; |
85 | | |
86 | 1 | ASSERT_FALSE(SplitArgs(input, &result).ok()); |
87 | 1 | ASSERT_EQ(0, result.size()); |
88 | 1 | } |
89 | | |
90 | | } // namespace util |
91 | | } // namespace yb |