Skip to content

Commit ef36bb4

Browse files
.
1 parent ccf403c commit ef36bb4

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

tests/term-text-search.test.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* - Term can be empty
1919
* - Multi-byte support (= No RegEx for a-z possible)
2020
* - Arrow symbol constant value = '->'
21+
* - Caret position must be numeric (0-N)
2122
* - Term = Standalone part of full text
2223
* - Boundary by whitespace before and/or after
2324
* - No whitespace boundary if first + only part in full text
@@ -50,26 +51,53 @@
5051
* - --------- : ----- : ------------------------------------
5152
* - Expect : Text : Caret position | Reason
5253
* - --------- : ----- : ------------------------------------
53-
* - No result : '' : * | Empty
54+
* - No result : '' : ? | Empty
5455
* - No result : ' ' : * | Whitespace
5556
* - No result : ' A ' : Before | Whitespace
56-
* - No result : ' 1 ' : After | Whitespace – Numeric
57-
* - Result : 'A' : Before | Match (right)
58-
* - Result : '1' : After | Match (left) – Numeric
59-
* - Result : 'AA' : Inner | Match (left + right)
60-
* - Result : '#' : Before | Match (right) – Special character
57+
* - Result : '👍' : Before | Match (right)
58+
* - Result : 'A1' : Inner | Match (left + right)
6159
* - ---------- : ---- : --------------------------------------
6260
*/
6361
const TermTextSearch = require('./term-text-search');
6462

6563
const instance = new TermTextSearch();
6664

67-
describe('Term text search', () => {
65+
describe('Term text search – Expect results', () => {
66+
test('for single letter text (from right)', () => {
67+
const result = instance.getTextAtCaretPosition('#', 1);
68+
expect(result).toStrictEqual('#');
69+
});
70+
71+
test('for within text', () => {
72+
const result = instance.getTextAtCaretPosition('A1', 1);
73+
expect(result).toStrictEqual('A1');
74+
});
75+
76+
test('for multi-byte text (from left)', () => {
77+
const result = instance.getTextAtCaretPosition('👍', 0);
78+
expect(result).toStrictEqual('👍');
79+
});
80+
});
6881

69-
test('no result for empty text', () => {
70-
//const result = instance.getTextAtCaretPosition('');
71-
//expect(result).toStrictEqual([]);
82+
describe('Term text search – Expect no results', () => {
83+
test('for empty text', () => {
84+
const result = instance.getTextAtCaretPosition('', 0);
85+
expect(result).toStrictEqual('');
7286
});
7387

88+
test('for whitespace text', () => {
89+
const result = instance.getTextAtCaretPosition(' ', 1);
90+
expect(result).toStrictEqual('');
91+
});
92+
93+
test('for word surrounded by whitespaces', () => {
94+
const result = instance.getTextAtCaretPosition(' A ', 3);
95+
expect(result).toStrictEqual('');
96+
});
97+
98+
test('for word surrounded by whitespaces', () => {
99+
const result = instance.getTextAtCaretPosition(' A ', 3);
100+
expect(result).toStrictEqual('');
101+
});
74102
});
75103

0 commit comments

Comments
 (0)