Skip to content

Commit

Permalink
test: refactor and update tests
Browse files Browse the repository at this point in the history
test: whitespace and mininit

This removes tests for one awful corner case: if you have in a single
file both expressions `/(\d)/` and `/\d*(\d)/`, the second pattern's
regexplanation will *sometimes* erroneously repeat the heading "capture
group 1", but you can clear this up by hovering a different regexp first

This case is weird enough that I'm choosing to ignore it for now
  • Loading branch information
bennypowers committed May 28, 2024
1 parent 40da8f8 commit 3a7303d
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 212 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ watch:
-type f \
-name '*.lua' \
-o -name '*.js' \
! -path "./.tests/**/*" | entr -d make run_tests
! -path "./.tests/**/*" | entr -d make test

test:
@REGEXPLAINER_DEBOUNCE=false \
nvim \
--headless \
--noplugin \
-u tests/mininit.lua \
-c "lua require'plenary.test_harness'.test_directory('tests/regexplainer/', {minimal_init='tests/mininit.lua',sequential=true})"\
-c "PlenaryBustedDirectory tests/regexplainer/ {minimal_init='tests/mininit.lua',sequential=true,keep_going=false}"\
-c "qa!"
12 changes: 1 addition & 11 deletions tests/fixtures/narrative/01 Simple Patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `a`
*/
/a/;

/**
* `Hello`
*/
Expand All @@ -27,13 +27,3 @@
* `123`
*/
/\1\2\3/;










4 changes: 1 addition & 3 deletions tests/fixtures/narrative/02 Modifiers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/**
* @example EXPECTED:
* `hello`
* `!` (_optional_)
*/
/hello!?/;
/hello!?/;

/**
* @example EXPECTED:
* `hello`
* `.` (_optional_)
*/
Expand Down
20 changes: 10 additions & 10 deletions tests/fixtures/narrative/03 Ranges and Quantifiers.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
/**
/**
* `@hello`
* One of `a-z`
*/
/@hello[a-z]/;

/**
/**
* One of **WB**, **WORD**, **0-9**, **WS**, **TAB**, **LF**, or **CR**
*/
/[\b\w\d\s\t\n\r]/;

/**
/**
* **START**
* One of `a-z`, `A-Z`, or `0-9` (_6-12x_)
* **END**
*/
/^[a-zA-Z0-9]{6,12}$/;

/**
/**
* One of `-`, **WORD**, or `.`
*/
/[-\w.]/;

/**
/**
* One of **WORD**, `,`, or `.`
*/
/[\w,.]/;

/**
/**
* One of **WORD**, `-`, or `.`
*/
/[\w\-.]/;

/**
/**
* One of `.`, `-`, or **WORD**
*/
/[.\-\w]/;

/**
* **0-9** (_>= 0x_)
* ` `
* `(space)`
*/
/\d*\ /;

/**
/**
* `a` (_1x_)
* `b` (_>= 2x_)
* `c` (_3-5x_)
Expand All @@ -51,7 +51,7 @@
*/
/a{1}b{2,}c{3,5}d*e+/g;

/**
/**
* **WB**
* One of `a-z`, `0-9`, `.`, `\_`, `%`, `+`, or `-` (_>= 1x_)
* `@hello`
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/narrative/04 Negated Ranges.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* **START**
* `p`
* Any except `p`, `^`, or `a` (_>= 0x_)
Expand Down
15 changes: 14 additions & 1 deletion tests/fixtures/narrative/05 Capture Groups.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/**
/**
* `@`
* capture group 1:
* `hello`
*/
/@(hello)/;

/**
* capture group 1:
* **0-9**
*/
/(\d)/;

/**
* **WORD** (_>= 0x_)
* capture group 1:
* **WORD**
*/
/\w*(\w)/;

/**
* `@`
* capture group 1:
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/narrative/07 Non-Capturing Groups.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* `hello`
* non-capturing group:
* Either `world` or `dolly`
* `world`
*/
/hello(?:world|dolly)/;
/hello(?:world)/;

24 changes: 15 additions & 9 deletions tests/fixtures/narrative/09 Lookaround.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
/**
* `@` **followed by **:
* `@`
* **followed by**:
* `u`
* `@`
*/
/@(?=u)@/;

/**
* `@` **NOT followed by **:
* `@`
* **NOT followed by**:
* `u`
* `@`
*/
/@(?!u)@/;

/**
* `@` **followed by ** (_2-3x_):
* `@`
* **followed by** (_2-3x_):
* Either `up` or `down`
* `@`
*/
/@(?=up|down){2,3}@/;

/**
* `@` **NOT followed by **:
* `@`
* **NOT followed by**:
* One of **WORD**, or **WS**
* `@`
*/
/@(?![\w\s])@/;

/**
* `@` **followed by **:
* `@`
* **followed by**:
* `g`
* non-capturing group (_optional_):
* `raph`
Expand All @@ -37,14 +42,15 @@
/@(?=g(?:raph)?ql)@/;

/**
* **preceeding **:
* **preceeding**:
* `it's the `
* `attack of the killer tomatos`
*/
/(?<=it's the )attack of the killer tomatos/;

/**
* `x` **NOT preceeding **:
* `x`
* **NOT preceeding**:
* `u`
* `@`
*/
Expand All @@ -56,7 +62,7 @@


/**
* **preceeding **:
* **preceeding**:
* `g`
* `\``
* capture group 1:
Expand All @@ -66,7 +72,7 @@
/(?<=g)`(.*)`/mg;

/**
* **preceeding **:
* **preceeding**:
* `g`
* non-capturing group (_optional_):
* `raph`
Expand Down
Loading

0 comments on commit 3a7303d

Please sign in to comment.