1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gn/vector_utils.h"
6
7 #include "util/test/test.h"
8
9 #include <string>
10
TEST(VectorSetSorter,AsVectorWithStrings)11 TEST(VectorSetSorter, AsVectorWithStrings) {
12 VectorSetSorter<std::string> sorter;
13
14 std::vector<std::string> input = {
15 "World!", "Hello", "bonjour", "Hello", "monde!", "World!",
16 };
17
18 sorter.Add(input.begin(), input.end());
19 auto result = sorter.AsVector();
20
21 ASSERT_EQ(result.size(), 4u) << result.size();
22 EXPECT_STREQ(result[0].c_str(), "Hello");
23 EXPECT_STREQ(result[1].c_str(), "World!");
24 EXPECT_STREQ(result[2].c_str(), "bonjour");
25 EXPECT_STREQ(result[3].c_str(), "monde!");
26 }
27
TEST(VectorSetSorter,IterateOverWithStrings)28 TEST(VectorSetSorter, IterateOverWithStrings) {
29 VectorSetSorter<std::string> sorter;
30
31 std::vector<std::string> input = {
32 "World!", "Hello", "bonjour", "Hello", "monde!", "World!",
33 };
34
35 sorter.Add(input.begin(), input.end());
36
37 std::vector<std::string> result;
38
39 sorter.IterateOver(
40 [&result](const std::string& str) { result.push_back(str); });
41
42 ASSERT_EQ(result.size(), 4u) << result.size();
43 EXPECT_STREQ(result[0].c_str(), "Hello");
44 EXPECT_STREQ(result[1].c_str(), "World!");
45 EXPECT_STREQ(result[2].c_str(), "bonjour");
46 EXPECT_STREQ(result[3].c_str(), "monde!");
47 }
48