forked from ricobank/apes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
121 lines (93 loc) · 2.83 KB
/
test.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const it = require('tapzero').test
const parseError = new RegExp('^could not parse$')
const { show, parse } = require('./apes.js')
// Testing valid Lvalues
it('parseBasicValid', t=>{
t.ok(parse('x = weth.balance()'))
})
it('parseTypedLvalueArraySingle', t => {
t.ok(parse('[uint x] = weth.balance()'))
})
it('parseTypedLvalueArraySingleInt', t => {
t.ok(parse('[int x] = weth.balance()'))
})
it('parseTypedLvalueArrayMultiple', t => {
t.ok(parse('[uint x,bytes32 y] = weth.balance()'))
})
it('parseTypedLvalueArrayMultipleInt', t => {
t.ok(parse('[int x,int y] = weth.balance()'))
})
it('parseTyepdLvalueArrayMultipleOddSpacing', t => {
t.ok(parse('[uint x ,bytes32 y]= weth.balance()'))
})
it('parseTyepdLvalueArrayMultipleAllSpacing', t => {
t.ok(parse('[ uint x , bytes32 y ] = weth.balance( ) '))
})
it('parseTypedLValueNoArrayAddress', t => {
t.ok(parse('address x = weth.balance()'))
})
it('parseTypedLValueNoArrayBool', t => {
t.ok(parse('bool x = weth.balance()'))
})
it('parseTypedLValueNoArrayInt', t => {
t.ok(parse('int x = weth.balance()'))
})
it('parseTypedLValueNoArrayUint', t => {
t.ok(parse('uint x = weth.balance()'))
})
it('parseTypedLValueNoArrayBytes32', t=> {
t.ok(parse('bytes32 x = weth.balance()'))
})
it('parseTypedLValueNoArrayFixed', t => {
t.ok(parse('fixed x = weth.balance()'))
})
it('parseTypedLValueNoArrayUfixed', t => {
t.ok(parse('ufixed x = weth.balance()'))
})
it('parseTypedLValueNoArrayFunction', t => {
t.ok(parse('function x = weth.balance()'))
})
/// Testing Invalid Lvalues
it('parseInvalidNullLvalue', t => {
t.throws( _ => {parse('=weth.balance()')}, parseError)
})
it('parseInvalidLEmptyLvalue', t => {
t.throws( _ => {parse(' =weth.balance()')})
})
it('parseInvalidDecnumLvalue', t => {
t.throws(_ => {parse("32=weth.balance()")}, parseError)
})
it('parseInvalidLValueArrayMultipleNoCommas', t => {
t.throws(_ => {
parse('[uint x uint y] = weth.balance()')
}, parseError)
})
it('parseInvalidLValueArrayMultipleExtraCommans', t => {
t.throws(_ => {
parse('[uint x,uint y,] = weth.balance()')
}, parseError)
})
it('parseInvalidTypedLvalue', t => {
t.throws(_ => {parse('badtype x = weth.balance()')}, parseError)
})
it('parseInvalidTypedLValueMultipleTyes', t => {
t.throws(_ => {parse('uint bytes32 x = weth.balance()')})
})
it('parseInvalidTypedLvalueArray', t => {
t.throws(_ => {
parse('[uint x, badtype y] = weth.balance()')
}, parseError)
})
// Test Valid Rvalues
it('parseValidRvalue', t => {
t.ok(parse('x = weth.balanceOf(uint 123)'))
})
it('parseValidTypedRvalueInt', t => {
t.ok(parse('x = weth.balanceOf(int 123)'))
})
// Test Invalid Rvalues
it('parseInvalidRvalueNoType', t => {
t.throws( _ => {
parse('x = weth.balanaceOf(123)')
}, parseError)
})