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

50 lines
936 B
CoffeeScript
Raw Normal View History

{indexOf, include, starts, ends, compact, count, merge, extend, flatten, del, last} = CoffeeScript.helpers
2010-09-25 09:15:47 +09:00
2010-09-28 21:52:51 +09:00
array = [0..4]
string = array.join ''
object = {}
2010-09-25 09:15:47 +09:00
2010-09-28 21:52:51 +09:00
# Test `indexOf`
eq 0, indexOf array, 0
eq 2, indexOf array, 2
eq 4, indexOf array, 4
eq(-1, indexOf array, 6)
2010-09-25 09:15:47 +09:00
2010-09-26 10:28:48 -04:00
# Test `include`
2010-09-25 09:15:47 +09:00
ok include array, 0
ok include array, 2
ok include array, 4
ok not include array, 6
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-09-28 21:52:51 +09:00
eq "#{ flatten [0, [1, 2], 3, [4]] }", "#{ array }"
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