-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathconstructor-syntax.js
70 lines (64 loc) · 2.42 KB
/
constructor-syntax.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
const assert = require('assert')
const linter = require('../../../lib/index')
const { multiLine } = require('../../common/contract-builder')
const { assertErrorMessage } = require('../../common/asserts')
const BaseDeprecation = require('../../../lib/rules/deprecations/base-deprecation')
describe('Linter - constructor-syntax', () => {
it('should raise a warning for old-style constructors', () => {
const code = multiLine(
' ', // 1
'pragma solidity 0.4.22; ', // 2
'contract A { ', // 3
' function A() public {} ', // 4
'} ' // 5
)
const report = linter.processStr(code, {
rules: { 'constructor-syntax': 'warn' },
})
assert.equal(report.warningCount, 1)
assertErrorMessage(report, 0, 'constructor keyword')
})
it('should NOT raise a warning for old-style constructors in old versions', () => {
const code = multiLine(
' ', // 1
'pragma solidity 0.4.21; ', // 2
'contract A { ', // 3
' function A() public {} ', // 4
'} ' // 5
)
const report = linter.processStr(code, {
rules: { 'constructor-syntax': 'warn' },
})
assert.equal(report.warningCount, 0)
})
it('should NOT raise a warning for new-style constructors', () => {
const code = multiLine(
' ', // 1
'pragma solidity 0.4.22; ', // 2
'contract A { ', // 3
' constructor() public {} ', // 4
'} ' // 5
)
const report = linter.processStr(code, {
rules: { 'constructor-syntax': 'warn' },
})
assert.equal(report.warningCount, 0)
})
it('should raise an error for new-style constructors in old versions', () => {
const code = multiLine(
' ', // 1
'pragma solidity 0.4.21; ', // 2
'contract A { ', // 3
' constructor() public {} ', // 4
'} ' // 5
)
const report = linter.processStr(code, {
rules: { 'constructor-syntax': 'error' },
})
assert.equal(report.errorCount, 1)
assertErrorMessage(report, 0, 'Constructor keyword')
})
it('should fail without deprecationVersion() implemented', () => {
assert.throws(() => new BaseDeprecation())
})
})