Skip to content

Commit

Permalink
SONARPY-2259 SONARPY-2260 add disabled tests checking if symbolV2() c…
Browse files Browse the repository at this point in the history
…orrect
  • Loading branch information
Seppli11 committed Oct 29, 2024
1 parent 2bce383 commit fe7e351
Showing 1 changed file with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Set;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.python.api.tree.AssignmentStatement;
import org.sonar.plugins.python.api.tree.FileInput;
Expand All @@ -40,23 +41,23 @@ void testSymbolTableModuleSymbols() {
FileInput fileInput = PythonTestUtils.parse(
"""
import lib
v = lib.foo()
a = lib.A()
b = a.do_something()
x = 42
def script_do_something(param):
c = 42
return c
script_do_something()
"""
);

var symbolTable = new SymbolTableBuilderV2(fileInput)
.build();

var moduleSymbols = symbolTable.getSymbolsByRootTree(fileInput);
Assertions.assertThat(moduleSymbols)
.hasSize(6)
Expand Down Expand Up @@ -97,7 +98,7 @@ void testSymbolTableGlobalSymbols() {
def script_do_something(param):
global b
b = 42
"""
);

Expand Down Expand Up @@ -130,7 +131,7 @@ def inner(param):
nonlocal a
a = "hello"
print(a)
"""
);

Expand Down Expand Up @@ -223,6 +224,44 @@ def script_do_something(param):

}


@Test
@Disabled("SONARPY-2259 primitives do not have a symbol")
void primitives_have_symbol() {
FileInput fileInput = PythonTestUtils.parse("""
x = 3
x is int
float(x)
""");

var symbolTable = new SymbolTableBuilderV2(fileInput)
.build();

var moduleSymbols = symbolTable.getSymbolsByRootTree(fileInput);
Assertions.assertThat(moduleSymbols)
.extracting(SymbolV2::name)
.containsExactlyInAnyOrder("x", "int", "float");
}

@Test
@Disabled("SONARPY-2260 variables which are never written to do not have a symbol")
void never_written_variables_have_symbol() {
FileInput fileInput = PythonTestUtils.parse("""
x + 3
if x == 3: pass
""");

var symbolTable = new SymbolTableBuilderV2(fileInput)
.build();

var moduleSymbols = symbolTable.getSymbolsByRootTree(fileInput);
Assertions.assertThat(moduleSymbols)
.extracting(SymbolV2::name)
.containsExactlyInAnyOrder("x");
}


private static void assertNameSymbol(Name name, String expectedSymbolName, int expectedUsagesCount) {
var symbol = name.symbolV2();
Assertions.assertThat(symbol).isNotNull();
Expand Down

0 comments on commit fe7e351

Please sign in to comment.