This repository was archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.coffee
123 lines (96 loc) · 3.12 KB
/
test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
sink = require 'stream-sink'
isStream = require 'is-stream'
isPromise = require 'is-promise'
s = require './index.js'
module.exports =
'pass': (t) ->
t.expect 2
t.strictEqual s._.pass(), true
t.strictEqual s._.pass('foo'), true
t.done()
'filterById': (t) ->
predicate = s._.filterById 2
t.expect 6
t.strictEqual predicate(), false
t.strictEqual predicate({}), false
t.strictEqual predicate([2]), false
t.strictEqual predicate({id: 1 }), false
t.strictEqual predicate({id: '2'}), false
t.strictEqual predicate({id: 2 }), true
t.done()
'filterByKeys':
'returns false for invalid data': (t) ->
predicate = s._.filterByKeys a: 'foo'
t.expect 3
t.strictEqual predicate(), false
t.strictEqual predicate([2]), false
t.strictEqual predicate({}), false
t.done()
'compares strictly': (t) ->
predicate = s._.filterByKeys a: '1'
t.expect 2
t.strictEqual predicate({a: 1 }), false
t.strictEqual predicate({a: '1'}), true
t.done()
'compares only *own* properties': (t) ->
predicate = s._.filterByKeys a: 'foo'
x = Object.create a: 'foo'
t.expect 1
t.strictEqual predicate(x), false
t.done()
'compares multiple keys': (t) ->
predicate = s._.filterByKeys a: 'foo', b: 'bar'
t.expect 4
t.strictEqual predicate({a: 'bar', b: 'bar'}), false
t.strictEqual predicate({a: 'bar', b: 'foo'}), false
t.strictEqual predicate({a: 'foo', b: 'foo'}), false
t.strictEqual predicate({a: 'foo', b: 'bar'}), true
t.done()
"reader('agencies.ndjson')":
'without `promised` flag':
'returns a stream': (t) ->
read = s._.reader 'agencies.ndjson'
t.ok isStream read 'VBB'
t.done()
'filters correctly': (t) ->
read = s._.reader 'agencies.ndjson'
t.expect 2
sink = read('VBB').pipe sink objectMode: true
sink.on 'data', (data) ->
t.strictEqual data.length, 1
t.strictEqual data[0].id, 'VBB'
t.done()
'with `promised` flag':
'returns a promise': (t) ->
read = s._.reader 'agencies.ndjson'
t.ok isPromise read true, 'VBB'
t.done()
'filters correctly': (t) ->
read = s._.reader 'agencies.ndjson'
t.expect 2
read(true, 'VBB').then (data) ->
t.strictEqual data.length, 1
t.strictEqual data[0].id, 'VBB'
t.done()
'examples from readme':
'agencies': (t) -> s.agencies(true, 'VBB').then (data) ->
t.strictEqual data.length, 1
t.strictEqual data[0].id, 'VBB'
t.strictEqual data[0].name, 'Verkehrsverbund Brandenburg-Berlin'
t.done()
'lines': (t) -> s.lines(true, 246).then (data) ->
t.strictEqual data.length, 1
t.strictEqual data[0].id, 246
t.strictEqual data[0].name, '100'
t.strictEqual data[0].type, 'bus'
t.done()
'stations': (t) -> s.stations(true, 9042101).then (data) ->
t.strictEqual data.length, 1
t.strictEqual data[0].id, 9042101
t.strictEqual data[0].name, 'U Spichernstr. (Berlin)'
t.done()
'trips': (t) -> s.trips(true, 95885).then (data) ->
t.strictEqual data.length, 1
t.strictEqual data[0].id, 95885
t.strictEqual data[0].lineId, 549 # U9
t.done()