Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pu/issue617 #619

Merged
merged 18 commits into from
Apr 14, 2021
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- GPU.js constructor needs to be provided directly to engine configuration. (#355)
- A **breaking change**: `'` symbol on the input is preserved in the value. (#617)
izulin marked this conversation as resolved.
Show resolved Hide resolved
izulin marked this conversation as resolved.
Show resolved Hide resolved

### Added
- Added support for row and column reordering. (#343)
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
"<rootDir>/test/**/*spec.(ts|js)"
],

silent: true,
silent: false,
izulin marked this conversation as resolved.
Show resolved Hide resolved

// A map from regular expressions to paths to transformers
transform: {
Expand Down
4 changes: 1 addition & 3 deletions src/CellContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ export class CellContentParser {
if (parsedDateNumber !== undefined) {
return new CellContent.Number(parsedDateNumber)
} else {
return new CellContent.String(
content.startsWith('\'') ? content.slice(1) : content,
)
return new CellContent.String(content)
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyGraph/AddressMapping/AddressMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export class AddressMapping {
this.addSheet(sheetId, new strategyConstructor(width, height))
}

public getCellValue(address: SimpleCellAddress): InterpreterValue {
public getCellValue(address: SimpleCellAddress, literalValue?: boolean): InterpreterValue {
const vertex = this.getCell(address)

if (vertex === null) {
return EmptyValue
} else if (vertex instanceof MatrixVertex) {
return vertex.getMatrixCellValue(address)
} else {
return vertex.getCellValue()
return vertex.getCellValue(literalValue)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/DependencyGraph/DependencyGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,12 @@ export class DependencyGraph {
return this.addressMapping.getCell(address)
}

public getCellValue(address: SimpleCellAddress): InterpreterValue {
return this.addressMapping.getCellValue(address)
public getCellValue(address: SimpleCellAddress, literalValue?: boolean): InterpreterValue {
return this.addressMapping.getCellValue(address, literalValue)
}

public getScalarValue(address: SimpleCellAddress): InternalScalarValue {
const value = this.addressMapping.getCellValue(address)
public getScalarValue(address: SimpleCellAddress, literalValue?: boolean): InternalScalarValue {
const value = this.addressMapping.getCellValue(address, literalValue)
if (value instanceof SimpleRangeValue) {
return new CellError(ErrorType.VALUE, ErrorMessage.ScalarExpected)
}
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyGraph/ValueCellVertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class ValueCellVertex {
/**
* Returns cell value stored in vertex
*/
public getCellValue(): ValueCellVertexValue {
public getCellValue(literalValue?: boolean): ValueCellVertexValue {
if(!literalValue && typeof this.cellValue === 'string') {
return this.cellValue.startsWith('\'') ? this.cellValue.slice(1) : this.cellValue
}
return this.cellValue
}

Expand Down
6 changes: 3 additions & 3 deletions src/Serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Serialization {
if (formula !== undefined) {
return formula
} else {
const value: CellValue = this.getCellValue(address)
const value: CellValue = this.getCellValue(address, true)
if (value instanceof DetailedCellError) {
return this.config.translationPackage.getErrorTranslation(value.type)
} else {
Expand All @@ -58,8 +58,8 @@ export class Serialization {
}
}

public getCellValue(address: SimpleCellAddress): CellValue {
return this.exporter.exportValue(this.dependencyGraph.getScalarValue(address))
public getCellValue(address: SimpleCellAddress, literalValue?: boolean): CellValue {
return this.exporter.exportValue(this.dependencyGraph.getScalarValue(address, literalValue))
}

public getSheetValues(sheet: number): CellValue[][] {
Expand Down
10 changes: 5 additions & 5 deletions test/CellContentParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ describe('CellContentParser', () => {
})

it( 'starts with \'', () => {
expect(cellContentParser.parse('\'123')).toEqual(new CellContent.String('123'))
expect(cellContentParser.parse('\'=1+1')).toEqual(new CellContent.String('=1+1'))
expect(cellContentParser.parse('\'\'1')).toEqual(new CellContent.String('\'1'))
expect(cellContentParser.parse('\' 1')).toEqual(new CellContent.String(' 1'))
expect(cellContentParser.parse('\'123')).toEqual(new CellContent.String('\'123'))
expect(cellContentParser.parse('\'=1+1')).toEqual(new CellContent.String('\'=1+1'))
expect(cellContentParser.parse('\'\'1')).toEqual(new CellContent.String('\'\'1'))
expect(cellContentParser.parse('\' 1')).toEqual(new CellContent.String('\' 1'))
expect(cellContentParser.parse(' \'1')).toEqual(new CellContent.String(' \'1'))
expect(cellContentParser.parse('\'02-02-2020')).toEqual(new CellContent.String('02-02-2020'))
expect(cellContentParser.parse('\'02-02-2020')).toEqual(new CellContent.String('\'02-02-2020'))
})

it('currency parsing', () => {
Expand Down
10 changes: 10 additions & 0 deletions test/escaping-support.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {HyperFormula} from '../src'
import {adr} from './testUtils'

describe('escaped formulas', () => {
it('should serialize properly', () => {
const engine = HyperFormula.buildFromArray([['\'=SUM(2,2)']])
expect(engine.getCellSerialized(adr('A1'))).toEqual('\'=SUM(2,2)')
expect(engine.getCellValue(adr('A1'))).toEqual('=SUM(2,2)')
})
})