-
Notifications
You must be signed in to change notification settings - Fork 106
/
error-literals.spec.ts
52 lines (46 loc) · 2.57 KB
/
error-literals.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
import {HyperFormula} from '../../src'
import {ErrorType, simpleCellAddress} from '../../src/Cell'
import {Config} from '../../src/Config'
import {SheetMapping} from '../../src/DependencyGraph'
import {buildTranslationPackage, enGB, plPL} from '../../src/i18n'
import {AstNodeType, ErrorAst, ParserWithCaching, ParsingErrorType} from '../../src/parser'
describe('Parsing error literals', () => {
it('should parse error literals', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=#VALUE!', simpleCellAddress(0, 0, 0)).ast as ErrorAst
expect(ast.type).toBe(AstNodeType.ERROR)
expect(ast.error.type).toEqual(ErrorType.VALUE)
})
it('should parse error literals with ?', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=#NAME?', simpleCellAddress(0, 0, 0)).ast as ErrorAst
expect(ast.type).toBe(AstNodeType.ERROR)
expect(ast.error.type).toEqual(ErrorType.NAME)
})
it('should parse error literals with slashes', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=#N/A', simpleCellAddress(0, 0, 0)).ast as ErrorAst
expect(ast.type).toBe(AstNodeType.ERROR)
expect(ast.error.type).toEqual(ErrorType.NA)
})
it('should parse error in other languages', () => {
HyperFormula.registerLanguage('plPL', plPL)
const parser = new ParserWithCaching(new Config({language: 'plPL'}), new SheetMapping(buildTranslationPackage(plPL)).get)
const ast = parser.parse('=#ARG!', simpleCellAddress(0, 0, 0)).ast as ErrorAst
expect(ast.type).toBe(AstNodeType.ERROR)
expect(ast.error.type).toEqual(ErrorType.VALUE)
})
it('should parse #DIV/0!', () => {
const parser = new ParserWithCaching(new Config({language: 'enGB'}), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=#DIV/0!', simpleCellAddress(0, 0, 0)).ast as ErrorAst
expect(ast.type).toBe(AstNodeType.ERROR)
expect(ast.error.type).toEqual(ErrorType.DIV_BY_ZERO)
})
it('should return parser error', () => {
const parser = new ParserWithCaching(new Config({language: 'enGB'}), new SheetMapping(buildTranslationPackage(enGB)).get)
const { ast, errors } = parser.parse('=#UNKNOWN!', simpleCellAddress(0, 0, 0))
expect(ast.type).toBe(AstNodeType.ERROR)
expect(errors[0].type).toBe(ParsingErrorType.ParserError)
expect(errors[0].message).toBe('Unknown error literal')
})
})