Skip to content

Commit 22c0a0a

Browse files
committed
fix(regex): fix space removal to only include leading and trailing spaces
1 parent 1d1c961 commit 22c0a0a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/regex.fnk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ reg = rx'
1818
```
1919
---
2020
rx = fn strings, ...exprs:
21-
ingorables = regex raw'(\#.*\n)|[\n\s]'
21+
ingorables = regex raw'(\s*#.*\n)|(\n\s*)'
2222

2323
[...parts] = pipe strings.raw:
2424
map part:

src/regex.test.fnk

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{describe, it, expect, to_equal} = import '@fink/jest'
22

3-
{matches, match_all, find_index, split, replace_all, replace, rx} = import './regex'
3+
{matches, match_all, find_index, split, replace_all, replace, rx, regex} = import './regex'
44

55

66
describe 'regex', fn:
@@ -63,8 +63,21 @@ describe 'string templates', fn:
6363
expect
6464
rx'
6565
(?<year>\d{4})- # year part of a date
66-
(?<month>\d{2})- # month part of a date
66+
(?<month>\d{2})- # month part of a date
6767
(?<day>\d{2}) # day part of a date
6868
'
6969
to_equal rx'(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})'
7070

71+
72+
it 'handles escaping comment', fn:
73+
expect
74+
rx'foo\#bar'
75+
to_equal regex 'foo\\#bar'
76+
77+
78+
it 'handles spaces', fn:
79+
expect
80+
rx'[ ]{3}'
81+
to_equal regex '[ ]{3}'
82+
83+

0 commit comments

Comments
 (0)