Index: test/plugin/TokenSequenceTest.cpp |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/test/plugin/TokenSequenceTest.cpp |
@@ -0,0 +1,210 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2015 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+#include <gtest/gtest.h> |
+#include "../../src/plugin/TokenSequence.h" |
+ |
+TEST(TokenSequence, MustHaveDelimiters) |
+{ |
+ ASSERT_THROW( |
+ { |
+ TokenSequence<std::wstring> s(L"foo", L""); |
+ }, |
+ std::runtime_error |
+ ); |
+} |
+ |
+TEST(TokenSequence, Cbegin1) |
+{ |
+ TokenSequence<std::wstring> s(L"", L" "); |
+ auto a = s.cbegin(); |
+ auto b = s.cbegin(); |
+ ASSERT_TRUE(a == b); |
+} |
+ |
+TEST(TokenSequence, Cbegin2) |
+{ |
+ TokenSequence<std::wstring> s(L"foo", L" "); |
+ auto a = s.cbegin(); |
+ auto b = s.cbegin(); |
+ ASSERT_TRUE(a == b); |
+} |
+ |
+TEST(TokenSequence, Cend1) |
+{ |
+ TokenSequence<std::wstring> s(L"", L" "); |
+ auto a = s.cend(); |
+ auto b = s.cend(); |
+ ASSERT_TRUE(a == b); |
+} |
+ |
+TEST(TokenSequence, Cend2) |
+{ |
+ TokenSequence<std::wstring> s(L"foo", L" "); |
+ auto a = s.cend(); |
+ auto b = s.cend(); |
+ ASSERT_TRUE(a == b); |
+} |
+ |
+TEST(TokenSequence, BeginIsEndIfNoTokens1) |
+{ |
+ TokenSequence<std::wstring> s(L"", L" "); |
+ auto a = s.cbegin(); |
+ auto b = s.cend(); |
+ ASSERT_TRUE(a == b); |
+} |
+ |
+TEST(TokenSequence, BeginIsEndIfNoTokens2) |
+{ |
+ TokenSequence<std::wstring> s(L" ", L" "); |
+ auto a = s.cbegin(); |
+ auto b = s.cend(); |
+ ASSERT_TRUE(a == b); |
+} |
+ |
+TEST(TokenSequence, BeginIsNotEndIfTokens) |
+{ |
+ TokenSequence<std::wstring> s(L"foo", L" "); |
+ auto a = s.cbegin(); |
+ auto b = s.cend(); |
+ ASSERT_TRUE(a != b); |
+} |
+ |
+TEST(TokenSequence, MayNotIndirectEndIterator1) |
+{ |
+ TokenSequence<std::wstring> s(L"foo", L" "); |
+ auto b = s.cend(); |
+ ASSERT_THROW( |
+ { |
+ auto x = *b; |
+ }, |
+ std::runtime_error |
+ ); |
+} |
+ |
+TEST(TokenSequence, MayNotIndirectEndIterator2) |
+{ |
+ TokenSequence<std::wstring> s(L"", L" "); |
+ auto a = s.cbegin(); |
+ ASSERT_THROW( |
+ { |
+ auto x = *a; |
+ }, |
+ std::runtime_error |
+ ); |
+} |
+ |
+TEST(TokenSequence, SingleToken1) |
+{ |
+ TokenSequence<std::wstring> s(L"foo", L" "); |
+ auto a = s.cbegin(); |
+ ASSERT_EQ(L"foo", *a); |
+ ++a; |
+ ASSERT_TRUE(a == s.cend()); |
+} |
+ |
+TEST(TokenSequence, SingleToken2) |
+{ |
+ TokenSequence<std::wstring> s(L"foo ", L" "); |
+ auto a = s.cbegin(); |
+ ASSERT_EQ(L"foo", *a); |
+ ++a; |
+ ASSERT_TRUE(a == s.cend()); |
+} |
+ |
+TEST(TokenSequence, SingleToken3) |
+{ |
+ TokenSequence<std::wstring> s(L" foo", L" "); |
+ auto a = s.cbegin(); |
+ ASSERT_EQ(L"foo", *a); |
+ ++a; |
+ ASSERT_TRUE(a == s.cend()); |
+} |
+ |
+TEST(TokenSequence, SingleToken4) |
+{ |
+ TokenSequence<std::wstring> s(L" foo ", L" "); |
+ auto a = s.cbegin(); |
+ ASSERT_EQ(L"foo", *a); |
+ ++a; |
+ ASSERT_TRUE(a == s.cend()); |
+} |
+ |
+TEST(TokenSequence, IncrementEndToken) |
+{ |
+ TokenSequence<std::wstring> s(L"foo", L" "); |
+ auto a = s.cend(); |
+ ++a; |
+ ASSERT_TRUE(a == s.cend()); |
+} |
+ |
+void MultipleTokens(const std::wstring& text) |
+{ |
+ TokenSequence<std::wstring> s(text, L" "); |
+ auto a = s.cbegin(); |
+ ASSERT_NE(a, s.cend()); |
+ ASSERT_EQ(L"foo", *a); |
+ ++a; |
+ ASSERT_NE(a, s.cend()); |
+ ASSERT_EQ(L"bar", *a); |
+ ++a; |
+ ASSERT_NE(a, s.cend()); |
+ ASSERT_EQ(L"baz", *a); |
+ ++a; |
+ ASSERT_EQ(a, s.cend()); |
+} |
+ |
+TEST(TokenSequence, MultipleTokens1) |
+{ |
+ MultipleTokens(L"foo bar baz"); |
+} |
+ |
+TEST(TokenSequence, MultipleTokens2) |
+{ |
+ MultipleTokens(L"foo bar baz "); |
+} |
+ |
+TEST(TokenSequence, MultipleTokens3) |
+{ |
+ MultipleTokens(L" foo bar baz"); |
+} |
+ |
+TEST(TokenSequence, MultipleTokens4) |
+{ |
+ MultipleTokens(L" foo bar baz "); |
+} |
+ |
+TEST(TokenSequence, ForLoop) |
+{ |
+ TokenSequence<std::wstring> s(L"foo bar baz", L" "); |
+ auto a = s.cbegin(); |
+ for (int j = 0; a != s.cend(); ++a, ++j) |
+ { |
+ switch (j) |
+ { |
+ case 0: |
+ ASSERT_EQ(L"foo", *a); |
+ break; |
+ case 1: |
+ ASSERT_EQ(L"bar", *a); |
+ break; |
+ case 2: |
+ ASSERT_EQ(L"baz", *a); |
+ break; |
+ } |
+ } |
+ ASSERT_EQ(s.cend(), a); |
+} |