mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Add replace and updateSpans to SpanIndex.
This commit is contained in:
@@ -5,6 +5,16 @@ describe "SpanIndex", ->
|
||||
beforeEach ->
|
||||
index = new SpanIndex
|
||||
|
||||
describe ".updateSpans(start, end, spans)", ->
|
||||
it "updates the spans of a range of entries indicated by the given index to the given value", ->
|
||||
index.insert(0, [3, 2, 3, 1, 2], ['a', 'b', 'c', 'd', 'e'])
|
||||
index.updateSpans(1, 3, 1)
|
||||
expect(index.spanForIndex(1)).toBe 3
|
||||
expect(index.spanForIndex(2)).toBe 4
|
||||
expect(index.spanForIndex(3)).toBe 5
|
||||
expect(index.spanForIndex(4)).toBe 6
|
||||
expect(index.spanForIndex(5)).toBe 8
|
||||
|
||||
describe ".sliceBySpan(start, end)", ->
|
||||
describe "when the index contains values that start and end evenly on the given start/end span indices", ->
|
||||
it "returns the spanning values with a start and end offset of 0", ->
|
||||
|
||||
@@ -8,9 +8,16 @@ class SpanIndex
|
||||
insert: (index, spans, values) ->
|
||||
@entries[index..index] = @buildIndexEntries(spans, values)
|
||||
|
||||
replace: (index, span, value) ->
|
||||
@splice(index, index, span, [value])
|
||||
|
||||
splice: (start, end, spans, values) ->
|
||||
@entries[start..end] = @buildIndexEntries(spans, values)
|
||||
|
||||
updateSpans: (start, end, span) ->
|
||||
for i in [start..end]
|
||||
@entries[i].span = span
|
||||
|
||||
at: (index) ->
|
||||
@entries[index].value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user