Skip to content

Commit

Permalink
add two tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHung authored Aug 2, 2023
1 parent 1d2ed27 commit a93363e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/computation-suspension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,20 @@ describe('Evaluation suspension', () => {

expect(engine.getCellFormula(adr('C1'))).toEqual('=A2+42')
})

it('#1291 - neighboring cell changes of an array formula should be emitted', () => {
const engine = HyperFormula.buildFromArray([[null, null, null]], { useArrayArithmetic: true })
engine.suspendEvaluation()

engine.setCellContents(adr('A1'), "={1;2;3}")
engine.setCellContents(adr('B1'), "4")
engine.setCellContents(adr('C1'), "5")

const changes = engine.resumeEvaluation()
expect(changes.length).toEqual(5)
expect(changes).toContainEqual({address: adr('A1'), value: 1})
expect(changes).toContainEqual({address: adr('A2'), value: 2})
expect(changes).toContainEqual({address: adr('A3'), value: 3})
expect(changes).toContainEqual({address: adr('B1'), value: 4})
expect(changes).toContainEqual({address: adr('C1'), value: 5})
})
21 changes: 20 additions & 1 deletion test/content-changes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SpreadRangeExporter implements ChangeExporter<CellValueChange> {

describe('ContentChanges', () => {
const simpleChangeExporter = new SimpleChangeExporter()
const spreadRangeExporter = new SpreadRangeExporter()

it('should be empty', () => {
const contentChanges = ContentChanges.empty()
Expand Down Expand Up @@ -83,12 +84,30 @@ describe('ContentChanges', () => {
const contentChanges = ContentChanges.empty()
contentChanges.addChange(SimpleRangeValue.onlyValues([[1, 2], ['foo', 'bar']]), adr('A1'))

const exportedChanges = contentChanges.exportChanges(new SpreadRangeExporter())
const exportedChanges = contentChanges.exportChanges(spreadRangeExporter)

expect(exportedChanges.length).toEqual(4)
expect(exportedChanges).toContainEqual({address: adr('A1'), value: 1})
expect(exportedChanges).toContainEqual({address: adr('B1'), value: 2})
expect(exportedChanges).toContainEqual({address: adr('A2'), value: 'foo'})
expect(exportedChanges).toContainEqual({address: adr('B2'), value: 'bar'})
})

it('#1291 - array change should not delete neighboring non-overlapping changes', () => {
const contentChanges = ContentChanges.empty()
contentChanges.addChange(4, adr('B1'))
contentChanges.addChange(5, adr('C1'))

const otherChanges = ContentChanges.empty()
otherChanges.addChange(SimpleRangeValue.onlyValues([[1], [2], [3]]), adr('A1'))
contentChanges.addAll(otherChanges)

const exportedChanges = contentChanges.exportChanges(spreadRangeExporter)
expect(exportedChanges.length).toEqual(5)
expect(exportedChanges).toContainEqual({address: adr('A1'), value: 1})
expect(exportedChanges).toContainEqual({address: adr('A2'), value: 2})
expect(exportedChanges).toContainEqual({address: adr('A3'), value: 3})
expect(exportedChanges).toContainEqual({address: adr('B1'), value: 4})
expect(exportedChanges).toContainEqual({address: adr('C1'), value: 5})
})
})

0 comments on commit a93363e

Please sign in to comment.