1 | const assert = require('assert')
|
2 | const { assertErrorCount } = require('./common/asserts')
|
3 | const linter = require('./../lib/index')
|
4 |
|
5 | describe('Parse error', () => {
|
6 | it('should report parse errors', () => {
|
7 | const report = linter.processStr('contract Foo {', {})
|
8 |
|
9 | assertErrorCount(report, 1)
|
10 | const error = report.reports[0]
|
11 | assert.equal(error.line, 1)
|
12 | assert.equal(error.column, 14)
|
13 | assert.ok(error.message.startsWith("Parse error: mismatched input '<EOF>'"))
|
14 | })
|
15 |
|
16 | it('should report multiple parse errors', () => {
|
17 | const report = linter.processStr('contract Foo { function constructor() }\n contract Bar {', {})
|
18 |
|
19 | assertErrorCount(report, 3)
|
20 | const messages = report.reports.map(error => error.message)
|
21 | assert.ok(
|
22 | messages[0].startsWith("Parse error: no viable alternative at input 'functionconstructor'")
|
23 | )
|
24 | assert.ok(messages[1].startsWith("Parse error: mismatched input '}'"))
|
25 | assert.ok(messages[2].startsWith("Parse error: mismatched input '<EOF>'"))
|
26 | })
|
27 | })
|