refactor: import rollup

This commit is contained in:
harttle
2018-08-20 23:58:41 +08:00
parent 4ece4e208f
commit bc9d8f92af
82 changed files with 8589 additions and 3963 deletions
+6 -4
View File
@@ -1,8 +1,10 @@
const chai = require('chai')
import chai from 'chai'
import mock from 'mock-fs'
import Liquid from '../../src'
import chaiAsPromised from 'chai-as-promised'
const expect = chai.expect
const mock = require('mock-fs')
const Liquid = require('../../src')
chai.use(require('chai-as-promised'))
chai.use(chaiAsPromised)
describe('cache options', function () {
let engine
+5 -5
View File
@@ -6,7 +6,7 @@ chai.use(require('chai-as-promised'))
describe('strict options', function () {
let engine
let ctx = {}
const ctx = {}
beforeEach(function () {
engine = Liquid({
root: '/root/',
@@ -18,16 +18,16 @@ describe('strict options', function () {
.eventually.equal('beforeafter')
})
it('should throw when strict_variables true', function () {
let tpl = engine.parse('before{{notdefined}}after')
let opts = {
const tpl = engine.parse('before{{notdefined}}after')
const opts = {
strict_variables: true
}
return expect(engine.render(tpl, ctx, opts)).to
.be.rejectedWith(/undefined variable: notdefined/)
})
it('should pass strict_variables to render by parseAndRender', function () {
let html = 'before{{notdefined}}after'
let opts = {
const html = 'before{{notdefined}}after'
const opts = {
strict_variables: true
}
return expect(engine.parseAndRender(html, ctx, opts)).to
+21 -19
View File
@@ -1,62 +1,64 @@
const chai = require('chai')
import chai from 'chai'
import Liquid from '../../src'
import chaiAsPromised from 'chai-as-promised'
const expect = chai.expect
const Liquid = require('../../src')
chai.use(require('chai-as-promised'))
chai.use(chaiAsPromised)
describe('trimming', function () {
let ctx = {name: 'harttle'}
const ctx = {name: 'harttle'}
describe('tag trimming', function () {
it('should respect trim_tag_left', function () {
let engine = Liquid({ trim_tag_left: true })
const engine = Liquid({ trim_tag_left: true })
return expect(engine.parseAndRender(' \n \t{%if true%}foo{%endif%} '))
.to.eventually.equal('foo ')
})
it('should respect trim_tag_right', function () {
let engine = Liquid({ trim_tag_right: true })
const engine = Liquid({ trim_tag_right: true })
return expect(engine.parseAndRender('\t{%if true%}foo{%endif%} \n'))
.to.eventually.equal('\tfoo')
})
it('should not trim value', function () {
let engine = Liquid({ trim_tag_left: true, trim_tag_right: true })
const engine = Liquid({ trim_tag_left: true, trim_tag_right: true })
return expect(engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx))
.to.eventually.equal('a harttle b')
})
})
describe('value trimming', function () {
it('should respect trim_value_left', function () {
let engine = Liquid({ trim_value_left: true })
const engine = Liquid({ trim_value_left: true })
return expect(engine.parseAndRender(' \n \t{{name}} ', ctx))
.to.eventually.equal('harttle ')
})
it('should respect trim_value_right', function () {
let engine = Liquid({ trim_value_right: true })
const engine = Liquid({ trim_value_right: true })
return expect(engine.parseAndRender(' \n \t{{name}} ', ctx))
.to.eventually.equal(' \n \tharttle')
})
it('should respect not trim tag', function () {
let engine = Liquid({ trim_value_left: true, trim_value_right: true })
const engine = Liquid({ trim_value_left: true, trim_value_right: true })
return expect(engine.parseAndRender('\t{% if true %} aha {%endif%}\t'))
.to.eventually.equal('\t aha \t')
})
})
describe('greedy', function () {
let src = '\n {%-if true-%}\n a \n{{-name-}}{%-endif-%}\n '
const src = '\n {%-if true-%}\n a \n{{-name-}}{%-endif-%}\n '
it('should enable greedy by default', function () {
let engine = Liquid()
const engine = Liquid()
return expect(engine.parseAndRender(src, ctx))
.to.eventually.equal('aharttle')
})
it('should respect to greedy:false by default', function () {
let engine = Liquid({greedy: false})
const engine = Liquid({greedy: false})
return expect(engine.parseAndRender(src, ctx))
.to.eventually.equal('\n a \nharttle ')
})
})
describe('markup', function () {
it('should support trim using markup', function () {
let engine = Liquid()
let src = [
const engine = Liquid()
const src = [
'{%- assign username = "John G. Chalmers-Smith" -%}',
'{%- if username and username.length > 10 -%}',
' Wow, {{ username }}, you have a long name!',
@@ -64,12 +66,12 @@ describe('trimming', function () {
' Hello there!',
'{%- endif -%}'
].join('\n')
let dst = 'Wow, John G. Chalmers-Smith, you have a long name!'
const dst = 'Wow, John G. Chalmers-Smith, you have a long name!'
return expect(engine.parseAndRender(src)).to.eventually.equal(dst)
})
it('should not trim when not specified', function () {
let engine = Liquid()
let src = [
const engine = Liquid()
const src = [
'{% assign username = "John G. Chalmers-Smith" %}',
'{% if username and username.length > 10 %}',
' Wow, {{ username }}, you have a long name!',
@@ -77,7 +79,7 @@ describe('trimming', function () {
' Hello there!',
'{% endif %}'
].join('\n')
let dst = '\n\n Wow, John G. Chalmers-Smith, you have a long name!\n'
const dst = '\n\n Wow, John G. Chalmers-Smith, you have a long name!\n'
return expect(engine.parseAndRender(src)).to.eventually.equal(dst)
})
})