mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
s/coffee/java/g
This commit is contained in:
parent
565021eb94
commit
607d1f075a
2 changed files with 32 additions and 39 deletions
|
|
@ -1,39 +0,0 @@
|
|||
|
||||
assert = require 'assert'
|
||||
|
||||
lib = require './../lib'
|
||||
|
||||
|
||||
# Tue, 07 Jun 2011 18:51:45 GMT
|
||||
t = new Date 1307472705867
|
||||
|
||||
|
||||
TESTS = [
|
||||
|
||||
["%L", "867"]
|
||||
|
||||
["%Y", "2011"]
|
||||
|
||||
["%m", "06"]
|
||||
["%b", "Jun"]
|
||||
["%B", "June"]
|
||||
|
||||
["%d", null, "07"]
|
||||
|
||||
["%H", null, "18"]
|
||||
|
||||
["%M", "51"]
|
||||
|
||||
["%S", "45"]
|
||||
|
||||
["%s", "1307472705"]
|
||||
]
|
||||
|
||||
for [format, expectedNonUTC, expectedUTC] in TESTS
|
||||
expectedUTC or= expectedNonUTC
|
||||
for [name, expected] in [['strftime', expectedNonUTC], ['strftimeUTC', expectedUTC]]
|
||||
if expected
|
||||
got = lib[name] format, t
|
||||
assert.equal expected, got, "Error for #{name}(#{JSON.stringify(format)}, t): expected #{JSON.stringify(expected)}, got #{JSON.stringify(got)}"
|
||||
|
||||
console.log "OK"
|
||||
32
test/test.js
Normal file
32
test/test.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// 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')
|
||||
Loading…
Reference in a new issue