]>
Commit | Line | Data |
---|---|---|
d21cd6c1 SR |
1 | // requires local modules: util |
2 | /* jshint expr: true */ | |
3 | ||
4 | var assert = chai.assert; | |
5 | var expect = chai.expect; | |
6 | ||
7 | describe('Utils', function() { | |
8 | "use strict"; | |
9 | ||
10 | describe('Array instance methods', function () { | |
11 | describe('push8', function () { | |
12 | it('should push a byte on to the array', function () { | |
13 | var arr = [1]; | |
14 | arr.push8(128); | |
15 | expect(arr).to.deep.equal([1, 128]); | |
16 | }); | |
17 | ||
18 | it('should only use the least significant byte of any number passed in', function () { | |
19 | var arr = [1]; | |
20 | arr.push8(0xABCD); | |
21 | expect(arr).to.deep.equal([1, 0xCD]); | |
22 | }); | |
23 | }); | |
24 | ||
25 | describe('push16', function () { | |
26 | it('should push two bytes on to the array', function () { | |
27 | var arr = [1]; | |
28 | arr.push16(0xABCD); | |
29 | expect(arr).to.deep.equal([1, 0xAB, 0xCD]); | |
30 | }); | |
31 | ||
32 | it('should only use the two least significant bytes of any number passed in', function () { | |
33 | var arr = [1]; | |
34 | arr.push16(0xABCDEF); | |
35 | expect(arr).to.deep.equal([1, 0xCD, 0xEF]); | |
36 | }); | |
37 | }); | |
38 | ||
39 | describe('push32', function () { | |
40 | it('should push four bytes on to the array', function () { | |
41 | var arr = [1]; | |
42 | arr.push32(0xABCDEF12); | |
43 | expect(arr).to.deep.equal([1, 0xAB, 0xCD, 0xEF, 0x12]); | |
44 | }); | |
45 | ||
46 | it('should only use the four least significant bytes of any number passed in', function () { | |
47 | var arr = [1]; | |
48 | arr.push32(0xABCDEF1234); | |
49 | expect(arr).to.deep.equal([1, 0xCD, 0xEF, 0x12, 0x34]); | |
50 | }); | |
51 | }); | |
52 | }); | |
53 | ||
54 | describe('logging functions', function () { | |
55 | beforeEach(function () { | |
56 | sinon.spy(console, 'log'); | |
57 | sinon.spy(console, 'warn'); | |
58 | sinon.spy(console, 'error'); | |
59 | }); | |
60 | ||
61 | afterEach(function () { | |
62 | console.log.restore(); | |
63 | console.warn.restore(); | |
64 | console.error.restore(); | |
65 | }); | |
66 | ||
67 | it('should use noop for levels lower than the min level', function () { | |
68 | Util.init_logging('warn'); | |
69 | Util.Debug('hi'); | |
70 | Util.Info('hello'); | |
71 | expect(console.log).to.not.have.been.called; | |
72 | }); | |
73 | ||
74 | it('should use console.log for Debug and Info', function () { | |
75 | Util.init_logging('debug'); | |
76 | Util.Debug('dbg'); | |
77 | Util.Info('inf'); | |
78 | expect(console.log).to.have.been.calledWith('dbg'); | |
79 | expect(console.log).to.have.been.calledWith('inf'); | |
80 | }); | |
81 | ||
82 | it('should use console.warn for Warn', function () { | |
83 | Util.init_logging('warn'); | |
84 | Util.Warn('wrn'); | |
85 | expect(console.warn).to.have.been.called; | |
86 | expect(console.warn).to.have.been.calledWith('wrn'); | |
87 | }); | |
88 | ||
89 | it('should use console.error for Error', function () { | |
90 | Util.init_logging('error'); | |
91 | Util.Error('err'); | |
92 | expect(console.error).to.have.been.called; | |
93 | expect(console.error).to.have.been.calledWith('err'); | |
94 | }); | |
95 | }); | |
96 | ||
97 | // TODO(directxman12): test the conf_default and conf_defaults methods | |
98 | // TODO(directxman12): test decodeUTF8 | |
99 | // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent) | |
100 | // TODO(directxman12): figure out a good way to test getPosition and getEventPosition | |
101 | // TODO(directxman12): figure out how to test the browser detection functions properly | |
102 | // (we can't really test them against the browsers, except for Gecko | |
103 | // via PhantomJS, the default test driver) | |
104 | // TODO(directxman12): figure out how to test Util.Flash | |
105 | }); |