Skip to content

Commit 977aa1f

Browse files
.
1 parent d13dcc7 commit 977aa1f

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

.vscode/launch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Jest All",
8+
"program": "${workspaceFolder}/node_modules/.bin/jest",
9+
"args": [
10+
"--runInBand"
11+
],
12+
"console": "integratedTerminal",
13+
"internalConsoleOptions": "neverOpen",
14+
"disableOptimisticBPs": true,
15+
"windows": {
16+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
17+
}
18+
},
19+
{
20+
"type": "node",
21+
"request": "launch",
22+
"name": "Jest Current File",
23+
"program": "${workspaceFolder}/node_modules/.bin/jest",
24+
"args": [
25+
"${fileBasenameNoExtension}",
26+
"--config",
27+
"jest.config.js"
28+
],
29+
"console": "integratedTerminal",
30+
"internalConsoleOptions": "neverOpen",
31+
"disableOptimisticBPs": true,
32+
"windows": {
33+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
34+
}
35+
}
36+
]
37+
}

docs/word-search-terms.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
TDD-focused mini tutorial for an imaginary, minimal feature described below.
44
Based on the '5 Step Method' described on [CodeUtopia](https://codeutopia.net/blog/2016/10/10/5-step-method-to-make-test-driven-development-and-unit-testing-easy).
55

6-
**Scope**
7-
8-
Deeply think about features, expectations and limitations first. Code last.
6+
Scope: Deeply think about features, expectations and limitations first. Code last.
97

108
## Example
119

@@ -23,7 +21,7 @@ Create a search engine, that returns a set of keywords for matching words. Multi
2321

2422
### Step 1
2523

26-
Decide tiny aspects and limitations: Business and data requirements,
24+
Decide tiny aspects and limitations: Business and data requirements,
2725
responsibilities and scope, domain specific feature needs.
2826

2927
- Input data: Word list with terms
@@ -83,13 +81,13 @@ Code – See below and attached source files.
8381
*(Hardcoding data here can be a good thing, as these won't unexpectedly mutate over time or across environments)*
8482
- Start with just the text (expectations)
8583
3. Fill in pseudo-code (yet) in test cases (steps 2+3)
86-
4. Start the CLI and instruct it to watch the tests
84+
4. Start the CLI and instruct it to watch the tests
8785
- Not needed, but somehow rewarding to see things turning green over time :)
8886
5. Start implementing the real code (step 5)
8987
- Start with the simplest features
9088
- Try to get intentionally broken tests out of the way first
9189
(e.g. quit early if inputs are invalid or empty, don't pass on raw data)
92-
- Add 'ornamental code' last (e.g. anything that improves the code,
90+
- Add 'ornamental code' last (e.g. anything that improves the code,
9391
without potentially changing the test results – like refactoring optimizations)
9492
- Relates to: 'Red, Green, Refactor' cycle
9593
- Check in with the CLI regularly
@@ -154,4 +152,3 @@ There are tons of tools and services out there. Named are just a few to show wha
154152

155153
- [Jest](https://jestjs.io)
156154
- [PhpUnit](https://phpunit.de)
157-

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"type": "module",
2828
"jest": {
29+
"testEnvironment": "node",
2930
"verbose": true
3031
}
3132
}

tests/term-text-search.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ class TermTextSearch {
22
constructor() {}
33

44
getTextAtCaretPosition(text, caretPosition) {
5-
if (this.isEmpty(text)) {
5+
if (this.isEmpty(text) || !this.isValidCaretPosition(caretPosition)) {
66
return '';
77
}
8+
9+
this.getText(this.normalize(text), caretPosition);
10+
}
11+
12+
getText(text, caretPosition) {
13+
return '';
814
}
915

1016
normalize(input) {
1117
return input.toLowerCase().trim();
1218
}
1319

20+
isValidCaretPosition(caretPosition) {
21+
return caretPosition >= 0;
22+
}
23+
1424
isEmpty(input) {
1525
const text = this.normalize(input);
1626

0 commit comments

Comments
 (0)