Tests for multipart string concatenation

This commit is contained in:
Kamil Śliwak 2023-03-23 12:53:16 +01:00
parent d7db1f097a
commit 4caee63ec8
6 changed files with 130 additions and 6 deletions

View File

@ -0,0 +1,33 @@
function stringSuffix(string memory s) pure suffix returns (string memory) { return s; }
function bytesSuffix(bytes memory b) pure suffix returns (bytes memory) { return b; }
contract C {
string public emptyString = "" '' "" "" stringSuffix;
bytes public emptyHex = hex"" hex'' hex"" hex"" bytesSuffix;
string public emptyUnicode = unicode"" unicode'' unicode"" unicode"" stringSuffix;
string public string1 = "abcd" "" stringSuffix;
string public string2 = "" "efgh" stringSuffix;
string public string3 = "abcd" "efgh" stringSuffix;
bytes public hex1 = hex"9798" hex"" bytesSuffix;
bytes public hex2 = hex"" hex"99a0" bytesSuffix;
bytes public hex3 = hex"9798" hex"99a0" bytesSuffix;
string public unicode1 = unicode"😃" unicode"" stringSuffix;
string public unicode2 = unicode"" unicode"😃" stringSuffix;
string public unicode3 = unicode"😃" unicode"😃" stringSuffix;
}
// ----
// emptyString() -> 0x20, 0
// emptyHex() -> 0x20, 0
// emptyUnicode() -> 0x20, 0
// string1() -> 0x20, 4, "abcd"
// string2() -> 0x20, 4, "efgh"
// string3() -> 0x20, 8, "abcdefgh"
// hex1() -> 0x20, 2, 0x9798000000000000000000000000000000000000000000000000000000000000
// hex2() -> 0x20, 2, 0x99a0000000000000000000000000000000000000000000000000000000000000
// hex3() -> 0x20, 4, 0x979899a000000000000000000000000000000000000000000000000000000000
// unicode1() -> 0x20, 4, "\xf0\x9f\x98\x83"
// unicode2() -> 0x20, 4, "\xf0\x9f\x98\x83"
// unicode3() -> 0x20, 8, "\xf0\x9f\x98\x83\xf0\x9f\x98\x83"

View File

@ -1,6 +0,0 @@
function suffix(string memory s) pure suffix returns (string memory) { return s; }
contract C {
// TODO: This should be an error
string s = "abcd" "" suffix;
}

View File

@ -0,0 +1,7 @@
function suffix(string memory) pure suffix returns (string memory) {}
contract C {
string s = "abcd" suffix "abcd" suffix;
}
// ----
// ParserError 2314: (113-119): Expected ';' but got 'StringLiteral'

View File

@ -0,0 +1,76 @@
function stringSuffix(string memory) pure suffix returns (string memory) {}
function bytesSuffix(bytes memory) pure suffix returns (bytes memory) {}
contract C {
function testString() public pure {
"" "" stringSuffix;
'' '' stringSuffix;
"" "" "" "" stringSuffix;
""''""'' "" stringSuffix;
"abcd" "" stringSuffix;
"" "efgh" stringSuffix;
"abcd" "efgh" stringSuffix;
"abcd""efgh" stringSuffix;
"abcd" "efgh"stringSuffix;
"abcd""efgh"stringSuffix;
'abcd' '' stringSuffix;
'' 'efgh' stringSuffix;
'abcd' 'efgh' stringSuffix;
'abcd''efgh' stringSuffix;
'abcd' 'efgh'stringSuffix;
'abcd''efgh'stringSuffix;
"abcd" 'efgh' stringSuffix;
'abcd' "efgh" stringSuffix;
}
function testHex() public pure {
hex"" hex"" bytesSuffix;
hex'' hex'' bytesSuffix;
hex"" hex"" hex"" hex"" bytesSuffix;
hex""hex''hex""hex'' hex"" bytesSuffix;
hex"1122" hex"" bytesSuffix;
hex"" hex"3344" bytesSuffix;
hex"1122" hex"3344" bytesSuffix;
hex"1122"hex"3344" bytesSuffix;
hex"1122" hex"3344"bytesSuffix;
hex"1122"hex"3344"bytesSuffix;
hex'1122' hex'' bytesSuffix;
hex'' hex'3344' bytesSuffix;
hex'1122' hex'3344' bytesSuffix;
hex'1122'hex'3344' bytesSuffix;
hex'1122' hex'3344'bytesSuffix;
hex'1122'hex'3344'bytesSuffix;
hex"1122" hex'3344' bytesSuffix;
hex'1122' hex"3344" bytesSuffix;
}
function testUnicode() public pure {
unicode"" unicode"" stringSuffix;
unicode'' unicode'' stringSuffix;
unicode"" unicode"" unicode"" unicode"" stringSuffix;
unicode""unicode''unicode""unicode'' unicode"" stringSuffix;
unicode"😃" unicode"" stringSuffix;
unicode"" unicode"😃" stringSuffix;
unicode"😃" unicode"😃" stringSuffix;
unicode"😃"unicode"😃" stringSuffix;
unicode"😃" unicode"😃"stringSuffix;
unicode"😃"unicode"😃"stringSuffix;
unicode'😃' unicode'' stringSuffix;
unicode'' unicode'😃' stringSuffix;
unicode'😃' unicode'😃' stringSuffix;
unicode'😃'unicode'😃' stringSuffix;
unicode'😃' unicode'😃'stringSuffix;
unicode'😃'unicode'😃'stringSuffix;
unicode"😃" unicode'😃' stringSuffix;
unicode'😃' unicode"😃" stringSuffix;
}
}

View File

@ -0,0 +1,7 @@
function hex(bytes memory) pure suffix returns (bytes memory) {}
contract C {
bytes b = hex"1234"hex;
}
// ----
// ParserError 2314: (9-12): Expected identifier but got 'ILLEGAL'

View File

@ -0,0 +1,7 @@
function unicode(string memory) pure suffix returns (string memory) {}
contract C {
string s = unicode"😃"unicode;
}
// ----
// ParserError 2314: (9-16): Expected identifier but got 'ILLEGAL'