Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"check-coverage": true,
"branches": 90,
"lines": 90,
"functions": 90,
"statements": 90,
"branches": 95,
"lines": 98,
"functions": 100,
"statements": 98,
"exclude": ["/node_modules/"],
"include": ["src/**/*.ts", "variant-coverage/**/*.ts"],
"reporter": ["lcov", "text"],
Expand Down
14 changes: 13 additions & 1 deletion tests/config/run-format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ const unstableTests = new Map(

// Here we add files that will not have the same AST after being formatted.
const unstableAstTests = new Map(
[].map((fixture) => {
[
// `: =` and `= :` are syntactically the same as `:=` and `=:`, but the ast
// changes from `YulColonAndEqual` and `YulEqualAndColon` to `ColonEqual`
// and `EqualColon`, which is expected but the workaround to keep the test
// stable is too much, so we just put it in this list.
"AssemblyV0.4.26/Assembly.sol",
].map((fixture) => {
const [file, isAstUnstable = () => true] = Array.isArray(fixture)
? fixture
: [fixture];
Expand Down Expand Up @@ -73,6 +79,12 @@ const antlrMismatchTests = new Map(
"IndexOf/IndexOf.sol",
// Syntax for `pragma solidity 0.5.0 - 0.6.0;` not supported by ANTLR
"Pragma/Pragma.sol",
// ANTLR doesn't support assembly assignment operators separated by a space
// like `: =` or `= :`
"AssemblyV0.4.26/Assembly.sol",
// ANTLR doesn't support UntypedTupleMember with a storage location, which
// is valid Slang, but not in Solidity.
"AllSolidityFeaturesV0.4.26/AllSolidityFeatures.sol",
].map((fixture) => {
const [file, compareBytecode = () => true] = Array.isArray(fixture)
? fixture
Expand Down
1 change: 1 addition & 0 deletions tests/format/AllSolidityFeatures/AllSolidityFeatures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ contract assemblyLocalBinding {
let x := 0x00
let y := x
let z := "hello"
let t := hex"0123456789abcdef"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ contract assemblyLocalBinding {
let x := 0x00
let y := x
let z := "hello"
let t := hex"0123456789abcdef"
}
}
}
Expand Down Expand Up @@ -545,6 +546,7 @@ contract assemblyLocalBinding {
let x := 0x00
let y := x
let z := "hello"
let t := hex"0123456789abcdef"
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/format/AllSolidityFeaturesV0.4.26/AllSolidityFeatures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ contract test {
var b = 7 + (c * (8 - 7)) - x;
return -(-b | 0);
}

function singleHexString() payable {
string storage a = hex"ab1248fe";
}


function storageLocationsInTuple() {
var (
memory foo,
storage bar,
baz) =
(0, 0, 0);
// ~~~~~~ ~~~~~~~ => these are the storage locations
}
}

contract c {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ contract test {
var b = 7 + (c * (8 - 7)) - x;
return -(-b | 0);
}

function singleHexString() payable {
string storage a = hex"ab1248fe";
}


function storageLocationsInTuple() {
var (
memory foo,
storage bar,
baz) =
(0, 0, 0);
// ~~~~~~ ~~~~~~~ => these are the storage locations
}
}

contract c {
Expand Down Expand Up @@ -225,6 +239,15 @@ contract test {
var b = 7 + (c * (8 - 7)) - x;
return -(-b | 0);
}

function singleHexString() payable {
string storage a = hex"ab1248fe";
}

function storageLocationsInTuple() {
var (memory foo, storage bar, baz) = (0, 0, 0);
// ~~~~~~ ~~~~~~~ => these are the storage locations
}
}

contract c {
Expand Down
7 changes: 7 additions & 0 deletions tests/format/Assembly/Assembly.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
contract Assembly {
function ifAssembly() {
assembly {
{
success := 1
}
if
returndatasize {
success := 0
Expand Down Expand Up @@ -51,6 +54,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
-> result {
result := add(x,
1)
leave
}
}
}
Expand All @@ -61,6 +65,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
-> result {
result := add(a,
add(b, c))
leave
}
}
}
Expand All @@ -70,6 +75,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
function sum (thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines)
-> result {
result := 0
leave
}
}
}
Expand All @@ -83,6 +89,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
veryLongParameterNames := 0
andItAlsoHasALotOfParameters := 0
soItShouldBeSplitInMultipleLines := 0
leave
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/format/Assembly/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ printWidth: 80
contract Assembly {
function ifAssembly() {
assembly {
{
success := 1
}
if
returndatasize {
success := 0
Expand Down Expand Up @@ -59,6 +62,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
-> result {
result := add(x,
1)
leave
}
}
}
Expand All @@ -69,6 +73,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
-> result {
result := add(a,
add(b, c))
leave
}
}
}
Expand All @@ -78,6 +83,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
function sum (thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines)
-> result {
result := 0
leave
}
}
}
Expand All @@ -91,6 +97,7 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
veryLongParameterNames := 0
andItAlsoHasALotOfParameters := 0
soItShouldBeSplitInMultipleLines := 0
leave
}
}
}
Expand Down Expand Up @@ -191,6 +198,9 @@ contract BooleanLiteralsInAssembly {
contract Assembly {
function ifAssembly() {
assembly {
{
success := 1
}
if returndatasize {
success := 0
}
Expand Down Expand Up @@ -249,6 +259,7 @@ contract Assembly {
assembly {
function inc(x) -> result {
result := add(x, 1)
leave
}
}
}
Expand All @@ -257,6 +268,7 @@ contract Assembly {
assembly {
function sum(a, b, c) -> result {
result := add(a, add(b, c))
leave
}
}
}
Expand All @@ -271,6 +283,7 @@ contract Assembly {
soItShouldBeSplitInMultipleLines
) -> result {
result := 0
leave
}
}
}
Expand All @@ -290,6 +303,7 @@ contract Assembly {
veryLongParameterNames := 0
andItAlsoHasALotOfParameters := 0
soItShouldBeSplitInMultipleLines := 0
leave
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/format/AssemblyV0.4.26/Assembly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contract MultipleAssemblyAssignment {
function foo() public pure {
assembly {
function bar() -> a, b {
b : = 2
a := 1
b := 2
}
Expand All @@ -52,6 +53,7 @@ contract AssemblyStackAssignment {
function f() public {
assembly {
4 =: y
4 = : y
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract MultipleAssemblyAssignment {
function foo() public pure {
assembly {
function bar() -> a, b {
b : = 2
a := 1
b := 2
}
Expand All @@ -60,6 +61,7 @@ contract AssemblyStackAssignment {
function f() public {
assembly {
4 =: y
4 = : y
}
}
}
Expand Down Expand Up @@ -108,6 +110,7 @@ contract MultipleAssemblyAssignment {
function foo() public pure {
assembly {
function bar() -> a, b {
b := 2
a := 1
b := 2
}
Expand All @@ -122,6 +125,8 @@ contract AssemblyStackAssignment {
assembly {
4
=: y
4
=: y
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/format/BinaryOperationHierarchy/Group.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
pragma solidity "0.8.28";

contract Group {
uint256 veryVeryVeryLongUint256A;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ printWidth: 80
| printWidth
=====================================input======================================
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
pragma solidity "0.8.28";

contract Group {
uint256 veryVeryVeryLongUint256A;
Expand Down Expand Up @@ -361,7 +361,7 @@ contract Group {
}
=====================================output=====================================
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
pragma solidity "0.8.28";

contract Group {
uint256 veryVeryVeryLongUint256A;
Expand Down
2 changes: 2 additions & 0 deletions tests/format/ForStatements/ForStatements.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ contract ForStatements {
function hi() public {
uint a;

for ((uint i, uint j) = getIndexes(); i < 100; i++) a++;

for (uint i; i < 100; i++) a++;

for (i = 0; i < 100; i++) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE);
Expand Down
4 changes: 4 additions & 0 deletions tests/format/ForStatements/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ contract ForStatements {
function hi() public {
uint a;

for ((uint i, uint j) = getIndexes(); i < 100; i++) a++;

for (uint i; i < 100; i++) a++;

for (i = 0; i < 100; i++) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE);
Expand Down Expand Up @@ -57,6 +59,8 @@ contract ForStatements {
function hi() public {
uint a;

for ((uint i, uint j) = getIndexes(); i < 100; i++) a++;

for (uint i; i < 100; i++) a++;

for (i = 0; i < 100; i++)
Expand Down
6 changes: 6 additions & 0 deletions tests/format/FunctionDefinitions/FunctionDefinitions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ contract FunctionDefinitions {
fallback () external {}
fallback () {}
fallback () external payable {}
fallback() modify(123) override(Foo) {}
fallback() returns(uint) {}
fallback() external modify() payable override(Foo) virtual returns(uint) {}
fallback() external payable virtual {}
fallback(bytes calldata _input) external {}


receive () modify(123) override(Foo) {}
receive () external modify() payable override(Foo) virtual {}
receive () external payable {}
receive() external payable virtual {}

Expand Down
11 changes: 11 additions & 0 deletions tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ contract FunctionDefinitions {
fallback () external {}
fallback () {}
fallback () external payable {}
fallback() modify(123) override(Foo) {}
fallback() returns(uint) {}
fallback() external modify() payable override(Foo) virtual returns(uint) {}
fallback() external payable virtual {}
fallback(bytes calldata _input) external {}


receive () modify(123) override(Foo) {}
receive () external modify() payable override(Foo) virtual {}
receive () external payable {}
receive() external payable virtual {}

Expand Down Expand Up @@ -415,9 +421,14 @@ contract FunctionDefinitions {
fallback() external {}
fallback() {}
fallback() external payable {}
fallback() override(Foo) modify(123) {}
fallback() returns (uint) {}
fallback() external payable virtual override(Foo) modify returns (uint) {}
fallback() external payable virtual {}
fallback(bytes calldata _input) external {}

receive() override(Foo) modify(123) {}
receive() external payable virtual override(Foo) modify {}
receive() external payable {}
receive() external payable virtual {}

Expand Down
Loading