UNPKG

2.96 kBtext/coffeescriptView Raw
1process.env.NODE_ENV = 'test'
2
3path = require 'path'
4assert = require 'assert'
5Tuple = require(path.resolve()).Tuple
6
7describe 'class "Tuple"', ->
8
9 it 'should have class-property "DEFAULT"', ->
10 assert.equal typeof Tuple.DEFAULT, 'object'
11
12 describe 'class-property "DEFAULT"', ->
13
14 it 'should have property "expire"', ->
15 assert.equal typeof Tuple.DEFAULT.expire, 'number'
16 assert.ok Tuple.DEFAULT.expire > 0
17
18 it 'should have class-method "isHash"', ->
19 assert.equal typeof Tuple.isHash, 'function'
20
21 describe 'class-method "isHash"', ->
22
23 it 'should return true if Hash', ->
24 assert.equal Tuple.isHash({a:1, b:2}), true
25
26 it 'should return false if String', ->
27 assert.equal Tuple.isHash("foo"), false
28
29 it 'should return false if Number', ->
30 assert.equal Tuple.isHash(58), false
31
32 it 'should return false if Array', ->
33 assert.equal Tuple.isHash([1,2,3]), false
34
35 it 'should return false if null', ->
36 assert.equal Tuple.isHash(null), false
37
38
39describe 'instance of Tuple {a:1, b:2}', ->
40
41 tuple = new Tuple(a:1, b:2)
42
43 it 'should have property "expire_at"', ->
44 assert.ok tuple.hasOwnProperty('expire_at')
45
46 it 'should have property "data"', ->
47 assert.ok tuple.hasOwnProperty('data')
48 assert.ok tuple.expire_at > new Date()/1000
49
50 it 'should match {a: 1, b: 2}', ->
51 assert.equal tuple.match({a:1, b:2}), true
52
53 it 'should match {a: 1, b: 2, c: 3}', ->
54 assert.equal tuple.match({a:1, b:2, c:3}), true
55
56 it 'should not match {a: 1, b: 3}', ->
57 assert.equal tuple.match({a:1, b:3}), false
58
59 it 'should not match {a: 1}', ->
60 assert.equal tuple.match({a:1}), false
61
62 it 'should not match [1,2,3]', ->
63 assert.equal tuple.match([1,2,3]), false
64
65 it 'should not match "foobar"', ->
66 assert.equal tuple.match("foobar"), false
67
68 it 'should match new Tuple({a:1, b:2, c:3})', ->
69 assert.equal tuple.match(new Tuple({a:1, b:2, c:3})), true
70
71 it 'should not match new Tuple({a:1, b:"foo"})', ->
72 assert.equal tuple.match(new Tuple({a:1, b:"foo"})), false
73
74describe 'instance of Tuple {arr: [1,2,3]}', ->
75
76 tuple = new Tuple(arr: [1,2,3])
77
78 it 'should match {foo: "bar", arr: [1,2,3]}', ->
79 assert.ok tuple.match {foo: "bar", arr: [1,2,3]}
80
81 it 'should not match {foo: "bar", arr: [1,2,4]}', ->
82 assert.equal tuple.match({foo: "bar", arr: [1,2,4]}), false
83
84
85describe 'instance of Tuple
86 {user: {name: "shokai", url: "http://shokai.org"}}', ->
87
88 tuple = new Tuple({user: {name: "shokai", url: "http://shokai.org"}})
89
90 it 'should match
91 {user: {name: "shokai", url: "http://shokai.org"}, foo: "bar"}', ->
92 assert.ok tuple.match({
93 user: {name: "shokai", url: "http://shokai.org"},
94 foo: "bar"})
95
96 it 'should not match
97 {user: {name: "shokai", url: "https://shokai.github.com"}, foo: "bar"}', ->
98 assert.equal tuple.match({
99 user: {name: "shokai", url: "https://shokai.github.com"},
100 foo: "bar"})
101 , false