1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/test_helpers.coffee

40 lines
746 B
CoffeeScript
Raw Normal View History

{starts, ends, compact, count, merge, extend, flatten, del, last} = CoffeeScript.helpers
2010-09-25 09:15:47 +09:00
array = [0, 1, 2, 3, 4]
2010-09-28 21:52:51 +09:00
string = array.join ''
object = {}
2010-09-25 09:15:47 +09:00
2010-09-26 10:28:48 -04:00
# Test `starts`
2010-09-25 09:15:47 +09:00
ok starts string, '012'
ok starts string, '34', 3
ok not starts string, '42'
ok not starts string, '42', 6
2010-09-26 10:28:48 -04:00
# Test `ends`
2010-09-25 09:15:47 +09:00
ok ends string, '234'
ok ends string, '01', 3
ok not ends string, '42'
ok not ends string, '42', 6
2010-09-26 10:28:48 -04:00
# Test `merge`
2010-09-25 09:15:47 +09:00
merged = merge object, array
ok merged isnt object
2010-09-28 21:52:51 +09:00
eq merged[3], 3
2010-09-25 09:15:47 +09:00
2010-09-26 10:28:48 -04:00
# Test `extend`
2010-09-25 09:15:47 +09:00
ok object is extend object, array
2010-09-28 21:52:51 +09:00
eq object[3], 3
2010-09-25 09:15:47 +09:00
2010-09-26 10:28:48 -04:00
# Test `flatten`
2010-10-21 12:45:50 +09:00
ay = yes
(ay and= typeof n is 'number') for n in flatten [0, [[1], 2], 3, [4]]
ok ay
2010-09-25 09:15:47 +09:00
2010-09-28 21:52:51 +09:00
# Test `del`
eq 1, del object, 1
2010-09-25 09:15:47 +09:00
ok 1 not of object
2010-09-28 21:52:51 +09:00
# Test `last`
eq 4, last array
eq 2, last array, 2