UNPKG

3.54 kBtext/coffeescriptView Raw
1require '../lib/main'
2require 'colors'
3
4test = (name, str) ->
5 if !Object.isString(str)
6 str = JSON.stringify str
7 console.log ('.' + name + ':').magenta, str.green
8
9# Begin Array Tests
10friends = ['bob', 'jill', 10, 'Jill', 'tom', 'mark', undefined, null, 'jill']
11friends.push ['dbags', ['tony', 'rigatoni']]
12friends.push 'whats-her-face'
13console.log 'Starting Protege Array tests'.red
14test 'Starting Object', friends
15test 'typeof', typeof friends
16
17test 'size()', friends.size()
18test 'first()', friends.first()
19test 'last()', friends.last()
20
21test 'clone()', friends.clone()
22test 'clear()', friends.clone().clear()
23test 'compact()', friends.compact()
24test 'flatten()', friends.flatten()
25
26test 'remove("jill")', friends.clone().remove('jill')
27test 'removeAll("jill")', friends.clone().removeAll('jill')
28test 'removeAllIgnoreCase("jill")', friends.clone().removeAllIgnoreCase('jill')
29test 'removeIndex(0)', friends.clone().removeIndex(0)
30
31test 'merge()', friends.clone().merge(friends)
32test 'unique()', friends.unique()
33test 'intersect(["jill"])', friends.clone().intersect(['jill'])
34
35# Begin Object Tests
36contacts = {douchebag: 'tony', bros: ['thomas', 'bob'], hos: ['jill', 'stephanie'], family: {dad: 'mike', mom: 'tiffany', sister: 'jill'}, "tool": 'tony'}
37console.log 'Starting Protege Object tests'.red
38test 'Starting Object', contacts
39test 'typeof', typeof contacts
40
41test 'isArray()', [typeof [], Object.isArray([])]
42test 'isBoolean()', [typeof true, Object.isBoolean(true)]
43test 'isNumber()', [typeof 0, Object.isNumber(0)]
44test 'isString()', [typeof '', Object.isString('')]
45test 'isFunction()', [typeof test, Object.isFunction(test)]
46test 'isObject()', [typeof contacts, Object.isObject(contacts)]
47
48test 'isEmpty()', [[], Object.isEmpty([])]
49test 'isEmpty()', ['', Object.isEmpty('')]
50test 'isEmpty()', [{}, Object.isEmpty({})]
51
52test 'clone()', contacts.clone()
53test 'keys()', contacts.keys()
54test 'values()', contacts.values()
55
56test 'getKeys("tony")', contacts.getKeys('tony')
57test 'getValues("tool")', contacts.getValues('tool')
58test 'getKey()', contacts.getKey()
59test 'getValue()', contacts.getValue()
60
61test 'concat({rapper: "pdizzy"})', contacts.concat({rapper: 'pdizzy'})
62test 'merge({douchebag: "mike"})', contacts.merge({douchebag: "mike"})
63test 'unique()', contacts.unique()
64test 'unique(true)', contacts.unique(true)
65test 'remove("family")', contacts.remove('family')
66
67buddy = 'Frank'
68console.log 'Starting Protege String tests'.red
69test 'Starting Object', buddy
70test 'typeof', typeof buddy
71test 'upcase()', buddy.upcase()
72test 'downcase()', buddy.downcase()
73
74test 'startsWith("F")', buddy.startsWith('F')
75test 'startsWithIgnoreCase("f")', buddy.startsWithIgnoreCase('f')
76test 'endsWith("k")', buddy.endsWith('k')
77test 'endsWithIgnoreCase("K")', buddy.endsWithIgnoreCase('K')
78
79test 'contains("rank")', buddy.contains('rank')
80test 'containsIgnoreCase("f")', buddy.containsIgnoreCase('f')
81test 'equalsIgnoreCase("frank")', buddy.equalsIgnoreCase('frank')
82
83console.log 'Starting Protege JSON tests'.red
84test 'Starting Object', contacts
85test 'typeof', typeof contacts
86test 'prettify()', contacts.prettify()
87test 'stringify()', contacts.stringify()
88
89console.log 'Starting Protege Function tests'.red
90
91myFunc = (argz) ->
92 console.log argz
93 return 15
94cacheFunc = myFunc.memoize()
95
96console.log myFunc
97test 'Starting Function', {}
98test 'typeof', typeof myFunc
99test 'cacheFunc(10)', cacheFunc 10
100test 'cacheFunc(11)', cacheFunc 11
101test 'cacheFunc(10)', cacheFunc 10
102delay 5000, -> console.log 9001