Fixes source extraction from docs.

This commit is contained in:
Erik Kundt 2019-10-23 22:13:17 +02:00
parent abf1aa74cf
commit ec53899a10
6 changed files with 251 additions and 242 deletions

View File

@ -456,7 +456,7 @@ New version:
// Throw is now disallowed.
require(x > 100);
int y = -3 >> 1;
// y == -2 (correct)
require(y == -2);
do {
x += 1;
if (x > 10) continue;
@ -473,7 +473,7 @@ New version:
using address_make_payable for address;
// Data location for 'arr' must be specified
function g(uint[] memory arr, bytes8 x, OtherContract otherContract, address unknownContract) public payable {
function g(uint[] memory /* arr */, bytes8 x, OtherContract otherContract, address unknownContract) public payable {
// 'otherContract.transfer' is not provided.
// Since the code of 'OtherContract' is known and has the fallback
// function, address(otherContract) has type 'address payable'.

View File

@ -158,13 +158,13 @@ to write a function, for example:
// Getter function generated by the compiler
/*
function myArray(uint i) returns (uint) {
function myArray(uint i) public view returns (uint) {
return myArray[i];
}
*/
// function that returns entire array
function getArray() returns (uint[] memory) {
function getArray() public view returns (uint[] memory) {
return myArray;
}
}

View File

@ -554,7 +554,7 @@ types.
pragma solidity >=0.5.0;
pragma experimental SMTChecker;
// This will not compile
// This will report a warning
contract Aliasing
{
uint[] array;

View File

@ -39,6 +39,7 @@ def extract_test_cases(path):
# and abort a line not indented properly.
def extract_docs_cases(path):
inside = False
extractedLines = []
tests = []
# Collect all snippets of indented blocks
@ -46,15 +47,23 @@ def extract_docs_cases(path):
if l != '':
if not inside and l.startswith(' '):
# start new test
tests += ['']
extractedLines += ['']
inside = l.startswith(' ')
if inside:
tests[-1] += l + '\n'
# Filter all tests that do not contain Solidity
return [
test for test in tests
if re.search(r'^ [ ]*(pragma solidity|contract |library |interface )', test, re.MULTILINE)
]
extractedLines[-1] += l + '\n'
codeStart = "(pragma solidity|contract.*{|library.*{|interface.*{)"
# Filter all tests that do not contain Solidity or are intended incorrectly.
for lines in extractedLines:
if re.search(r'^\s{0,3}' + codeStart, lines, re.MULTILINE):
print("Intendation error in " + path + ":")
print(lines)
exit(1)
if re.search(r'^\s{4}' + codeStart, lines, re.MULTILINE):
tests.append(lines)
return tests
def write_cases(f, tests):
cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower()