forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompletionManagerLegacyTests.java
More file actions
143 lines (125 loc) · 6.04 KB
/
Copy pathCompletionManagerLegacyTests.java
File metadata and controls
143 lines (125 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.completion;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.junit.jupiter.api.Test;
class CompletionManagerLegacyTests {
@Test
void testGetGhostTexts1() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") {", "int[] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTexts2() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(")", "int[] arr, int low, int high) {", 0);
assertEquals(2, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText inlineGhostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("int[] arr, int low, int high", inlineGhostText.getText());
assertEquals(0, inlineGhostText.getModelOffset());
assertTrue(EolGhostText.class.isInstance(ghostTexts.get(1)));
EolGhostText eolGhostText = (EolGhostText) ghostTexts.get(1);
assertEquals(" {", eolGhostText.getText());
assertEquals(1, eolGhostText.getModelOffset());
}
@Test
void testGetGhostTexts3() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts("int[] arr, int low, int high) {",
"int[] arr, int low, int high) {", 0);
assertTrue(ghostTexts.isEmpty());
}
@Test
void testGetGhostTexts4() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts("]) {", "] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals(" arr, int low, int high", ghostText.getText());
assertEquals(1, ghostText.getModelOffset());
}
@Test
void testGetGhostTexts5() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts("", "int[] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(EolGhostText.class.isInstance(ghostTexts.get(0)));
EolGhostText ghostText = (EolGhostText) ghostTexts.get(0);
assertEquals("int[] arr, int low, int high) {", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithNewLineCharacterOnTheTail() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") {\n", "(int[] arr, int low, int high) {",
0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithNewLineCharacterOnTheTail2() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") {\r", "(int[] arr, int low, int high) {",
0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithNewLineCharacterOnTheTail3() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") {\r\n",
"(int[] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithTabCharacterOnTheTail() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") {\t", "(int[] arr, int low, int high) {",
0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithSpaceCharactersOnTheTail() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") { \r\n",
"(int[] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithChaoticCharactersOnTheTail() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts(") {\t\t\r\t\n\t\n\r\n",
"(int[] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
@Test
void testGetGhostTextWithWhiteSpaceCharactersOnTheTailWithoutCurlyBrace() {
List<GhostText> ghostTexts = CompletionManagerLegacy.getGhostTexts("\t\t\r\t\n\t\n\r\n",
"(int[] arr, int low, int high) {", 0);
assertEquals(1, ghostTexts.size());
assertTrue(InlineGhostText.class.isInstance(ghostTexts.get(0)));
InlineGhostText ghostText = (InlineGhostText) ghostTexts.get(0);
assertEquals("(int[] arr, int low, int high) {", ghostText.getText());
assertEquals(0, ghostText.getModelOffset());
}
}