4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
8 (function (module, io, should) {
12 'parse uri': function () {
13 var http = io.util.parseUri('http://google.com')
14 , https = io.util.parseUri('https://www.google.com:80')
15 , query = io.util.parseUri('google.com:8080/foo/bar?foo=bar');
17 http.protocol.should().eql('http');
18 http.port.should().eql('');
19 http.host.should().eql('google.com');
20 https.protocol.should().eql('https');
21 https.port.should().eql('80');
22 https.host.should().eql('www.google.com');
23 query.port.should().eql('8080');
24 query.query.should().eql('foo=bar');
25 query.path.should().eql('/foo/bar');
26 query.relative.should().eql('/foo/bar?foo=bar');
29 'unique uri': function () {
30 var protocol = io.util.parseUri('http://google.com')
31 , noprotocol = io.util.parseUri('google.com')
32 , https = io.util.parseUri('https://google.com')
33 , path = io.util.parseUri('https://google.com/google.com/com/?foo=bar');
35 if ('object' == typeof window) {
36 io.util.uniqueUri(protocol).should().eql('http://google.com:3000');
37 io.util.uniqueUri(noprotocol).should().eql('http://google.com:3000');
39 io.util.uniqueUri(protocol).should().eql('http://google.com:80');
40 io.util.uniqueUri(noprotocol).should().eql('http://google.com:80');
43 io.util.uniqueUri(https).should().eql('https://google.com:443');
44 io.util.uniqueUri(path).should().eql('https://google.com:443');
47 'chunk query string': function () {
48 io.util.chunkQuery('foo=bar').should().be.a('object');
49 io.util.chunkQuery('foo=bar').foo.should().eql('bar');
52 'merge query strings': function () {
53 var base = io.util.query('foo=bar', 'foo=baz')
54 , add = io.util.query('foo=bar', 'bar=foo')
56 base.should().eql('?foo=baz');
57 add.should().eql('?foo=bar&bar=foo');
59 io.util.query('','').should().eql('');
60 io.util.query('foo=bar', '').should().eql('?foo=bar');
61 io.util.query('', 'foo=bar').should().eql('?foo=bar');
64 'request': function () {
65 var type = typeof io.util.request();
66 type.should().eql('object');
69 'is array': function () {
70 io.util.isArray([]).should().be_true;
71 io.util.isArray({}).should().be_false;
72 io.util.isArray('str').should().be_false;
73 io.util.isArray(new Date).should().be_false;
74 io.util.isArray(true).should().be_false;
75 io.util.isArray(arguments).should().be_false;
78 'merge, deep merge': function () {
102 // same structure, but changed names
117 io.util.merge(start, duplicate);
119 start.foo.should().eql('foo');
120 start.bar.should().eql('bar');
122 io.util.merge(start, extra);
123 start.ping.should().eql('pong');
124 start.foo.should().eql('foo');
126 io.util.merge(deep, deeper);
128 deep.foo.should().eql('bar');
129 deep.level1.foo.should().eql('baz');
130 deep.level1.level2.foo.should().eql('foo');
131 deep.level1.level2.level3.foo.should().eql('pewpew');
134 'defer': function (next) {
137 io.util.defer(function () {
138 ((new Date - now) >= ( io.util.webkit ? 100 : 0 )).should().be_true();
143 'indexOf': function () {
144 var data = ['socket', 2, 3, 4, 'socket', 5, 6, 7, 'io'];
145 io.util.indexOf(data, 'socket', 1).should().eql(4);
146 io.util.indexOf(data, 'socket').should().eql(0);
147 io.util.indexOf(data, 'waffles').should().eql(-1);
153 'undefined' == typeof module ? module = {} : module
154 , 'undefined' == typeof io ? require('socket.io-client') : io
155 , 'undefined' == typeof should ? require('should') : should