mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add syntax tests to augment the test coverage of
libsolidity/parsing/Scanner.cpp and libsolidity/parsing/Scanner.h Fix #4627 and PR #5003. - Add multiline comment test - Add upper case hex literal test - Add test for unicode escapes - Add test for strings with escaped newlines - Add test for string escapes - Add test for strings that do not terminate before end of file - Add test for unterminated blocks
This commit is contained in:
parent
2409986cf3
commit
faa0caae08
13
test/libsolidity/syntaxTests/multiline_comments.sol
Normal file
13
test/libsolidity/syntaxTests/multiline_comments.sol
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* This is a multi-line comment
|
||||
* it should create no problems
|
||||
*
|
||||
*/
|
||||
|
||||
contract test {
|
||||
/*
|
||||
* this is another multi-line comment
|
||||
*
|
||||
*/
|
||||
}
|
||||
// ----
|
7
test/libsolidity/syntaxTests/string/string_escapes.sol
Normal file
7
test/libsolidity/syntaxTests/string/string_escapes.sol
Normal file
@ -0,0 +1,7 @@
|
||||
contract test {
|
||||
function f() public pure returns (bytes32) {
|
||||
bytes32 escapeCharacters = "\t\b\n\r\f\'\"\\\b";
|
||||
return escapeCharacters;
|
||||
}
|
||||
}
|
||||
// ----
|
9
test/libsolidity/syntaxTests/string/string_new_line.sol
Normal file
9
test/libsolidity/syntaxTests/string/string_new_line.sol
Normal file
@ -0,0 +1,9 @@
|
||||
contract test {
|
||||
function f() public pure returns (bytes32) {
|
||||
bytes32 escapeCharacters = "This a test
|
||||
";
|
||||
return escapeCharacters;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (100-112): Expected primary expression.
|
@ -0,0 +1,8 @@
|
||||
contract test {
|
||||
function f() public pure returns (bytes32) {
|
||||
bytes32 escapeCharacters = "text \";
|
||||
return escapeCharacters;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (100-109): Expected primary expression.
|
@ -0,0 +1,7 @@
|
||||
contract test {
|
||||
function f() public pure returns (bytes32) {
|
||||
bytes32 escapeCharacters = "This a test
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (100-112): Expected primary expression.
|
@ -0,0 +1,4 @@
|
||||
contract test {
|
||||
function f() pure public { "abc\
|
||||
// ----
|
||||
// ParserError: (47-53): Expected primary expression.
|
31
test/libsolidity/syntaxTests/unicode_escape_literals.sol
Normal file
31
test/libsolidity/syntaxTests/unicode_escape_literals.sol
Normal file
@ -0,0 +1,31 @@
|
||||
contract test {
|
||||
|
||||
function oneByteUTF8() public pure returns (bytes32) {
|
||||
bytes32 usdollar = "aaa\u0024aaa";
|
||||
return usdollar;
|
||||
}
|
||||
|
||||
function twoBytesUTF8() public pure returns (bytes32) {
|
||||
bytes32 cent = "aaa\u00A2aaa";
|
||||
return cent;
|
||||
}
|
||||
|
||||
function threeBytesUTF8() public pure returns (bytes32) {
|
||||
bytes32 eur = "aaa\u20ACaaa";
|
||||
return eur;
|
||||
}
|
||||
|
||||
function together() public pure returns (bytes32) {
|
||||
bytes32 res = "\u0024\u00A2\u20AC";
|
||||
return res;
|
||||
}
|
||||
|
||||
// this function returns an invalid unicode character
|
||||
function invalidLiteral() public pure returns(bytes32) {
|
||||
bytes32 invalid = "\u00xx";
|
||||
return invalid;
|
||||
}
|
||||
|
||||
}
|
||||
// ----
|
||||
// ParserError: (678-681): Expected primary expression.
|
@ -0,0 +1,4 @@
|
||||
contract c {
|
||||
function f() pure public { 1.
|
||||
// ----
|
||||
// ParserError: (47-47): Expected identifier but got end of source
|
@ -0,0 +1,5 @@
|
||||
contract test {
|
||||
function f() pure public { 1.x; }
|
||||
}
|
||||
// ----
|
||||
// TypeError: (47-50): Member "x" not found or not visible after argument-dependent lookup in int_const 1.
|
@ -0,0 +1,4 @@
|
||||
contract c {
|
||||
function f() pure public { 0.
|
||||
// ----
|
||||
// ParserError: (47-47): Expected identifier but got end of source
|
@ -0,0 +1,5 @@
|
||||
contract test {
|
||||
function f() pure public { 0.x; }
|
||||
}
|
||||
// ----
|
||||
// TypeError: (47-50): Member "x" not found or not visible after argument-dependent lookup in int_const 0.
|
9
test/libsolidity/syntaxTests/upper_case_hex_literals.sol
Normal file
9
test/libsolidity/syntaxTests/upper_case_hex_literals.sol
Normal file
@ -0,0 +1,9 @@
|
||||
contract test {
|
||||
|
||||
function f() public pure returns (uint256) {
|
||||
uint256 a = 0x1234aAbcC;
|
||||
uint256 b = 0x1234ABCDEF;
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
// ----
|
Loading…
Reference in New Issue
Block a user