-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathcontract-name-capwords.js
95 lines (77 loc) · 2.87 KB
/
contract-name-capwords.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
const assert = require('assert')
const linter = require('../../../lib/index')
const contractWith = require('../../common/contract-builder').contractWith
describe('Linter - contract-name-capwords', () => {
it('should raise struct name error', () => {
const code = contractWith('struct a {}')
const report = linter.processStr(code, {
rules: { 'contract-name-capwords': 'error' },
})
assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('CapWords'))
})
it('should raise contract name error', () => {
const code = 'contract a {}'
const report = linter.processStr(code, {
rules: { 'contract-name-capwords': 'error' },
})
assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('CapWords'))
})
it('should raise enum name error', () => {
const code = contractWith('enum abc {}')
const report = linter.processStr(code, {
rules: { 'contract-name-capwords': 'error' },
})
assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('CapWords'))
})
describe('Struct name with $ character', () => {
const WITH_$ = {
'starting with $': contractWith('struct $MyStruct {}'),
'containing a $': contractWith('struct My$Struct {}'),
'ending with $': contractWith('struct MyStruct$ {}'),
'only with $': contractWith('struct $ {}'),
}
for (const [key, code] of Object.entries(WITH_$)) {
it(`should not raise contract name error for Structs ${key}`, () => {
const report = linter.processStr(code, {
rules: { 'contract-name-capwords': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
describe('Enums name with $ character', () => {
const WITH_$ = {
'starting with $': contractWith('enum $MyEnum {}'),
'containing a $': contractWith('enum My$Enum {}'),
'ending with $': contractWith('enum MyEnum$ {}'),
'only with $': contractWith('enum $ {}'),
}
for (const [key, code] of Object.entries(WITH_$)) {
it(`should not raise contract name error for Enums ${key}`, () => {
const report = linter.processStr(code, {
rules: { 'contract-name-capwords': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
describe('Contract name with $ character', () => {
const WITH_$ = {
'starting with $': 'contract $MyContract {}',
'containing a $': 'contract My$Contract {}',
'ending with $': 'contract MyContract$ {}',
'only with $': 'contract $ {}',
}
for (const [key, code] of Object.entries(WITH_$)) {
it(`should not raise contract name error for Contracts ${key}`, () => {
const report = linter.processStr(code, {
rules: { 'contract-name-capwords': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
})