Skip to content

Commit 3485bc9

Browse files
committed
Reformat tests in nlohmann::json style.
1 parent 59a16df commit 3485bc9

File tree

470 files changed

+4707
-9427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

470 files changed

+4707
-9427
lines changed

libsolutil/JSON.cpp

-64
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include <libsolutil/CommonData.h>
2626

2727
#include <boost/algorithm/string.hpp>
28-
#include <boost/algorithm/string/trim.hpp>
2928

30-
#include <map>
3129
#include <sstream>
3230

3331
#ifdef STRICT_NLOHMANN_JSON_VERSION_CHECK
@@ -65,64 +63,6 @@ void removeNullMembersHelper(Json& _json)
6563
}
6664
}
6765

68-
std::string trimRightAllLines(std::string const& input)
69-
{
70-
std::vector<std::string> lines;
71-
std::string output;
72-
boost::split(lines, input, boost::is_any_of("\n"));
73-
for (auto& line: lines)
74-
{
75-
boost::trim_right(line);
76-
if (!line.empty())
77-
output += line + "\n";
78-
}
79-
return boost::trim_right_copy(output);
80-
}
81-
82-
std::string formatLikeJsoncpp(std::string const& _dumped, JsonFormat const& _format)
83-
{
84-
uint32_t indentLevel = 0;
85-
std::stringstream reformatted;
86-
bool inQuotes = false;
87-
for (size_t i = 0; i < _dumped.size(); ++i)
88-
{
89-
char c = _dumped[i];
90-
bool emptyThing = false;
91-
92-
if (c == '"' && (i == 0 || _dumped[i - 1] != '\\'))
93-
inQuotes = !inQuotes;
94-
95-
if (!inQuotes)
96-
{
97-
if (i < _dumped.size() - 1)
98-
{
99-
char nc = _dumped[i + 1];
100-
if ((c == '[' && nc == ']') || (c == '{' && nc == '}'))
101-
emptyThing = true;
102-
}
103-
if (c == '[' || c == '{')
104-
{
105-
if (i > 0 && _dumped[i - 1] != '\n')
106-
if (!emptyThing)
107-
reformatted << '\n' << std::string(indentLevel * _format.indent, ' ');
108-
indentLevel++;
109-
}
110-
else if (c == ']' || c == '}')
111-
{
112-
indentLevel--;
113-
if (i + 1 < _dumped.size() && _dumped[i + 1] != '\n'
114-
&& (_dumped[i + 1] == ']' || _dumped[i + 1] == '}'))
115-
reformatted << '\n' << std::string(indentLevel * _format.indent, ' ');
116-
}
117-
}
118-
reformatted << c;
119-
if (!emptyThing && !inQuotes && (c == '[' || c == '{') && indentLevel > 0 && i + 1 < _dumped.size()
120-
&& _dumped[i + 1] != '\n')
121-
reformatted << '\n' << std::string(indentLevel * _format.indent, ' ');
122-
}
123-
return trimRightAllLines(reformatted.str());
124-
}
125-
12666
std::string escapeNewlinesAndTabsWithinStringLiterals(std::string const& _json)
12767
{
12868
std::stringstream fixed;
@@ -201,10 +141,6 @@ std::string jsonPrint(Json const& _input, JsonFormat const& _format)
201141
/* ensure_ascii */ true
202142
);
203143

204-
// let's remove this once all test-cases having the correct output.
205-
if (_format.format == JsonFormat::Pretty)
206-
dumped = formatLikeJsoncpp(dumped, _format);
207-
208144
return dumped;
209145
}
210146

test/cmdlineTests/abi_via_ir/output

+12-24
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Contract JSON ABI
44
[
55
{
6-
"inputs":
7-
[
6+
"inputs": [
87
{
98
"internalType": "uint256",
109
"name": "z",
@@ -20,8 +19,7 @@ Contract JSON ABI
2019
"type": "error"
2120
},
2221
{
23-
"inputs":
24-
[
22+
"inputs": [
2523
{
2624
"internalType": "uint256",
2725
"name": "z",
@@ -32,8 +30,7 @@ Contract JSON ABI
3230
"type": "error"
3331
},
3432
{
35-
"inputs":
36-
[
33+
"inputs": [
3734
{
3835
"internalType": "uint256",
3936
"name": "r",
@@ -45,8 +42,7 @@ Contract JSON ABI
4542
},
4643
{
4744
"anonymous": true,
48-
"inputs":
49-
[
45+
"inputs": [
5046
{
5147
"indexed": false,
5248
"internalType": "uint256",
@@ -59,8 +55,7 @@ Contract JSON ABI
5955
},
6056
{
6157
"anonymous": false,
62-
"inputs":
63-
[
58+
"inputs": [
6459
{
6560
"indexed": false,
6661
"internalType": "uint256",
@@ -73,8 +68,7 @@ Contract JSON ABI
7368
},
7469
{
7570
"anonymous": false,
76-
"inputs":
77-
[
71+
"inputs": [
7872
{
7973
"indexed": false,
8074
"internalType": "uint256",
@@ -86,11 +80,9 @@ Contract JSON ABI
8680
"type": "event"
8781
},
8882
{
89-
"inputs":
90-
[
83+
"inputs": [
9184
{
92-
"components":
93-
[
85+
"components": [
9486
{
9587
"internalType": "uint256",
9688
"name": "x",
@@ -113,8 +105,7 @@ Contract JSON ABI
113105
Contract JSON ABI
114106
[
115107
{
116-
"inputs":
117-
[
108+
"inputs": [
118109
{
119110
"internalType": "uint256",
120111
"name": "r",
@@ -125,8 +116,7 @@ Contract JSON ABI
125116
"type": "error"
126117
},
127118
{
128-
"inputs":
129-
[
119+
"inputs": [
130120
{
131121
"internalType": "uint256",
132122
"name": "u",
@@ -138,8 +128,7 @@ Contract JSON ABI
138128
},
139129
{
140130
"anonymous": false,
141-
"inputs":
142-
[
131+
"inputs": [
143132
{
144133
"indexed": false,
145134
"internalType": "uint256",
@@ -152,8 +141,7 @@ Contract JSON ABI
152141
},
153142
{
154143
"anonymous": false,
155-
"inputs":
156-
[
144+
"inputs": [
157145
{
158146
"indexed": false,
159147
"internalType": "uint256",

test/cmdlineTests/asm_json/output

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
======= asm_json/input.sol:C =======
33
EVM assembly:
44
{
5-
".code":
6-
[
5+
".code": [
76
{
87
"begin": 60,
98
"end": 160,
@@ -140,13 +139,10 @@ EVM assembly:
140139
"source": 0
141140
}
142141
],
143-
".data":
144-
{
145-
"0":
146-
{
142+
".data": {
143+
"0": {
147144
".auxdata": "<BYTECODE REMOVED>",
148-
".code":
149-
[
145+
".code": [
150146
{
151147
"begin": 60,
152148
"end": 160,
@@ -1570,8 +1566,7 @@ EVM assembly:
15701566
]
15711567
}
15721568
},
1573-
"sourceList":
1574-
[
1569+
"sourceList": [
15751570
"asm_json/input.sol",
15761571
"#utility.yul"
15771572
]

test/cmdlineTests/ast_compact_json_with_base_path/output

+9-18
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@ JSON AST (compact format):
44
======= ast_compact_json_with_base_path/c.sol =======
55
{
66
"absolutePath": "ast_compact_json_with_base_path/c.sol",
7-
"exportedSymbols":
8-
{
9-
"C":
10-
[
7+
"exportedSymbols": {
8+
"C": [
119
5
1210
]
1311
},
1412
"id": 6,
1513
"license": "GPL-3.0",
1614
"nodeType": "SourceUnit",
17-
"nodes":
18-
[
15+
"nodes": [
1916
{
2017
"id": 4,
21-
"literals":
22-
[
18+
"literals": [
2319
"solidity",
2420
">=",
2521
"0.0"
@@ -35,8 +31,7 @@ JSON AST (compact format):
3531
"contractKind": "contract",
3632
"fullyImplemented": true,
3733
"id": 5,
38-
"linearizedBaseContracts":
39-
[
34+
"linearizedBaseContracts": [
4035
5
4136
],
4237
"name": "C",
@@ -54,22 +49,18 @@ JSON AST (compact format):
5449
======= ast_compact_json_with_base_path/input.sol =======
5550
{
5651
"absolutePath": "ast_compact_json_with_base_path/input.sol",
57-
"exportedSymbols":
58-
{
59-
"C":
60-
[
52+
"exportedSymbols": {
53+
"C": [
6154
5
6255
]
6356
},
6457
"id": 3,
6558
"license": "GPL-3.0",
6659
"nodeType": "SourceUnit",
67-
"nodes":
68-
[
60+
"nodes": [
6961
{
7062
"id": 1,
71-
"literals":
72-
[
63+
"literals": [
7364
"solidity",
7465
">=",
7566
"0.0"

0 commit comments

Comments
 (0)