kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/indexer/proto/comments_test.cc (about)

     1  /*
     2   * Copyright 2018 The Kythe Authors. All rights reserved.
     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  
    17  #include "kythe/cxx/indexer/proto/comments.h"
    18  
    19  #include "gmock/gmock.h"
    20  #include "gtest/gtest.h"
    21  
    22  namespace kythe {
    23  namespace {
    24  
    25  using ::testing::Eq;
    26  
    27  TEST(CommentsTest, Empty) { EXPECT_THAT(StripCommentMarkers(""), Eq("")); }
    28  
    29  TEST(CommentsTest, LeadingMarker1) {
    30    EXPECT_THAT(StripCommentMarkers("// foo"), Eq("foo"));
    31    EXPECT_THAT(StripCommentMarkers("  // foo"), Eq("foo"));
    32  }
    33  
    34  TEST(CommentsTest, TrailingSpace) {
    35    EXPECT_THAT(StripCommentMarkers(" "), Eq(""));
    36    EXPECT_THAT(StripCommentMarkers("bar "), Eq("bar"));
    37  }
    38  
    39  TEST(CommentsTest, LeadingAndTrailing1) {
    40    EXPECT_THAT(StripCommentMarkers("// foo  "), Eq("foo"));
    41    EXPECT_THAT(StripCommentMarkers("  // foo  "), Eq("foo"));
    42  }
    43  
    44  TEST(CommentsTest, LeadingMarkers) {
    45    EXPECT_THAT(StripCommentMarkers("// a b c\n"
    46                                    "  // d e f\n"
    47                                    "  // g"),
    48                Eq("a b c\n"
    49                   "d e f\n"
    50                   "g"));
    51  }
    52  
    53  TEST(CommentsTest, LeadingAndTrailing) {
    54    EXPECT_THAT(StripCommentMarkers(" // the days are bright \n"
    55                                    " // and filled with pain \t\n"
    56                                    "// enclose me in your gentle  \n"
    57                                    " //\n"
    58                                    "  rain "),
    59                Eq("the days are bright\n"
    60                   "and filled with pain\n"
    61                   "enclose me in your gentle\n"
    62                   "\n"
    63                   "rain"));
    64  }
    65  
    66  TEST(CommentsTest, BlockComment) {
    67    EXPECT_THAT(StripCommentMarkers("/* all your base\n"
    68                                    " * are belong\n"
    69                                    " *\n"
    70                                    " * to us\n"
    71                                    " */"),
    72                Eq("all your base\n"
    73                   "are belong\n"
    74                   "\n"
    75                   "to us\n"));
    76  }
    77  
    78  }  // namespace
    79  }  // namespace kythe