1 /**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <cstddef>
18 #include <cstdio>
19 #include "lsp_api_test.h"
20 #include "public/es2panda_lib.h"
21 #include "lsp/include/internal_api.h"
22 #include "lsp/include/line_column_offset.h"
23
24 using ark::es2panda::lsp::Initializer;
25
26 class LCOTests : public LSPAPITests {};
27
TEST_F(LCOTests,LCOPositionIsZero)28 TEST_F(LCOTests, LCOPositionIsZero)
29 {
30 auto posZero = 0;
31 Initializer initializer = Initializer();
32 es2panda_Context *context =
33 initializer.CreateContext("not-found-node.ets", ES2PANDA_STATE_CHECKED,
34 "interface X\n{ name: string};\nlet variable: X = { name: 'Test' };\n");
35 auto lineAndChar = ark::es2panda::lsp::ToLineColumnOffset(context, posZero);
36
37 auto expectedLine = 0;
38 ASSERT_EQ(lineAndChar.GetLine(), expectedLine);
39 ASSERT_EQ(lineAndChar.GetCharacter(), posZero);
40
41 initializer.DestroyContext(context);
42 }
TEST_F(LCOTests,LCOPositionIsCorrect)43 TEST_F(LCOTests, LCOPositionIsCorrect)
44 {
45 const size_t position = 33;
46 Initializer initializer = Initializer();
47 es2panda_Context *context =
48 initializer.CreateContext("not-found-node.ets", ES2PANDA_STATE_CHECKED,
49 "interface X\n{ name: string};\nlet variable: X = { name: 'Test' };\n");
50 auto lineAndChar = ark::es2panda::lsp::ToLineColumnOffset(context, position);
51
52 auto expectedLine = 2;
53 ASSERT_EQ(lineAndChar.GetLine(), expectedLine);
54 ASSERT_EQ(lineAndChar.GetCharacter(), position);
55
56 initializer.DestroyContext(context);
57 }
58