/
operator-percent.spec.ts
61 lines (49 loc) · 1.53 KB
/
operator-percent.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {HyperFormula} from '../../src'
import {CellError, ErrorType} from '../../src/Cell'
import {adr} from '../testUtils'
import '../testConfig'
describe("Percent operator", () => {
it('works for obvious case', () => {
const engine = HyperFormula.buildFromArray([
['=3%'],
])
expect(engine.getCellValue(adr('A1'))).toBe(0.03)
})
it('use number coerce', () => {
const engine = HyperFormula.buildFromArray([
['="3"%'],
['="foobar"%'],
['=TRUE()%'],
])
expect(engine.getCellValue(adr('A1'))).toBe(0.03)
expect(engine.getCellValue(adr('A2'))).toEqual(new CellError(ErrorType.VALUE))
expect(engine.getCellValue(adr('A3'))).toEqual(0.01)
})
it('pass reference', () => {
const engine = HyperFormula.buildFromArray([
['=A2%'],
['=42']
])
expect(engine.getCellValue(adr('A1'))).toEqual(0.42)
})
it('pass error', () => {
const engine = HyperFormula.buildFromArray([
['=A2%'],
['=FOOBAR()']
])
expect(engine.getCellValue(adr('A1'))).toEqual(new CellError(ErrorType.NAME))
})
it('works with other operator and coercion', () => {
const engine = HyperFormula.buildFromArray([['=TRUE()%*1']])
expect(engine.getCellValue(adr('A1'))).toEqual(0.01)
})
// Inconsistency with Product 1
it('range value results in VALUE error', () => {
const engine = HyperFormula.buildFromArray([
['1'],
['9', '=A1:A3%'],
['3'],
])
expect(engine.getCellValue(adr('B2'))).toEqual(new CellError(ErrorType.VALUE))
})
})