aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-09-10 18:25:07 +0800
committerGitHub <noreply@github.com>2018-09-10 18:25:07 +0800
commit255eda2ea69cf1996b1d6e1289b47f394ae28712 (patch)
tree5d31eabb82ab01dd541c7fb8648f0b92917bbee4 /test/libsolidity
parent86d8502598c6f6dc3a5c7a5fa21e56dbbfc09d8c (diff)
parent4fb4846d1fd8d3ab8867ba6bc2ccd17ab5d353f7 (diff)
downloaddexon-solidity-255eda2ea69cf1996b1d6e1289b47f394ae28712.tar.gz
dexon-solidity-255eda2ea69cf1996b1d6e1289b47f394ae28712.tar.zst
dexon-solidity-255eda2ea69cf1996b1d6e1289b47f394ae28712.zip
Merge pull request #4912 from ethereum/fixNewline
Fix bugs in comments.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityScanner.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp
index f2e756bb..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
@@ -500,6 +502,110 @@ BOOST_AUTO_TEST_CASE(invalid_hex_literal_nonhex_string)
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
}
+BOOST_AUTO_TEST_CASE(invalid_multiline_comment_close)
+{
+ // This used to parse as "comment", "identifier"
+ Scanner scanner(CharStream("/** / x"));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
+ 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()