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