fix: date from integer, #125

This commit is contained in:
harttle
2019-05-12 21:03:35 +08:00
parent bef290923c
commit fdf0043b9c
6 changed files with 42 additions and 4 deletions
+22
View File
@@ -1,6 +1,12 @@
import { test, ctx } from '../../../stub/render'
import { expect } from 'chai'
import Liquid from '../../../../src/liquid'
describe('filters/date', function () {
let liquid: Liquid
beforeEach(function () {
liquid = new Liquid()
})
it('should support date: %a %b %d %Y', function () {
const str = ctx.date.toDateString()
return test('{{ date | date:"%a %b %d %Y"}}', str)
@@ -17,4 +23,20 @@ describe('filters/date', function () {
it('should render object as string if not valid', function () {
return test('{{ obj | date: "%Y"}}', '[object Object]')
})
it('should create from number-like string', async function () {
const src = '{{ "1488859200" | date: "%Y-%m-%dT%H:%M:%S" }}'
const dst = '2017-03-07T12:00:00'
expect(await liquid.parseAndRender(src)).to.equal(dst)
})
it('should create from number', async function () {
const src = '{{ 1488859200 | date: "%Y-%m-%dT%H:%M:%S" }}'
const dst = '2017-03-07T12:00:00'
expect(await liquid.parseAndRender(src)).to.equal(dst)
})
it('should support manipulation', async function () {
const src = '{{ date | date: "%s" | minus : 604800 | date: "%Y-%m-%dT%H:%M:%S"}}'
const ctx = { date: new Date('2017-03-07 12:00:00.000+8:00') }
const dst = '2017-02-28T12:00:00'
expect(await liquid.parseAndRender(src, ctx)).to.equal(dst)
})
})
+8
View File
@@ -18,6 +18,14 @@ describe('util/underscore', function () {
expect(_.isString(123)).to.be.false
})
})
describe('.isNumber()', function () {
it('should return false for "foo"', function () {
expect(_.isNumber('foo')).to.be.false
})
it('should return true for 0', function () {
expect(_.isNumber(0)).to.be.true
})
})
describe('.stringify()', function () {
it('should respect to toLiquid() method', function () {
expect(_.stringify({ toLiquid: () => 'foo' })).to.equal('foo')