mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Add tests to traverseRegexMatchesInRange
This commit is contained in:
parent
51c4e012df
commit
d739ebddbc
@ -243,6 +243,41 @@ describe 'Buffer', ->
|
||||
expect(matches[2][1]).toBe 'rr'
|
||||
expect(ranges[2]).toEqual [[6,34], [6,41]]
|
||||
|
||||
describe "when the last regex match exceeds the end of the range", ->
|
||||
describe "when the portion of the match within the range also matches the regex", ->
|
||||
it "calls the iterator with the truncated match", ->
|
||||
matches = []
|
||||
ranges = []
|
||||
buffer.traverseRegexMatchesInRange /cu(r*)/g, [[4,0], [6,9]], (match, range) ->
|
||||
matches.push(match)
|
||||
ranges.push(range)
|
||||
|
||||
expect(matches.length).toBe 2
|
||||
expect(ranges.length).toBe 2
|
||||
|
||||
expect(matches[0][0]).toBe 'curr'
|
||||
expect(matches[0][1]).toBe 'rr'
|
||||
expect(ranges[0]).toEqual [[5,6], [5,10]]
|
||||
|
||||
expect(matches[1][0]).toBe 'cur'
|
||||
expect(matches[1][1]).toBe 'r'
|
||||
expect(ranges[1]).toEqual [[6,6], [6,9]]
|
||||
|
||||
describe "when the portion of the match within the range does not matches the regex", ->
|
||||
it "calls the iterator with the truncated match", ->
|
||||
matches = []
|
||||
ranges = []
|
||||
buffer.traverseRegexMatchesInRange /cu(r*)e/g, [[4,0], [6,9]], (match, range) ->
|
||||
matches.push(match)
|
||||
ranges.push(range)
|
||||
|
||||
expect(matches.length).toBe 1
|
||||
expect(ranges.length).toBe 1
|
||||
|
||||
expect(matches[0][0]).toBe 'curre'
|
||||
expect(matches[0][1]).toBe 'rr'
|
||||
expect(ranges[0]).toEqual [[5,6], [5,11]]
|
||||
|
||||
describe "when the iterator calls the 'replace' control function with a replacement string", ->
|
||||
it "replaces each occurrence of the regex match with the string", ->
|
||||
ranges = []
|
||||
|
@ -158,7 +158,7 @@ class Buffer
|
||||
|
||||
if matchEndIndex > endIndex
|
||||
regex.lastIndex = 0
|
||||
if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex..endIndex])
|
||||
if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex...endIndex])
|
||||
matchLength = match[0].length
|
||||
matchEndIndex = matchStartIndex + matchLength
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user