forked from protofire/solhint
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontract-name-camelcase.js
More file actions
131 lines (104 loc) · 3.84 KB
/
contract-name-camelcase.js
File metadata and controls
131 lines (104 loc) · 3.84 KB
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
122
123
124
125
126
127
128
129
130
131
const assert = require('assert')
const linter = require('../../../lib/index')
const contractWith = require('../../common/contract-builder').contractWith
describe('Linter - contract-name-camelcase', () => {
describe('in structs', () => {
it('should raise contract name error', () => {
const code = contractWith('struct a {}')
const report = linter.processStr(code, {
rules: { 'contract-name-camelcase': 'error' },
})
assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('CamelCase'))
})
it('should not raise contract name error', () => {
const code = contractWith('struct MyStruct {}')
const report = linter.processStr(code, {
rules: { 'contract-name-camelcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
describe('with $ character', () => {
const WITH_$ = {
$: contractWith('struct $ {}'),
'starting with $': contractWith('struct $MyStruct {}'),
'containing a $': contractWith('struct My$Struct {}'),
'ending with $': contractWith('struct MyStruct$ {}'),
}
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-camelcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
})
describe('in contracts', () => {
it('should raise contract name error', () => {
const code = 'contract a {}'
const report = linter.processStr(code, {
rules: { 'contract-name-camelcase': 'error' },
})
assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('CamelCase'))
})
it('should not raise contract name error', () => {
const code = 'contract MyContract {}'
const report = linter.processStr(code, {
rules: { 'contract-name-camelcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
describe('with $ character', () => {
const WITH_$ = {
$: 'contract $ {}',
'starting with $': 'contract $MyContract {}',
'containing a $': 'contract My$Contract {}',
'ending with $': 'contract MyContract$ {}',
}
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-camelcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
})
describe('in enums', () => {
it('should raise contract name error', () => {
const code = contractWith('enum abc {}')
const report = linter.processStr(code, {
rules: { 'contract-name-camelcase': 'error' },
})
assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('CamelCase'))
})
it('should not raise contract name error', () => {
const code = contractWith('enum MyEnum {}')
const report = linter.processStr(code, {
rules: { 'contract-name-camelcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
describe('with $ character', () => {
const WITH_$ = {
$: contractWith('enum $ {}'),
'starting with $': contractWith('enum $MyEnum {}'),
'containing a $': contractWith('enum My$Enum {}'),
'ending with $': contractWith('enum MyEnum$ {}'),
}
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-camelcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
})
})