Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion test/cruds/adding-columns.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ExportedCellChange, HyperFormula} from '../../src'
import {AlwaysSparse, ExportedCellChange, HyperFormula} from '../../src'
import {AbsoluteCellRange} from '../../src/AbsoluteCellRange'
import {Config} from '../../src/Config'
import {ArrayVertex, FormulaCellVertex} from '../../src/DependencyGraph'
Expand Down Expand Up @@ -424,3 +424,63 @@ describe('Adding column - arrays', () => {
expect(matrixVertex.getAddress(engine.lazilyTransformingAstService)).toEqual(adr('D1'))
})
})

describe('Adding a column at the beginning of the sheet', () => {
it('works with buildEmpty', () => {
const engine = HyperFormula.buildEmpty()
engine.addSheet()
engine.setCellContents({col: 0, row: 0, sheet: 0}, 1)
engine.setCellContents({col: 0, row: 1, sheet: 0}, 2)
engine.setCellContents({col: 0, row: 5, sheet: 0}, 5)
engine.addColumns(0, [0, 1])

expect(engine.getSheetSerialized(0)).toEqual([[null, 1], [null, 2], [], [], [], [null, 5]])
})

it('works with buildFromArray', () => {
const engine = HyperFormula.buildFromArray([[1], [2], [], [], [], [5]])
engine.addColumns(0, [0, 1])

expect(engine.getSheetSerialized(0)).toEqual([[null, 1], [null, 2], [], [], [], [null, 5]])
})

it('works with buildEmpty and AlwaysDense', () => {
const engine = HyperFormula.buildEmpty({chooseAddressMappingPolicy: new AlwaysDense()})
engine.addSheet()
engine.setCellContents({col: 0, row: 0, sheet: 0}, 1)
engine.setCellContents({col: 0, row: 1, sheet: 0}, 2)
engine.setCellContents({col: 0, row: 5, sheet: 0}, 5)
engine.addColumns(0, [0, 1])

expect(engine.getSheetSerialized(0)).toEqual([[null, 1], [null, 2], [], [], [], [null, 5]])
})

it('works with buildFromArray and AlwaysDense', () => {
const engine = HyperFormula.buildFromArray([[1], [2], [], [], [], [5]], {
chooseAddressMappingPolicy: new AlwaysDense(),
})
engine.addColumns(0, [0, 1])

expect(engine.getSheetSerialized(0)).toEqual([[null, 1], [null, 2], [], [], [], [null, 5]])
})

it('works with buildEmpty and AlwaysSparse', () => {
const engine = HyperFormula.buildEmpty({chooseAddressMappingPolicy: new AlwaysSparse()})
engine.addSheet()
engine.setCellContents({col: 0, row: 0, sheet: 0}, 1)
engine.setCellContents({col: 0, row: 1, sheet: 0}, 2)
engine.setCellContents({col: 0, row: 5, sheet: 0}, 5)
engine.addColumns(0, [0, 1])

expect(engine.getSheetSerialized(0)).toEqual([[null, 1], [null, 2], [], [], [], [null, 5]])
})

it('works with buildFromArray and AlwaysSparse', () => {
const engine = HyperFormula.buildFromArray([[1], [2], [], [], [], [5]], {
chooseAddressMappingPolicy: new AlwaysSparse(),
})
engine.addColumns(0, [0, 1])

expect(engine.getSheetSerialized(0)).toEqual([[null, 1], [null, 2], [], [], [], [null, 5]])
})
})