|
18 | 18 | * - Term can be empty
|
19 | 19 | * - Multi-byte support (= No RegEx for a-z possible)
|
20 | 20 | * - Arrow symbol constant value = '->'
|
| 21 | + * - Caret position must be numeric (0-N) |
21 | 22 | * - Term = Standalone part of full text
|
22 | 23 | * - Boundary by whitespace before and/or after
|
23 | 24 | * - No whitespace boundary if first + only part in full text
|
|
50 | 51 | * - --------- : ----- : ------------------------------------
|
51 | 52 | * - Expect : Text : Caret position | Reason
|
52 | 53 | * - --------- : ----- : ------------------------------------
|
53 |
| - * - No result : '' : * | Empty |
| 54 | + * - No result : '' : ? | Empty |
54 | 55 | * - No result : ' ' : * | Whitespace
|
55 | 56 | * - 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) |
61 | 59 | * - ---------- : ---- : --------------------------------------
|
62 | 60 | */
|
63 | 61 | const TermTextSearch = require('./term-text-search');
|
64 | 62 |
|
65 | 63 | const instance = new TermTextSearch();
|
66 | 64 |
|
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 | +}); |
68 | 81 |
|
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(''); |
72 | 86 | });
|
73 | 87 |
|
| 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 | + }); |
74 | 102 | });
|
75 | 103 |
|
0 commit comments