use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CyclomaticComplexityComputerTest method compute.
@Test
void compute() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/computer/CyclomaticComplexityComputerTest.bsl");
// when
Computer<ComplexityData> cyclomaticComplexityComputer = new CyclomaticComplexityComputer(documentContext);
ComplexityData data = cyclomaticComplexityComputer.compute();
final Map<MethodSymbol, Integer> methodsComplexity = data.getMethodsComplexity();
// then
MethodSymbol example1 = documentContext.getSymbolTree().getMethods().get(0);
Integer example1Complexity = methodsComplexity.get(example1);
assertThat(example1Complexity).isEqualTo(12);
MethodSymbol example2 = documentContext.getSymbolTree().getMethods().get(1);
Integer example2Complexity = methodsComplexity.get(example2);
assertThat(example2Complexity).isEqualTo(11);
MethodSymbol example3 = documentContext.getSymbolTree().getMethods().get(2);
Integer example3Complexity = methodsComplexity.get(example3);
assertThat(example3Complexity).isEqualTo(1);
MethodSymbol example4 = documentContext.getSymbolTree().getMethods().get(3);
Integer example4Complexity = methodsComplexity.get(example4);
assertThat(example4Complexity).isEqualTo(15);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class MethodSymbolComputerTest method testParameters.
@Test
void testParameters() {
DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/computer/MethodSymbolComputerTest.bsl");
List<MethodSymbol> methods = documentContext.getSymbolTree().getMethods();
List<ParameterDefinition> parameters = methods.get(2).getParameters();
assertThat(parameters.size()).isEqualTo(4);
assertThat(parameters.get(0).getName()).isEqualTo("Парам");
assertThat(parameters.get(0).isByValue()).isFalse();
assertThat(parameters.get(0).isOptional()).isFalse();
assertThat(parameters.get(0).getRange()).isEqualTo(Ranges.create(14, 12, 17));
assertThat(parameters.get(1).getName()).isEqualTo("Парам2");
assertThat(parameters.get(1).isByValue()).isTrue();
assertThat(parameters.get(1).isOptional()).isFalse();
assertThat(parameters.get(1).getRange()).isEqualTo(Ranges.create(14, 24, 30));
assertThat(parameters.get(2).getName()).isEqualTo("Парам3");
assertThat(parameters.get(2).isByValue()).isFalse();
assertThat(parameters.get(2).isOptional()).isTrue();
assertThat(parameters.get(2).getDefaultValue().getValue()).isEqualTo("0");
assertThat(parameters.get(2).getRange()).isEqualTo(Ranges.create(14, 32, 38));
assertThat(parameters.get(3).getName()).isEqualTo("Парам4");
assertThat(parameters.get(3).isByValue()).isTrue();
assertThat(parameters.get(3).isOptional()).isTrue();
assertThat(parameters.get(3).getDefaultValue().getValue()).isEqualTo("0");
assertThat(parameters.get(3).getRange()).isEqualTo(Ranges.create(14, 49, 55));
parameters = methods.get(23).getParameters();
assertThat(parameters.get(0).getName()).isEqualTo("Парам1");
assertThat(parameters.get(0).getDescription()).isPresent();
assertThat(parameters.get(1).getName()).isEqualTo("Парам2");
assertThat(parameters.get(1).getDescription()).isEmpty();
assertThat(parameters.get(2).getName()).isEqualTo("Парам3");
assertThat(parameters.get(2).getDescription()).isPresent();
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class ModuleSymbolComputerTest method testModuleName.
@Test
void testModuleName() {
// given
var documentContext = spy(TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/ModuleSymbol.bsl"));
var computer = new ModuleSymbolComputer(documentContext);
MDOReference mdoReference = mock(MDOReference.class);
when(mdoReference.getMdoRef()).thenReturn("Document.Document1");
AbstractMDObjectBase mdObject = mock(AbstractMDObjectBase.class);
when(mdObject.getMdoReference()).thenReturn(mdoReference);
doReturn(Optional.of(mdObject)).when(documentContext).getMdObject();
// when-then pairs:
// when
doReturn(ModuleType.UNKNOWN).when(documentContext).getModuleType();
var moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1");
// when
doReturn(ModuleType.ObjectModule).when(documentContext).getModuleType();
moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1.ObjectModule");
// when
doReturn(ModuleType.ManagerModule).when(documentContext).getModuleType();
moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1.ManagerModule");
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class SymbolTreeComputerTest method testModule.
@Test
void testModule() {
// given
var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/SymbolTreeComputer.bsl");
var symbolTreeComputer = new SymbolTreeComputer(documentContext);
// when
var symbolTree = symbolTreeComputer.compute();
// then
var module = symbolTree.getModule();
assertThat(module.getOwner()).isEqualTo(documentContext);
assertThat(module.getParent()).isEmpty();
assertThat(module.getChildren()).hasSize(2);
for (SourceDefinedSymbol child : module.getChildren()) {
assertThat(child.getParent()).hasValue(module);
}
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class AbstractDiagnosticTest method getQuickFixes.
protected List<CodeAction> getQuickFixes(Range range) {
DocumentContext documentContext = getDocumentContext();
List<Diagnostic> diagnostics = this.diagnosticInstance.getDiagnostics(documentContext);
return getQuickFixes(documentContext, diagnostics, range);
}
Aggregations