Search in sources :

Example 36 with DocumentContext

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);
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with DocumentContext

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();
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ParameterDefinition(com.github._1c_syntax.bsl.languageserver.context.symbol.ParameterDefinition) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with DocumentContext

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");
}
Also used : AbstractMDObjectBase(com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase) MDOReference(com.github._1c_syntax.mdclasses.mdo.support.MDOReference) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with DocumentContext

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);
    }
}
Also used : SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with DocumentContext

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);
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)86 Test (org.junit.jupiter.api.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)57 Diagnostic (org.eclipse.lsp4j.Diagnostic)36 List (java.util.List)22 Position (org.eclipse.lsp4j.Position)21 SneakyThrows (lombok.SneakyThrows)17 Path (java.nio.file.Path)16 CodeAction (org.eclipse.lsp4j.CodeAction)16 TestUtils (com.github._1c_syntax.bsl.languageserver.util.TestUtils)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Collectors (java.util.stream.Collectors)14 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)12 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)12 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)11 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)10 MDCommonModule (com.github._1c_syntax.mdclasses.mdo.MDCommonModule)10