LCOV - code coverage report
Current view: top level - test/unittests/torque - ls-server-data-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 27 27 100.0 %
Date: 2019-04-17 Functions: 8 10 80.0 %

          Line data    Source code
       1             : // Copyright 2019 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/torque/server-data.h"
       6             : #include "src/torque/torque-compiler.h"
       7             : #include "test/unittests/test-utils.h"
       8             : 
       9             : namespace v8 {
      10             : namespace internal {
      11             : namespace torque {
      12             : 
      13             : namespace {
      14             : 
      15           6 : struct TestCompiler {
      16             :   SourceFileMap::Scope file_map_scope;
      17             :   LanguageServerData::Scope server_data_scope;
      18             : 
      19           2 :   void Compile(const std::string& source) {
      20             :     TorqueCompilerOptions options;
      21           2 :     options.abort_on_lint_errors = false;
      22             :     options.output_directory = "";
      23           2 :     options.verbose = false;
      24           2 :     options.collect_language_server_data = true;
      25             : 
      26           6 :     const TorqueCompilerResult result = CompileTorque(source, options);
      27             :     SourceFileMap::Get() = result.source_file_map;
      28             :     LanguageServerData::Get() = result.language_server_data;
      29           2 :   }
      30             : };
      31             : 
      32             : }  // namespace
      33             : 
      34       15443 : TEST(LanguageServer, GotoTypeDefinition) {
      35             :   const std::string source =
      36             :       "type void;\n"
      37             :       "type never;\n"
      38             :       "type T1 generates 'TNode<Object>';\n"
      39             :       "type T2 generates 'TNode<Object>';\n"
      40           1 :       "macro SomeMacro(a: T1, b: T2): T1 { return a; }";
      41             : 
      42           1 :   TestCompiler compiler;
      43           1 :   compiler.Compile(source);
      44             : 
      45             :   // Find the definition for type 'T1' of argument 'a' on line 4.
      46           2 :   const SourceId id = SourceFileMap::GetSourceId("<torque>");
      47           1 :   auto maybe_position = LanguageServerData::FindDefinition(id, {4, 19});
      48           1 :   ASSERT_TRUE(maybe_position.has_value());
      49           2 :   EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 7}}));
      50             : 
      51             :   // Find the defintion for type 'T2' of argument 'b' on line 4.
      52           2 :   maybe_position = LanguageServerData::FindDefinition(id, {4, 26});
      53           1 :   ASSERT_TRUE(maybe_position.has_value());
      54           2 :   EXPECT_EQ(*maybe_position, (SourcePosition{id, {3, 5}, {3, 7}}));
      55             : }
      56             : 
      57       15443 : TEST(LanguageServer, GotoTypeDefinitionExtends) {
      58             :   const std::string source =
      59             :       "type void;\n"
      60             :       "type never;\n"
      61             :       "type T1 generates 'TNode<T1>';\n"
      62           1 :       "type T2 extends T1 generates 'TNode<T2>';";
      63             : 
      64           1 :   TestCompiler compiler;
      65           1 :   compiler.Compile(source);
      66             : 
      67             :   // Find the definition for 'T1' of the extends clause on line 3.
      68           2 :   const SourceId id = SourceFileMap::GetSourceId("<torque>");
      69           1 :   auto maybe_position = LanguageServerData::FindDefinition(id, {3, 16});
      70           1 :   ASSERT_TRUE(maybe_position.has_value());
      71           2 :   EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 7}}));
      72             : }
      73             : 
      74             : }  // namespace torque
      75             : }  // namespace internal
      76        9264 : }  // namespace v8

Generated by: LCOV version 1.10