YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/util/string_trim-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 <string>
15
16
#include <gtest/gtest.h>
17
18
#include "yb/util/string_trim.h"
19
#include "yb/util/test_macros.h"
20
21
namespace yb {
22
namespace util {
23
24
1
TEST(StringTrimTest, LeftTrimStr) {
25
1
  ASSERT_EQ("foo ", LeftTrimStr("  \t \f \n \r \v foo "));
26
1
  ASSERT_EQ("oobar", LeftTrimStr("foobar", "fr"));
27
1
}
28
29
1
TEST(StringTrimTest, RightTrimStr) {
30
1
  ASSERT_EQ(" foo", RightTrimStr(" foo\t \f \n \r \v "));
31
1
  ASSERT_EQ("fooba", RightTrimStr("foobar", "fr"));
32
1
}
33
34
1
TEST(StringTrimTest, TrimStr) {
35
1
  ASSERT_EQ("foo", TrimStr(" \t \f \n \r \v foo \t \f \n \r \v "));
36
1
  ASSERT_EQ("ooba", TrimStr("foobar", "fr"));
37
1
}
38
39
1
TEST(StringTrimTest, TestApplyEagerLineContinuation) {
40
1
  ASSERT_EQ("  foo bar\n  baz  ", ApplyEagerLineContinuation("  foo \\\n      bar\n  baz  "));
41
1
  ASSERT_EQ("  foo bar\n  baz  ", ApplyEagerLineContinuation("  foo \\\n   \\\n    bar\n  baz  "));
42
1
}
43
44
1
TEST(StringTrimTest, TestTrimLeadingSpaces) {
45
1
  ASSERT_STR_EQ_VERBOSE_TRIMMED(
46
1
      R"#(
47
1
This is my
48
1
49
1
  Text block
50
1
)#",
51
1
      LeftShiftTextBlock(R"#(
52
1
      This is my
53
1
54
1
        Text block
55
1
      )#"));
56
1
}
57
58
1
TEST(StringTrimTest, TestTrimCppComments) {
59
1
  ASSERT_EQ(
60
1
      R"#(
61
1
Line1
62
1
63
1
Line2
64
1
)#",
65
1
      TrimCppComments(R"#(
66
1
Line1  // This is a comment
67
1
68
1
Line2  // This is a comment too
69
1
)#")
70
1
      );
71
1
}
72
73
1
TEST(StringTrimTest, TrimTrailingWhitespaceFromEveryLine) {
74
1
  ASSERT_EQ(
75
1
      "Line1\nLine2\nLine3\n",
76
1
      TrimTrailingWhitespaceFromEveryLine("Line1   \nLine2\nLine3   \n"));
77
1
  ASSERT_EQ(
78
1
      "Line1\nLine2\nLine3",
79
1
      TrimTrailingWhitespaceFromEveryLine("Line1   \nLine2\nLine3   "));
80
1
  ASSERT_EQ(
81
1
      "Line1  // Some C++ comment\nLine2\n",
82
1
      TrimTrailingWhitespaceFromEveryLine("Line1  // Some C++ comment   \nLine2   \n"));
83
1
  ASSERT_EQ(
84
1
      "Line1  // Some C++ comment\nLine2",
85
1
      TrimTrailingWhitespaceFromEveryLine("Line1  // Some C++ comment   \nLine2   "));
86
1
  ASSERT_EQ(
87
1
      "\n  Line2\nLine3\n",
88
1
      TrimTrailingWhitespaceFromEveryLine("\n  Line2\nLine3   \n"));
89
1
}
90
91
}  // namespace util
92
}  // namespace yb