aboutsummaryrefslogtreecommitdiffstats
path: root/test/libdevcore
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-11-14 02:33:35 +0800
committerGitHub <noreply@github.com>2018-11-14 02:33:35 +0800
commit1d4f565a64988a3400847d2655ca24f73f234bc6 (patch)
treecaaa6c26e307513505349b50ca4f2a8a9506752b /test/libdevcore
parent59dbf8f1085b8b92e8b7eb0ce380cbeb642e97eb (diff)
parent91b6b8a88e76016e0324036cb7a7f9300a1e2439 (diff)
downloaddexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.gz
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.bz2
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.lz
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.xz
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.zst
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.zip
Merge pull request #5416 from ethereum/develop
Merge develop into release for 0.5.0
Diffstat (limited to 'test/libdevcore')
-rw-r--r--test/libdevcore/IterateReplacing.cpp97
-rw-r--r--test/libdevcore/StringUtils.cpp19
-rw-r--r--test/libdevcore/UTF8.cpp8
3 files changed, 120 insertions, 4 deletions
diff --git a/test/libdevcore/IterateReplacing.cpp b/test/libdevcore/IterateReplacing.cpp
new file mode 100644
index 00000000..08cd1e22
--- /dev/null
+++ b/test/libdevcore/IterateReplacing.cpp
@@ -0,0 +1,97 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity 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 solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * Unit tests for the iterateReplacing function
+ */
+
+#include <libdevcore/CommonData.h>
+
+#include <test/Options.h>
+
+using namespace std;
+
+namespace dev
+{
+namespace test
+{
+
+BOOST_AUTO_TEST_SUITE(IterateReplacing)
+
+BOOST_AUTO_TEST_CASE(no_replacement)
+{
+ vector<string> v{"abc", "def", "ghi"};
+ function<boost::optional<vector<string>>(string&)> f = [](string&) -> boost::optional<vector<string>> { return {}; };
+ iterateReplacing(v, f);
+ vector<string> expectation{"abc", "def", "ghi"};
+ BOOST_CHECK(v == expectation);
+}
+
+BOOST_AUTO_TEST_CASE(empty_input)
+{
+ vector<string> v;
+ function<boost::optional<vector<string>>(string&)> f = [](string&) -> boost::optional<vector<string>> { return {}; };
+ iterateReplacing(v, f);
+ vector<string> expectation;
+ BOOST_CHECK(v == expectation);
+}
+
+BOOST_AUTO_TEST_CASE(delete_some)
+{
+ vector<string> v{"abc", "def", "ghi"};
+ function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> {
+ if (_s == "def")
+ return vector<string>();
+ else
+ return {};
+ };
+ iterateReplacing(v, f);
+ vector<string> expectation{"abc", "ghi"};
+ BOOST_CHECK(v == expectation);
+}
+
+BOOST_AUTO_TEST_CASE(inject_some_start)
+{
+ vector<string> v{"abc", "def", "ghi"};
+ function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> {
+ if (_s == "abc")
+ return vector<string>{"x", "y"};
+ else
+ return {};
+ };
+ iterateReplacing(v, f);
+ vector<string> expectation{"x", "y", "def", "ghi"};
+ BOOST_CHECK(v == expectation);
+}
+
+BOOST_AUTO_TEST_CASE(inject_some_end)
+{
+ vector<string> v{"abc", "def", "ghi"};
+ function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> {
+ if (_s == "ghi")
+ return vector<string>{"x", "y"};
+ else
+ return {};
+ };
+ iterateReplacing(v, f);
+ vector<string> expectation{"abc", "def", "x", "y"};
+ BOOST_CHECK(v == expectation);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+}
+}
diff --git a/test/libdevcore/StringUtils.cpp b/test/libdevcore/StringUtils.cpp
index 9ee93d02..76c11b82 100644
--- a/test/libdevcore/StringUtils.cpp
+++ b/test/libdevcore/StringUtils.cpp
@@ -48,6 +48,7 @@ BOOST_AUTO_TEST_CASE(test_similarity)
BOOST_CHECK_EQUAL(stringWithinDistance("abc", "abcdef", 2), false);
BOOST_CHECK_EQUAL(stringWithinDistance("abcd", "wxyz", 2), false);
BOOST_CHECK_EQUAL(stringWithinDistance("", "", 2), true);
+ BOOST_CHECK_EQUAL(stringWithinDistance("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY", "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYZ", 2, 6400), false);
}
BOOST_AUTO_TEST_CASE(test_dldistance)
@@ -81,6 +82,24 @@ BOOST_AUTO_TEST_CASE(test_alternatives_list)
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\", \"b\", \"c\" or \"d\"");
}
+BOOST_AUTO_TEST_CASE(test_human_readable_join)
+{
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({})), "");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a"})), "a");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b"})), "a, b");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b", "c"})), "a, b, c");
+
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({}), "; "), "");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a"}), "; "), "a");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b"}), "; "), "a; b");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b", "c"}), "; "), "a; b; c");
+
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({}), "; ", " or "), "");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a"}), "; ", " or "), "a");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b"}), "; ", " or "), "a or b");
+ BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b", "c"}), "; ", " or "), "a; b or c");
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/libdevcore/UTF8.cpp b/test/libdevcore/UTF8.cpp
index 6de4570f..daf47bb0 100644
--- a/test/libdevcore/UTF8.cpp
+++ b/test/libdevcore/UTF8.cpp
@@ -148,7 +148,7 @@ hélló
Ḕ ḕ Ḗ ḗ Ḙ ḙ Ḛ
-ἐ ἑ ἒ ἓ ἔ ἕ
+ἐ ἑ ἒ ἓ ἔ ἕ
₠ ₡ ₢ ₣ ₤ ₥
@@ -164,9 +164,9 @@ hélló
␀ ␁ ␂ ␃ ␄ ␅
-⑀ ⑁ ⑂ ⑃ ⑄
+⑀ ⑁ ⑂ ⑃ ⑄
-① ② ③ ④ ⑤
+① ② ③ ④ ⑤
╘ ╙ ╚ ╛ ╜ ╝
@@ -200,7 +200,7 @@ hélló
שּׁ שּׂ אַ אָ אּ
-ﮄ ﮅ ﮆ ﮇ ﮈ ﮉ
+ﮄ ﮅ ﮆ ﮇ ﮈ ﮉ
ﺵ ﺶ ﺷ ﺸ