mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add more tests for strings with unicode (escapes)
This commit is contained in:
parent
289fc7a9d0
commit
950612cf42
22
test/libsolidity/semanticTests/strings/unicode_escapes.sol
Normal file
22
test/libsolidity/semanticTests/strings/unicode_escapes.sol
Normal 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"
|
@ -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"
|
@ -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.
|
@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
bytes b1 = "\xa0\x00";
|
||||
bytes32 b2 = "\xa0\x00";
|
||||
bytes b3 = hex"a000";
|
||||
}
|
||||
// ----
|
6
test/libsolidity/syntaxTests/string/string_unicode.sol
Normal file
6
test/libsolidity/syntaxTests/string/string_unicode.sol
Normal file
@ -0,0 +1,6 @@
|
||||
contract test {
|
||||
function f() public pure returns (string memory) {
|
||||
return "😃, 😭, and 😈";
|
||||
}
|
||||
}
|
||||
// ----
|
@ -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.
|
@ -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.
|
@ -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.
|
Loading…
Reference in New Issue
Block a user