Skip to content

Commit d27ca1c

Browse files
.
1 parent f649a45 commit d27ca1c

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

tests/term-text-search.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class TermTextSearch {
2+
constructor() {
3+
}
4+
}
5+
6+
7+
module.exports = TermTextSearch;
8+

tests/term-text-search.test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* 0. Definitions
3+
*
4+
* - Caret : Cursor position in text (numeric)
5+
* - Term : User input, any string value, can be empty
6+
* - Token : Matched part of term (part left, part right)
7+
* - Word : Result (combined tokens, if any)
8+
*
9+
* ###
10+
*
11+
* 1. Decide tiny aspects and limitations: Business and data requirements,
12+
* responsibilities and scope, domain specific feature needs.
13+
*
14+
* Required
15+
* - Input data expectations + assumptions:
16+
* - All values are strings
17+
* - Term can be empty
18+
* - Multi-byte support (= No RegEx for a-z possible)
19+
* - Arrow symbol constant value = '->'
20+
* - Term = Standalone part of full text
21+
* - Boundary by whitespace before and/or after
22+
* - No whitespace boundary if first + only part in full text
23+
* - Minimum term length to find = 1
24+
* - Get term if caret is ...
25+
* - In the middle of a term (any position within)
26+
* - At the end / after a term (last character)
27+
*
28+
* Optional
29+
* - Get term if caret is at term start / before term
30+
*
31+
* Excluded / Boundaries
32+
* - No other data types except strings supported
33+
* - Case does not matter (no need to check here)
34+
*
35+
* ###
36+
*
37+
* 2. Define input/output of aspects (data types, structures, results)
38+
* 3. Define function signatures (parameters, variants)
39+
*
40+
* Pseudo-type annotations similar to TypeScript/Flow:
41+
* - constructor()
42+
* - getWordAtCaretPosition(string text, uint caretPosition): string
43+
*
44+
* ###
45+
*
46+
* 4. Define edge test cases for tiny aspects (including misuse and expected fails).
47+
* For sake of simplicity, no other data types have been considered here.
48+
*
49+
* - --------- : ----- : ------------------------------------
50+
* - Expect : Text : Caret position | Reason
51+
* - --------- : ----- : ------------------------------------
52+
* - No result : '' : * | Empty
53+
* - No result : ' ' : * | Whitespace
54+
* - No result : ' A ' : Before | Whitespace
55+
* - No result : ' A ' : After | Whitespace
56+
* - Result : 'A' : Before | Match (right)
57+
* - Result : 'A' : After | Match (left)
58+
* - Result : 'AA' : Inner | Match (left + right)
59+
* - ---------- : ---- : --------------------------------------
60+
*/
61+
const TermTextSearch = require('./term-text-search');
62+
63+
const instance = new TermTextSearch();
64+
65+
describe('xxx', () => {
66+
67+
test('', () => {
68+
//const result = instance.search('');
69+
//expect(result).toStrictEqual([]);
70+
});
71+
72+
});
73+
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)