Skip to content

Commit

Permalink
Merge pull request ethereum#12798 from ethereum/lsp-tests-expectations
Browse files Browse the repository at this point in the history
LSP.py: Implement expectations directly in the test files
  • Loading branch information
christianparpart authored Apr 25, 2022
2 parents 5591740 + afd9fee commit fbecdbe
Show file tree
Hide file tree
Showing 7 changed files with 942 additions and 316 deletions.
2 changes: 1 addition & 1 deletion scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ printTask "Testing Python scripts..."
"$REPO_ROOT/test/pyscriptTests.py"

printTask "Testing LSP..."
"$REPO_ROOT/scripts/test_solidity_lsp.py" "${SOLIDITY_BUILD_DIR}/solc/solc"
"$REPO_ROOT/test/lsp.py" "${SOLIDITY_BUILD_DIR}/solc/solc"

printTask "Running commandline tests..."
# Only run in parallel if this is run on CI infrastructure
Expand Down
139 changes: 139 additions & 0 deletions test/libsolidity/lsp/goto_definition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
pragma solidity >=0.8.0;

import "./lib.sol";
// ^ @importDirective

interface I
{
function f(uint x) external returns (uint);
// ^ @functionF
}

contract IA is I
// ^^ @IASymbol
{
function f(uint x) public pure override returns (uint) { return x + 1; }
}
Expand All @@ -21,6 +24,7 @@ contract IB is I
library IntLib
{
function add(int self, int b) public pure returns (int) { return self + b; }
// ^^^ @IntLibAdd
}

contract C
Expand All @@ -29,40 +33,175 @@ contract C
function virtual_inheritance() public payable
{
obj = new IA();
// ^ @usingIASymbol
obj.f(1); // goto-definition should jump to definition of interface.
// ^ @virtualFunctionLookup
}

using IntLib for *;
function using_for(int i) pure public
{
i.add(5);
// ^ @usingIntAdd
14.add(4);
}

function useLib(uint n) public payable returns (uint)
{
return Lib.add(n, 1);
// ^ @LibSymbol
// ^ @LibAddSymbol
}

function enums(Color c) public pure returns (Color d)
// ^ @ColorSymbolInParameter
{
Color e = Color.Red;
// ^ @eVariableDeclaration
// ^ @RedEnumMemberAccess
if (c == e)
// ^ @eVariableAccess
d = Color.Green;
else
d = c;
}

type Price is uint128;
// ^^^^^ @PriceDeclaration
function udlTest() public pure returns (uint128)
{
Price p = Price.wrap(128);
// ^ @PriceSymbol
// ^ @PriceInWrap
return Price.unwrap(p);
}

function structCtorTest(uint8 v) public pure returns (uint8 result)
{
RGBColor memory c = RGBColor(v, 2 * v, 3 * v);
// ^ @RGBColorCursor
result = c.red;
int a;
// ^^^^^ @unusedLocalVar
}
}
// ----
// goto_definition: @unusedLocalVar 2072
// lib: @diagnostics 2072
// -> textDocument/definition {
// "position": @importDirective
// }
// <- [
// {
// "range": {
// "end": {
// "character": 0,
// "line": 0
// },
// "start": {
// "character": 0,
// "line": 0
// }
// },
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @usingIASymbol
// }
// <- [
// {
// "range": @IASymbol,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @virtualFunctionLookup
// }
// <- [
// {
// "range": @functionF,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @usingIntAdd
// }
// <- [
// {
// "range": @IntLibAdd,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @LibSymbol
// }
// <- [
// {
// "range": @LibLibrary,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @LibAddSymbol
// }
// <- [
// {
// "range": @addSymbol,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ColorSymbolInParameter
// }
// <- [
// {
// "range": @ColorEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @RedEnumMemberAccess
// }
// <- [
// {
// "range": @EnumMemberRed,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @eVariableAccess
// }
// <- [
// {
// "range": @eVariableDeclaration,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @PriceSymbol
// }
// <- [
// {
// "range": @PriceDeclaration,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @PriceInWrap
// }
// <- [
// {
// "range": @PriceDeclaration,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @RGBColorCursor
// }
// <- [
// {
// "range": @RGBColorStruct,
// "uri": "lib.sol"
// }
// ]
52 changes: 52 additions & 0 deletions test/libsolidity/lsp/goto_definition_imports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,70 @@
pragma solidity >=0.8.0;

import {Weather as Wetter} from "./lib.sol";
// ^ @wheatherImportCursor
import "./lib.sol" as That;
// ^^^^ @ThatImport

contract C
{
function test_symbol_alias() public pure returns (Wetter result)
// ^ @WetterCursor
{
result = Wetter.Sunny;
}

function test_library_alias() public pure returns (That.Color result)
// ^ @ThatCursor
{
That.Color color = That.Color.Red;
// ^ @ThatVarCursor ^ @ThatExpressionCursor
result = color;
}
}
// ----
// lib: @diagnostics 2072
// -> textDocument/definition {
// "position": @wheatherImportCursor
// }
// <- [
// {
// "range": @whetherEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @WetterCursor
// }
// <- [
// {
// "range": @whetherEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ThatCursor
// }
// <- [
// {
// "range": @ColorEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ThatVarCursor
// }
// <- [
// {
// "range": @ColorEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ThatExpressionCursor
// }
// <- [
// {
// "range": @ThatImport,
// "uri": "goto_definition_imports.sol"
// }
// ]
8 changes: 8 additions & 0 deletions test/libsolidity/lsp/lib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ pragma solidity >=0.8.0;
error E(uint, uint);

enum Weather {
// ^^^^^^^ @whetherEnum
Sunny,
Cloudy,
Rainy
}

/// Some custom Color enum type holding 3 colors.
enum Color {
// ^^^^^ @ColorEnum
/// Red color.
Red,
// ^^^ @EnumMemberRed
/// Green color.
Green,
/// Blue color.
Blue
}

library Lib
// @ ^^^ @LibLibrary
{
function add(uint a, uint b) public pure returns (uint result)
// ^( @addFunction
// ^^^ @addSymbol
{
result = a + b;
}
Expand All @@ -37,8 +42,11 @@ library Lib
}

struct RGBColor
// ^^^^^^^^ @RGBColorStruct
{
uint8 red;
uint8 green;
uint8 blue;
}
// ----
// lib: @diagnostics 2072
2 changes: 2 additions & 0 deletions test/libsolidity/lsp/publish_diagnostics_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ contract D
// ^^^^^^^^^^^^ @unusedContractVariable
}
}
// ----
// publish_diagnostics_1: @unusedReturnVariable 6321 @unusedVariable 2072 @unusedContractVariable 2072
2 changes: 2 additions & 0 deletions test/libsolidity/lsp/publish_diagnostics_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ contract D
// ^^^^^^^^^^^^^^^^^^^^^ @wrongArgumentsCount
}
}
// ----
// publish_diagnostics_2: @conversionError 9574 @argumentsRequired 6777 @wrongArgumentsCount 6160
Loading

0 comments on commit fbecdbe

Please sign in to comment.