aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-09-06 22:42:39 +0800
committerchriseth <chris@ethereum.org>2018-09-06 22:42:59 +0800
commit6a40048aa43abdd17fa6e8b74e4c32127f6c1840 (patch)
tree432e5de07536aaae222c4bd0d0b76ab568a22abf /test/libsolidity
parent0b7b8162cab67d58915d4561a52d70e7208233c1 (diff)
downloaddexon-solidity-6a40048aa43abdd17fa6e8b74e4c32127f6c1840.tar.gz
dexon-solidity-6a40048aa43abdd17fa6e8b74e4c32127f6c1840.tar.zst
dexon-solidity-6a40048aa43abdd17fa6e8b74e4c32127f6c1840.zip
Tests.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityScanner.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp
index 6b7f559a..3a210f94 100644
--- a/test/libsolidity/SolidityScanner.cpp
+++ b/test/libsolidity/SolidityScanner.cpp
@@ -23,6 +23,8 @@
#include <libsolidity/parsing/Scanner.h>
#include <boost/test/unit_test.hpp>
+using namespace std;
+
namespace dev
{
namespace solidity
@@ -508,6 +510,102 @@ BOOST_AUTO_TEST_CASE(invalid_multiline_comment_close)
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
}
+BOOST_AUTO_TEST_CASE(multiline_doc_comment_at_eos)
+{
+ // This used to parse as "whitespace"
+ Scanner scanner(CharStream("/**"));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+}
+
+BOOST_AUTO_TEST_CASE(multiline_comment_at_eos)
+{
+ Scanner scanner(CharStream("/*"));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+}
+
+BOOST_AUTO_TEST_CASE(regular_line_break_in_single_line_comment)
+{
+ for (auto const& nl: {"\r", "\n"})
+ {
+ Scanner scanner(CharStream("// abc " + string(nl) + " def "));
+ BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_single_line_comment)
+{
+ for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
+ {
+ Scanner scanner(CharStream("// abc " + string(nl) + " def "));
+ BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ for (size_t i = 0; i < string(nl).size() - 1; i++)
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(regular_line_breaks_in_single_line_doc_comment)
+{
+ for (auto const& nl: {"\r", "\n"})
+ {
+ Scanner scanner(CharStream("/// abc " + string(nl) + " def "));
+ BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "abc ");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_single_line_doc_comment)
+{
+ for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
+ {
+ Scanner scanner(CharStream("/// abc " + string(nl) + " def "));
+ BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "abc ");
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ for (size_t i = 0; i < string(nl).size() - 1; i++)
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(regular_line_breaks_in_strings)
+{
+ for (auto const& nl: {"\n", "\r"})
+ {
+ Scanner scanner(CharStream("\"abc " + string(nl) + " def\""));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_strings)
+{
+ for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
+ {
+ Scanner scanner(CharStream("\"abc " + string(nl) + " def\""));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ for (size_t i = 0; i < string(nl).size(); i++)
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+ }
+}
BOOST_AUTO_TEST_SUITE_END()