Add more tests for strings with unicode (escapes)

This commit is contained in:
Alex Beregszaszi 2020-07-13 18:23:42 +01:00
parent 289fc7a9d0
commit 950612cf42
11 changed files with 64 additions and 11 deletions

View File

@ -0,0 +1,22 @@
contract C {
function oneByteUTF8() public pure returns (string memory) {
return "aaa\u0024aaa"; // usdollar
}
function twoBytesUTF8() public pure returns (string memory) {
return "aaa\u00A2aaa"; // cent
}
function threeBytesUTF8() public pure returns (string memory) {
return "aaa\u20ACaaa"; // euro
}
function combined() public pure returns (string memory) {
return "\u0024\u00A2\u20AC";
}
}
// ----
// oneByteUTF8() -> 0x20, 7, "aaa$aaa"
// twoBytesUTF8() -> 0x20, 8, "aaa\xc2\xa2aaa"
// threeBytesUTF8() -> 0x20, 9, "aaa\xe2\x82\xacaaa"
// combined() -> 0x20, 6, "$\xc2\xa2\xe2\x82\xac"

View File

@ -0,0 +1,7 @@
contract C {
function f() public pure returns (string memory) {
return "😃, 😭, and 😈";
}
}
// ----
// f() -> 0x20, 0x14, "\xf0\x9f\x98\x83, \xf0\x9f\x98\xad, and \xf0\x9f\x98\x88"

View File

@ -0,0 +1,5 @@
contract C {
string s = hex"a000";
}
// ----
// TypeError 7407: (28-37): Type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.

View File

@ -0,0 +1,6 @@
contract C {
bytes b1 = "\xa0\x00";
bytes32 b2 = "\xa0\x00";
bytes b3 = hex"a000";
}
// ----

View File

@ -0,0 +1,6 @@
contract test {
function f() public pure returns (string memory) {
return "😃, 😭, and 😈";
}
}
// ----

View File

@ -1,5 +1,4 @@
contract test {
function oneByteUTF8() public pure returns (bytes32) {
bytes32 usdollar = "aaa\u0024aaa";
return usdollar;
@ -15,17 +14,8 @@ contract test {
return eur;
}
function together() public pure returns (bytes32) {
function combined() 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 8936: (678-681): Invalid escape sequence.

View File

@ -0,0 +1,7 @@
contract test {
function f() public pure returns (string memory) {
return "\xc1";
}
}
// ----
// TypeError 6359: (86-92): Return argument type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type (type of first return variable) string memory.

View File

@ -0,0 +1,10 @@
contract test {
// this function returns an invalid unicode character
function invalidLiteral() public pure returns (bytes32) {
bytes32 invalid = "\u00xx";
return invalid;
}
}
// ----
// ParserError 8936: (162-165): Invalid escape sequence.