UNPKG

1.26 kBJavaScriptView Raw
1const assert = require('assert')
2
3const applyFixes = require('../../lib/apply-fixes')
4
5describe('applyFixes', () => {
6 it('should work when there are no reports', () => {
7 const inputSrc = 'contract Foo {}'
8 const fixes = []
9
10 const { fixed } = applyFixes(fixes, inputSrc)
11
12 assert.equal(fixed, false)
13 })
14
15 it('should work for a single replace', () => {
16 const inputSrc = `
17contract Foo {
18 function foo() {
19 throw;
20 }
21}`.trim()
22
23 const fixes = [
24 {
25 range: [38, 42],
26 text: 'revert()'
27 }
28 ]
29
30 const { fixed, output } = applyFixes(fixes, inputSrc)
31
32 assert.equal(fixed, true)
33 assert.equal(
34 output,
35 `
36contract Foo {
37 function foo() {
38 revert();
39 }
40}`.trim()
41 )
42 })
43
44 it('should work for two fixes', () => {
45 const inputSrc = `
46contract Foo {
47 function foo() {
48 throw;
49 throw;
50 }
51}`.trim()
52
53 const fixes = [
54 {
55 range: [38, 42],
56 text: 'revert()'
57 },
58 {
59 range: [49, 53],
60 text: 'revert()'
61 }
62 ]
63
64 const { fixed, output } = applyFixes(fixes, inputSrc)
65
66 assert.equal(fixed, true)
67 assert.equal(
68 output,
69 `
70contract Foo {
71 function foo() {
72 revert();
73 revert();
74 }
75}`.trim()
76 )
77 })
78})