OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 #include <gtest/gtest.h> |
| 18 #include "../../src/plugin/TokenSequence.h" |
| 19 |
| 20 TEST(TokenSequence, MustHaveDelimiters) |
| 21 { |
| 22 ASSERT_THROW( |
| 23 { |
| 24 TokenSequence<std::wstring> s(L"foo", L""); |
| 25 }, |
| 26 std::runtime_error |
| 27 ); |
| 28 } |
| 29 |
| 30 TEST(TokenSequence, Cbegin1) |
| 31 { |
| 32 TokenSequence<std::wstring> s(L"", L" "); |
| 33 auto a = s.cbegin(); |
| 34 auto b = s.cbegin(); |
| 35 ASSERT_TRUE(a == b); |
| 36 } |
| 37 |
| 38 TEST(TokenSequence, Cbegin2) |
| 39 { |
| 40 TokenSequence<std::wstring> s(L"foo", L" "); |
| 41 auto a = s.cbegin(); |
| 42 auto b = s.cbegin(); |
| 43 ASSERT_TRUE(a == b); |
| 44 } |
| 45 |
| 46 TEST(TokenSequence, Cend1) |
| 47 { |
| 48 TokenSequence<std::wstring> s(L"", L" "); |
| 49 auto a = s.cend(); |
| 50 auto b = s.cend(); |
| 51 ASSERT_TRUE(a == b); |
| 52 } |
| 53 |
| 54 TEST(TokenSequence, Cend2) |
| 55 { |
| 56 TokenSequence<std::wstring> s(L"foo", L" "); |
| 57 auto a = s.cend(); |
| 58 auto b = s.cend(); |
| 59 ASSERT_TRUE(a == b); |
| 60 } |
| 61 |
| 62 TEST(TokenSequence, BeginIsEndIfNoTokens1) |
| 63 { |
| 64 TokenSequence<std::wstring> s(L"", L" "); |
| 65 auto a = s.cbegin(); |
| 66 auto b = s.cend(); |
| 67 ASSERT_TRUE(a == b); |
| 68 } |
| 69 |
| 70 TEST(TokenSequence, BeginIsEndIfNoTokens2) |
| 71 { |
| 72 TokenSequence<std::wstring> s(L" ", L" "); |
| 73 auto a = s.cbegin(); |
| 74 auto b = s.cend(); |
| 75 ASSERT_TRUE(a == b); |
| 76 } |
| 77 |
| 78 TEST(TokenSequence, BeginIsNotEndIfTokens) |
| 79 { |
| 80 TokenSequence<std::wstring> s(L"foo", L" "); |
| 81 auto a = s.cbegin(); |
| 82 auto b = s.cend(); |
| 83 ASSERT_TRUE(a != b); |
| 84 } |
| 85 |
| 86 TEST(TokenSequence, MayNotIndirectEndIterator1) |
| 87 { |
| 88 TokenSequence<std::wstring> s(L"foo", L" "); |
| 89 auto b = s.cend(); |
| 90 ASSERT_THROW( |
| 91 { |
| 92 auto x = *b; |
| 93 }, |
| 94 std::runtime_error |
| 95 ); |
| 96 } |
| 97 |
| 98 TEST(TokenSequence, MayNotIndirectEndIterator2) |
| 99 { |
| 100 TokenSequence<std::wstring> s(L"", L" "); |
| 101 auto a = s.cbegin(); |
| 102 ASSERT_THROW( |
| 103 { |
| 104 auto x = *a; |
| 105 }, |
| 106 std::runtime_error |
| 107 ); |
| 108 } |
| 109 |
| 110 TEST(TokenSequence, SingleToken1) |
| 111 { |
| 112 TokenSequence<std::wstring> s(L"foo", L" "); |
| 113 auto a = s.cbegin(); |
| 114 ASSERT_EQ(L"foo", *a); |
| 115 ++a; |
| 116 ASSERT_TRUE(a == s.cend()); |
| 117 } |
| 118 |
| 119 TEST(TokenSequence, SingleToken2) |
| 120 { |
| 121 TokenSequence<std::wstring> s(L"foo ", L" "); |
| 122 auto a = s.cbegin(); |
| 123 ASSERT_EQ(L"foo", *a); |
| 124 ++a; |
| 125 ASSERT_TRUE(a == s.cend()); |
| 126 } |
| 127 |
| 128 TEST(TokenSequence, SingleToken3) |
| 129 { |
| 130 TokenSequence<std::wstring> s(L" foo", L" "); |
| 131 auto a = s.cbegin(); |
| 132 ASSERT_EQ(L"foo", *a); |
| 133 ++a; |
| 134 ASSERT_TRUE(a == s.cend()); |
| 135 } |
| 136 |
| 137 TEST(TokenSequence, SingleToken4) |
| 138 { |
| 139 TokenSequence<std::wstring> s(L" foo ", L" "); |
| 140 auto a = s.cbegin(); |
| 141 ASSERT_EQ(L"foo", *a); |
| 142 ++a; |
| 143 ASSERT_TRUE(a == s.cend()); |
| 144 } |
| 145 |
| 146 TEST(TokenSequence, IncrementEndToken) |
| 147 { |
| 148 TokenSequence<std::wstring> s(L"foo", L" "); |
| 149 auto a = s.cend(); |
| 150 ++a; |
| 151 ASSERT_TRUE(a == s.cend()); |
| 152 } |
| 153 |
| 154 void MultipleTokens(const std::wstring& text) |
| 155 { |
| 156 TokenSequence<std::wstring> s(text, L" "); |
| 157 auto a = s.cbegin(); |
| 158 ASSERT_NE(a, s.cend()); |
| 159 ASSERT_EQ(L"foo", *a); |
| 160 ++a; |
| 161 ASSERT_NE(a, s.cend()); |
| 162 ASSERT_EQ(L"bar", *a); |
| 163 ++a; |
| 164 ASSERT_NE(a, s.cend()); |
| 165 ASSERT_EQ(L"baz", *a); |
| 166 ++a; |
| 167 ASSERT_EQ(a, s.cend()); |
| 168 } |
| 169 |
| 170 TEST(TokenSequence, MultipleTokens1) |
| 171 { |
| 172 MultipleTokens(L"foo bar baz"); |
| 173 } |
| 174 |
| 175 TEST(TokenSequence, MultipleTokens2) |
| 176 { |
| 177 MultipleTokens(L"foo bar baz "); |
| 178 } |
| 179 |
| 180 TEST(TokenSequence, MultipleTokens3) |
| 181 { |
| 182 MultipleTokens(L" foo bar baz"); |
| 183 } |
| 184 |
| 185 TEST(TokenSequence, MultipleTokens4) |
| 186 { |
| 187 MultipleTokens(L" foo bar baz "); |
| 188 } |
| 189 |
| 190 TEST(TokenSequence, ForLoop) |
| 191 { |
| 192 TokenSequence<std::wstring> s(L"foo bar baz", L" "); |
| 193 auto a = s.cbegin(); |
| 194 for (int j = 0; a != s.cend(); ++a, ++j) |
| 195 { |
| 196 switch (j) |
| 197 { |
| 198 case 0: |
| 199 ASSERT_EQ(L"foo", *a); |
| 200 break; |
| 201 case 1: |
| 202 ASSERT_EQ(L"bar", *a); |
| 203 break; |
| 204 case 2: |
| 205 ASSERT_EQ(L"baz", *a); |
| 206 break; |
| 207 } |
| 208 } |
| 209 ASSERT_EQ(s.cend(), a); |
| 210 } |
OLD | NEW |