-
Notifications
You must be signed in to change notification settings - Fork 106
/
boolean-operators.spec.ts
75 lines (54 loc) · 2.62 KB
/
boolean-operators.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {simpleCellAddress} from '../../src/Cell'
import {Config} from '../../src/Config'
import {SheetMapping} from '../../src/DependencyGraph'
import {buildTranslationPackage, enGB} from '../../src/i18n'
import {
AstNodeType,
EqualsOpAst,
GreaterThanOpAst,
GreaterThanOrEqualOpAst,
LessThanOpAst,
LessThanOrEqualOpAst,
NotEqualOpAst,
ParserWithCaching,
} from '../../src/parser'
import '../testConfig'
describe('Parser - Boolean operators', () => {
it('Equals operator', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1=2', simpleCellAddress(0, 0, 0)).ast as EqualsOpAst
expect(ast.type).toBe(AstNodeType.EQUALS_OP)
})
it('Not equal operator', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1<>2', simpleCellAddress(0, 0, 0)).ast as NotEqualOpAst
expect(ast.type).toBe(AstNodeType.NOT_EQUAL_OP)
})
it('Greater than operator', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1>2', simpleCellAddress(0, 0, 0)).ast as GreaterThanOpAst
expect(ast.type).toBe(AstNodeType.GREATER_THAN_OP)
})
it('Less than operator', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1<2', simpleCellAddress(0, 0, 0)).ast as LessThanOpAst
expect(ast.type).toBe(AstNodeType.LESS_THAN_OP)
})
it('Greater than or equal operator', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1>=2', simpleCellAddress(0, 0, 0)).ast as GreaterThanOrEqualOpAst
expect(ast.type).toBe(AstNodeType.GREATER_THAN_OR_EQUAL_OP)
})
it('Less than or equal operator', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1<=2', simpleCellAddress(0, 0, 0)).ast as LessThanOrEqualOpAst
expect(ast.type).toBe(AstNodeType.LESS_THAN_OR_EQUAL_OP)
})
it('Boolean operator with more complex childs', () => {
const parser = new ParserWithCaching(new Config(), new SheetMapping(buildTranslationPackage(enGB)).get)
const ast = parser.parse('=1+2=1+2*6', simpleCellAddress(0, 0, 0)).ast as EqualsOpAst
expect(ast.type).toBe(AstNodeType.EQUALS_OP)
expect(ast.left.type).toBe(AstNodeType.PLUS_OP)
expect(ast.right.type).toBe(AstNodeType.PLUS_OP)
})
})