188c88e8eSopenharmony_civar chai = require('chai')
288c88e8eSopenharmony_civar sinon = require('sinon')
388c88e8eSopenharmony_civar sinonChai = require('sinon-chai')
488c88e8eSopenharmony_civar expect = chai.expect
588c88e8eSopenharmony_cichai.use(sinonChai)
688c88e8eSopenharmony_ci
788c88e8eSopenharmony_civar fixer = require('../lib/fix')
888c88e8eSopenharmony_ci
988c88e8eSopenharmony_cidescribe('fix', function () {
1088c88e8eSopenharmony_ci  it('old fix method: ast hack and re-generate', function () {
1188c88e8eSopenharmony_ci    expect(fixer.formatWhenFix('module.exports = {data: {a: 1}}')).
1288c88e8eSopenharmony_ci      eql('module.exports = {\n    data: function () {\n        return { a: 1 };\n    }\n};')
1388c88e8eSopenharmony_ci    expect(fixer.formatWhenFix('module.exports = {data: function () {return {a: 1}}}')).
1488c88e8eSopenharmony_ci      eql('module.exports = {data: function () {return {a: 1}}}')
1588c88e8eSopenharmony_ci  })
1688c88e8eSopenharmony_ci
1788c88e8eSopenharmony_ci  it('new fix method: loc-based hack', function () {
1888c88e8eSopenharmony_ci    expect(fixer.fix('module.exports = {data: {a: 1}}')).
1988c88e8eSopenharmony_ci      eql('module.exports = {data: function () {return {a: 1}}}')
2088c88e8eSopenharmony_ci    expect(fixer.fix('module.exports = {data: function () {return {a: 1}}}')).
2188c88e8eSopenharmony_ci      eql('module.exports = {data: function () {return {a: 1}}}')
2288c88e8eSopenharmony_ci  })
2388c88e8eSopenharmony_ci
2488c88e8eSopenharmony_ci  it('fix code with multi lines', function () {
2588c88e8eSopenharmony_ci    var result = fixer.fix('module.exports = {\n    data: {a: 1}}')
2688c88e8eSopenharmony_ci    expect(result).eql('module.exports = {\n    data: function () {return {a: 1}}}')
2788c88e8eSopenharmony_ci  })
2888c88e8eSopenharmony_ci
2988c88e8eSopenharmony_ci  it('fix code with other declarations', function () {
3088c88e8eSopenharmony_ci    var result = fixer.fix('require("./b.wx")\n\nvar c = require("./lib/c")\n\nmodule.exports = {\n    data: {\n        text: "hello " + c.name\n    }\n};')
3188c88e8eSopenharmony_ci    expect(result).eql('require("./b.wx")\n\nvar c = require("./lib/c")\n\nmodule.exports = {\n    data: function () {return {\n        text: "hello " + c.name\n    }}\n};')
3288c88e8eSopenharmony_ci  })
3388c88e8eSopenharmony_ci})
34