strftime/test/test.js
2011-06-07 18:49:59 -07:00

32 lines
1 KiB
JavaScript

// Based on CoffeeScript by andrewschaaf on github
var assert = require('assert')
, lib = require('./../lib')
// Tue, 07 Jun 2011 18:51:45 GMT
, Time = new Date(1307472705867)
, Tests =
[ { format: '%L', expected: '867' }
, { format: '%Y', expected: '2011' }
, { format: '%m', expected: '06' }
, { format: '%b', expected: 'Jun' }
, { format: '%B', expected: 'June' }
, { format: '%d', expected: null, expectedUTC: '07' }
, { format: '%H', expected: null, expectedUTC: '18' }
, { format: '%M', expected: '51' }
, { format: '%S', expected: '45' }
, { format: '%s', expected: '1307472705' }
]
Tests.forEach(function(t) {
if (t.expected) test('strftime', t.format, t.expected)
test('strftimeUTC', t.format, t.expectedUTC || t.expected)
})
function test(name, format, expected) {
var actual = lib[name](format, Time)
assert.equal(expected, actual, name + '("' + format + '", Time) is ' + JSON.stringify(actual) + ', expected ' + JSON.stringify(expected))
}
console.log('OK')