Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/plugin/TokenSequenceTest.cpp

Issue 29331055: Issue #1234 - Remove 'CString' from PluginFilter.* (Closed)
Patch Set: Created Nov. 29, 2015, 3:49 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« test/UtilTest.cpp ('K') | « test/UtilTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« test/UtilTest.cpp ('K') | « test/UtilTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld