Flutter Engine
 
Loading...
Searching...
No Matches
comments_unittests.cc File Reference
#include "flutter/tools/licenses_cpp/src/comments.h"
#include "gtest/gtest.h"
#include <sstream>

Go to the source code of this file.

Functions

 TEST (CommentsTest, Simple)
 
 TEST (CommentsTest, Nothing)
 
 TEST (CommentsTest, Multiline)
 
 TEST (CommentsTest, MultilineCpp)
 
 TEST (CommentsTest, CWithLeadingStars)
 
 TEST (CommentsTest, CWithTrailingStars)
 
 TEST (CommentsTest, CTextOnEndingLine)
 
 TEST (CommentsTest, HashComments)
 
 TEST (CommentsTest, JoinCComments)
 
 TEST (CommentsTest, JoinCCommentsNegative)
 
 TEST (CommentsTest, MixmatchComments)
 
 TEST (CommentsTest, MixmatchCommentsWithWhitespace)
 

Function Documentation

◆ TEST() [1/12]

TEST ( CommentsTest  ,
CTextOnEndingLine   
)

Definition at line 104 of file comments_unittests.cc.

104 {
105 std::string test = R"test(
106/*hello
107world*/
108)test";
109
110 std::vector<std::string> comments;
111 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
112 comments.push_back(std::string(comment));
113 });
114
115 ASSERT_EQ(comments.size(), 1u);
116 EXPECT_EQ(comments[0], "hello\nworld");
117}
void IterateComments(const char *buffer, size_t size, std::function< void(std::string_view)> callback)

References IterateComments().

◆ TEST() [2/12]

TEST ( CommentsTest  ,
CWithLeadingStars   
)

Definition at line 70 of file comments_unittests.cc.

70 {
71 std::string test = R"test(
72/*************
73 * hello
74 * world
75 */
76)test";
77
78 std::vector<std::string> comments;
79 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
80 comments.push_back(std::string(comment));
81 });
82
83 ASSERT_EQ(comments.size(), 1u);
84 EXPECT_EQ(comments[0], "hello\nworld\n");
85}

References IterateComments().

◆ TEST() [3/12]

TEST ( CommentsTest  ,
CWithTrailingStars   
)

Definition at line 87 of file comments_unittests.cc.

87 {
88 std::string test = R"test(
89/*************
90 * hello *
91 * world *
92 */
93)test";
94
95 std::vector<std::string> comments;
96 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
97 comments.push_back(std::string(comment));
98 });
99
100 ASSERT_EQ(comments.size(), 1u);
101 EXPECT_EQ(comments[0], "hello\nworld\n");
102}

References IterateComments().

◆ TEST() [4/12]

TEST ( CommentsTest  ,
HashComments   
)

Definition at line 119 of file comments_unittests.cc.

119 {
120 std::string test = R"test(
121# Hello
122# World
123)test";
124
125 std::vector<std::string> comments;
126 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
127 comments.push_back(std::string(comment));
128 });
129
130 ASSERT_EQ(comments.size(), 1u);
131 EXPECT_EQ(comments[0], "Hello\nWorld");
132}

References IterateComments().

◆ TEST() [5/12]

TEST ( CommentsTest  ,
JoinCComments   
)

Definition at line 134 of file comments_unittests.cc.

134 {
135 std::string test = R"test(
136/*Hello*/
137/*World*/
138)test";
139
140 std::vector<std::string> comments;
141 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
142 comments.push_back(std::string(comment));
143 });
144
145 ASSERT_EQ(comments.size(), 1u);
146 EXPECT_EQ(comments[0], "Hello\nWorld");
147}

References IterateComments().

◆ TEST() [6/12]

TEST ( CommentsTest  ,
JoinCCommentsNegative   
)

Definition at line 149 of file comments_unittests.cc.

149 {
150 std::string test = R"test(
151/*Hello*/
152
153/*World*/
154)test";
155
156 std::vector<std::string> comments;
157 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
158 comments.push_back(std::string(comment));
159 });
160
161 ASSERT_EQ(comments.size(), 2u);
162 EXPECT_EQ(comments[0], "Hello");
163 EXPECT_EQ(comments[1], "World");
164}

References IterateComments().

◆ TEST() [7/12]

TEST ( CommentsTest  ,
MixmatchComments   
)

Definition at line 166 of file comments_unittests.cc.

166 {
167 std::string test = R"test(
168// Hello
169/*
170World
171*/
172)test";
173
174 std::vector<std::string> comments;
175 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
176 comments.push_back(std::string(comment));
177 });
178
179 ASSERT_EQ(comments.size(), 1u);
180 EXPECT_EQ(comments[0], "Hello\nWorld\n");
181}

References IterateComments().

◆ TEST() [8/12]

TEST ( CommentsTest  ,
MixmatchCommentsWithWhitespace   
)

Definition at line 183 of file comments_unittests.cc.

183 {
184 std::string test = R"test(
185// Hello
186
187/*
188World
189*/
190)test";
191
192 std::vector<std::string> comments;
193 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
194 comments.push_back(std::string(comment));
195 });
196
197 ASSERT_EQ(comments.size(), 2u);
198 EXPECT_EQ(comments[0], "Hello");
199 EXPECT_EQ(comments[1], "World\n");
200}

References IterateComments().

◆ TEST() [9/12]

TEST ( CommentsTest  ,
Multiline   
)

Definition at line 36 of file comments_unittests.cc.

36 {
37 std::string test = R"test(
38/*
39hello world
40*/
41dfdd
42)test";
43
44 std::vector<std::string> comments;
45 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
46 comments.push_back(std::string(comment));
47 });
48
49 ASSERT_EQ(comments.size(), 1u);
50 EXPECT_EQ(comments[0], "hello world\n");
51}

References IterateComments().

◆ TEST() [10/12]

TEST ( CommentsTest  ,
MultilineCpp   
)

Definition at line 53 of file comments_unittests.cc.

53 {
54 std::string test = R"test(
55doo
56// hello
57// world
58daa
59)test";
60
61 std::vector<std::string> comments;
62 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
63 comments.push_back(std::string(comment));
64 });
65
66 ASSERT_EQ(comments.size(), 1u);
67 EXPECT_EQ(comments[0], "hello\nworld");
68}

References IterateComments().

◆ TEST() [11/12]

TEST ( CommentsTest  ,
Nothing   
)

Definition at line 23 of file comments_unittests.cc.

23 {
24 std::string test = R"test(
25hello world
26)test";
27
28 std::vector<std::string> comments;
29 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
30 comments.push_back(std::string(comment));
31 });
32
33 ASSERT_EQ(comments.size(), 0u);
34}

References IterateComments().

◆ TEST() [12/12]

TEST ( CommentsTest  ,
Simple   
)

Definition at line 9 of file comments_unittests.cc.

9 {
10 std::string test = R"test(
11// Hello
12)test";
13
14 std::vector<std::string> comments;
15 IterateComments(test.c_str(), test.size(), [&](std::string_view comment) {
16 comments.push_back(std::string(comment));
17 });
18
19 ASSERT_EQ(comments.size(), 1u);
20 EXPECT_EQ(comments[0], "Hello");
21}

References IterateComments().