Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solidity tests for bin number literal
- Loading branch information
Showing
13 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
test/libsolidity/semanticTests/various/test_underscore_in_bin.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
contract test { | ||
function f(bool cond) public pure returns (uint256) { | ||
uint32 x = 0b0001001000110100_10101011; | ||
uint256 y = 0b0001001000110100_1010101111001101_0001001000110100; | ||
return cond ? x : y; | ||
} | ||
} | ||
// ---- | ||
// f(bool): true -> 0x1234ab | ||
// f(bool): false -> 0x1234abcd1234 |
5 changes: 5 additions & 0 deletions
5
test/libsolidity/syntaxTests/denominations/combining_bin_and_denomination.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract C { | ||
uint constant x = 0b01 wei; | ||
} | ||
// ---- | ||
// TypeError 5146: (32-40): Binary numbers cannot be used with unit denominations. You can use an expression of the form "0b1011 * 1 days" instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract C { | ||
uint x = 0b10a; | ||
} | ||
// ---- | ||
// ParserError 8936: (26-30): Identifier-start is not allowed at end of a number. |
17 changes: 17 additions & 0 deletions
17
test/libsolidity/syntaxTests/parsing/lexer_numbers_with_underscores_bin.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
contract C { | ||
function f() public pure { | ||
uint x1 = 0b1111111_010100000000; | ||
uint x2 = 0b111111_010100000000; | ||
uint x3 = 0b11111_010100000000; | ||
uint x4 = 0b1111_010100000000; | ||
uint x5 = 0b111_010100000000; | ||
uint x6 = 0b11_010100000000; | ||
uint x7 = 0b1_010100000000; | ||
uint x8 = 0b1010_0101_010_101; | ||
uint x9 = 0b010_10101_1100_001; | ||
uint x10 = 0b100101010_001010101111_010010101; | ||
|
||
x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; | ||
} | ||
} | ||
// ---- |
7 changes: 7 additions & 0 deletions
7
test/libsolidity/syntaxTests/parsing/lexer_numbers_with_underscores_bin_fail.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract C { | ||
function f() public pure { | ||
uint X1 = 0b010101__1100__001100__1001001; | ||
} | ||
} | ||
// ---- | ||
// SyntaxError 2990: (56-87): Invalid use of underscores in number literal. Only one consecutive underscores between digits allowed. |
31 changes: 31 additions & 0 deletions
31
test/libsolidity/syntaxTests/types/bin_literal_to_bytesNN_different_size_explicit.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
contract C { | ||
function f() public pure { | ||
bytes1 b1 = bytes1(0b1); | ||
bytes1 b2 = bytes1(0b100000000); | ||
bytes2 b3 = bytes2(0b11111111); | ||
bytes2 b4 = bytes2(0b100000000); | ||
bytes2 b5 = bytes2(0b10000000000000000); | ||
bytes3 b6 = bytes3(0b1111111111111111); | ||
bytes3 b7 = bytes3(0b10000000000000000); | ||
bytes3 b8 = bytes3(0b1000000000000000000000000); | ||
bytes4 b9 = bytes4(0b111111111111111111111111); | ||
bytes4 b10 = bytes4(0b1000000000000000000000000); | ||
bytes4 b11 = bytes4(0b100000000000000000000000000000000); | ||
bytes16 b12 = bytes16(0b1); | ||
bytes32 b13 = bytes32(0b1); | ||
} | ||
} | ||
// ---- | ||
// TypeError 9640: (60-71): Explicit type conversion not allowed from "int_const 1" to "bytes1". | ||
// TypeError 9640: (90-109): Explicit type conversion not allowed from "int_const 256" to "bytes1". | ||
// TypeError 9640: (128-146): Explicit type conversion not allowed from "int_const 255" to "bytes2". | ||
// TypeError 9640: (165-184): Explicit type conversion not allowed from "int_const 256" to "bytes2". | ||
// TypeError 9640: (203-230): Explicit type conversion not allowed from "int_const 65536" to "bytes2". | ||
// TypeError 9640: (249-275): Explicit type conversion not allowed from "int_const 65535" to "bytes3". | ||
// TypeError 9640: (294-321): Explicit type conversion not allowed from "int_const 65536" to "bytes3". | ||
// TypeError 9640: (340-375): Explicit type conversion not allowed from "int_const 16777216" to "bytes3". | ||
// TypeError 9640: (394-428): Explicit type conversion not allowed from "int_const 16777215" to "bytes4". | ||
// TypeError 9640: (448-483): Explicit type conversion not allowed from "int_const 16777216" to "bytes4". | ||
// TypeError 9640: (503-546): Explicit type conversion not allowed from "int_const 4294967296" to "bytes4". | ||
// TypeError 9640: (567-579): Explicit type conversion not allowed from "int_const 1" to "bytes16". | ||
// TypeError 9640: (600-612): Explicit type conversion not allowed from "int_const 1" to "bytes32". |
31 changes: 31 additions & 0 deletions
31
test/libsolidity/syntaxTests/types/bin_literal_to_bytesNN_different_size_implicit.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
contract C { | ||
function f() public pure { | ||
bytes1 b1 = 0b1; | ||
bytes1 b2 = 0b100000000; | ||
bytes2 b3 = 0b11111111; | ||
bytes2 b4 = 0b100000000; | ||
bytes2 b5 = 0b10000000000000000; | ||
bytes3 b6 = 0b1111111111111111; | ||
bytes3 b7 = 0b10000000000000000; | ||
bytes3 b8 = 0b1000000000000000000000000; | ||
bytes4 b9 = 0b111111111111111111111111; | ||
bytes4 b10 = 0b1000000000000000000000000; | ||
bytes4 b11 = 0b100000000000000000000000000000000; | ||
bytes16 b12 = 0b1; | ||
bytes32 b13 = 0b1; | ||
} | ||
} | ||
// ---- | ||
// TypeError 9574: (48-63): Type int_const 1 is not implicitly convertible to expected type bytes1. | ||
// TypeError 9574: (70-93): Type int_const 256 is not implicitly convertible to expected type bytes1. | ||
// TypeError 9574: (100-122): Type int_const 255 is not implicitly convertible to expected type bytes2. | ||
// TypeError 9574: (129-152): Type int_const 256 is not implicitly convertible to expected type bytes2. | ||
// TypeError 9574: (159-190): Type int_const 65536 is not implicitly convertible to expected type bytes2. | ||
// TypeError 9574: (197-227): Type int_const 65535 is not implicitly convertible to expected type bytes3. | ||
// TypeError 9574: (234-265): Type int_const 65536 is not implicitly convertible to expected type bytes3. | ||
// TypeError 9574: (272-311): Type int_const 16777216 is not implicitly convertible to expected type bytes3. | ||
// TypeError 9574: (318-356): Type int_const 16777215 is not implicitly convertible to expected type bytes4. | ||
// TypeError 9574: (363-403): Type int_const 16777216 is not implicitly convertible to expected type bytes4. | ||
// TypeError 9574: (410-458): Type int_const 4294967296 is not implicitly convertible to expected type bytes4. | ||
// TypeError 9574: (465-482): Type int_const 1 is not implicitly convertible to expected type bytes16. | ||
// TypeError 9574: (489-506): Type int_const 1 is not implicitly convertible to expected type bytes32. |
14 changes: 14 additions & 0 deletions
14
test/libsolidity/syntaxTests/types/bin_literal_to_bytesNN_same_size_explicit.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
contract C { | ||
function f() public pure { | ||
bytes1 b1 = bytes1(0b00000001); | ||
bytes1 b2 = bytes1(0b11111111); | ||
bytes2 b3 = bytes2(0b0000000100000000); | ||
bytes2 b4 = bytes2(0b1111111111111111); | ||
bytes3 b5 = bytes3(0b000000010000000000000000); | ||
bytes3 b6 = bytes3(0b111111111111111111111111); | ||
bytes4 b7 = bytes4(0b00000001000000000000000000000000); | ||
bytes4 b8 = bytes4(0b11111111111111111111111111111111); | ||
b1; b2; b3; b4; b5; b6; b7; b8; | ||
} | ||
} | ||
// ---- |
14 changes: 14 additions & 0 deletions
14
test/libsolidity/syntaxTests/types/bin_literal_to_bytesNN_same_size_implicit.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
contract C { | ||
function f() public pure { | ||
bytes1 b1 = 0b00000001; | ||
bytes1 b2 = 0b11111111; | ||
bytes2 b3 = 0b0000000100000000; | ||
bytes2 b4 = 0b1111111111111111; | ||
bytes3 b5 = 0b000000010000000000000000; | ||
bytes3 b6 = 0b111111111111111111111111; | ||
bytes4 b7 = 0b00000001000000000000000000000000; | ||
bytes4 b8 = 0b11111111111111111111111111111111; | ||
b1; b2; b3; b4; b5; b6; b7; b8; | ||
} | ||
} | ||
// ---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters