|
1 |
| -'use strict'; |
2 |
| - |
3 | 1 | import test from 'ava';
|
4 |
| -import app from '../app.js'; |
5 |
| - |
6 |
| -test('Loads credentials', t => { |
7 |
| - const credentials = app.credentials; |
8 |
| - const properties = [ |
9 |
| - 'CLIENT_ID', |
10 |
| - 'CLIENT_SECRET', |
11 |
| - 'REDDIT_USER', |
12 |
| - 'REDDIT_PASS' |
13 |
| - ]; |
14 |
| - |
15 |
| - for (let propertyName of properties) { |
16 |
| - t.truthy(credentials[propertyName]); |
17 |
| - t.is(typeof credentials[propertyName], 'string'); |
18 |
| - } |
19 |
| -}); |
20 |
| - |
21 |
| -test('Creates a Snoostrom client', t => { |
22 |
| - t.true(app.client instanceof require('snoostorm')); |
23 |
| -}); |
24 |
| - |
25 |
| -test('Creates a valid comment stream', t => { |
26 |
| - t.true(app.comments instanceof require('events')); |
27 |
| - t.true('comment' in app.comments._events); |
28 |
| -}); |
| 2 | +import decode from '../util/decode'; |
29 | 3 |
|
30 | 4 | test('Decodes delimited strings', t => {
|
31 |
| - t.is(app.decode('01110000 01100001 01110011 01110011'), 'pass'); |
| 5 | + t.is(decode('01110000 01100001 01110011 01110011'), 'pass'); |
32 | 6 | });
|
33 | 7 |
|
34 | 8 | test('Decodes non-delimited strings', t => {
|
35 |
| - t.is(app.decode('01110000011000010111001101110011'), 'pass'); |
| 9 | + t.is(decode('01110000011000010111001101110011'), 'pass'); |
36 | 10 | });
|
37 | 11 |
|
38 | 12 | test('Decodes strings with whitespace padding', t => {
|
39 |
| - t.is(app.decode('\t01110000 01100001 01110011 01110011 \n'), 'pass'); |
| 13 | + t.is(decode('\t01110000 01100001 01110011 01110011 \n'), 'pass'); |
40 | 14 | });
|
41 | 15 |
|
42 | 16 | test('Decodes binary on separate line', t => {
|
43 |
| - t.is(app.decode('text \n01110000 01100001 01110011 01110011'), 'pass'); |
| 17 | + t.is(decode('text \n01110000 01100001 01110011 01110011'), 'pass'); |
44 | 18 | });
|
45 | 19 |
|
46 | 20 | test('Decodes UTF-8', t => {
|
47 |
| - t.is(app.decode('00100100 11000010 10100010 11100010 10000010 10101100 11110000 10010000 10001101 10001000'), '$¢€𐍈'); |
| 21 | + t.is(decode('00100100 11000010 10100010 11100010 10000010 10101100 11110000 10010000 10001101 10001000'), '$¢€𐍈'); |
48 | 22 | });
|
49 | 23 |
|
50 | 24 | test('Fails on incomplete bytes (delimited)', t => {
|
51 |
| - t.is(app.decode('01110000 01100001 01110011 0111001'), ''); |
52 |
| - t.is(app.decode('01110000 0100001 01110011 01110011'), ''); |
| 25 | + t.is(decode('01110000 01100001 01110011 0111001'), ''); |
| 26 | + t.is(decode('01110000 0100001 01110011 01110011'), ''); |
53 | 27 | });
|
54 | 28 |
|
55 | 29 | test('Fails on incomplete bytes (non-delimited)', t => {
|
56 |
| - t.is(app.decode('011100000110000101110011011100101'), ''); |
| 30 | + t.is(decode('011100000110000101110011011100101'), ''); |
57 | 31 | });
|
58 | 32 |
|
59 | 33 | test('Fails on invalid UTF', t => {
|
60 |
| - t.is(app.decode('100000000000000000000000'), ''); |
| 34 | + t.is(decode('100000000000000000000000'), ''); |
61 | 35 | });
|
62 | 36 |
|
63 | 37 | test('Fails on text followed by binary', t => {
|
64 |
| - t.is(app.decode('text text text 01110000 01100001 01110011'), ''); |
| 38 | + t.is(decode('text text text 01110000 01100001 01110011'), ''); |
65 | 39 | });
|
66 | 40 |
|
67 | 41 | test('Fails on less than three bytes', t => {
|
68 |
| - t.is(app.decode('01101000 01101001'), ''); |
69 |
| - t.is(app.decode('01101001'), ''); |
| 42 | + t.is(decode('01101000 01101001'), ''); |
| 43 | + t.is(decode('01101001'), ''); |
70 | 44 |
|
71 |
| - t.not(app.decode('01101000 01101001 01101001'), ''); |
| 45 | + t.not(decode('01101000 01101001 01101001'), ''); |
72 | 46 | });
|
73 | 47 |
|
74 | 48 | test('Fails on non-binary', t => {
|
75 |
| - t.is(app.decode('clearly not binary'), ''); |
| 49 | + t.is(decode('clearly not binary'), ''); |
76 | 50 | });
|
77 | 51 |
|
78 | 52 | test('Fails on empty string', t => {
|
79 |
| - t.is(app.decode(''), ''); |
| 53 | + t.is(decode(''), ''); |
80 | 54 | });
|
81 | 55 |
|
82 | 56 | test('Throws `TypeError` on non-string parameters', t => {
|
83 | 57 | const nonStringTypes = [null, undefined, NaN, true, false, 10101010, [], {}];
|
84 | 58 |
|
85 | 59 | for (let type of nonStringTypes) {
|
86 |
| - t.throws(() => app.decode(type), TypeError); |
| 60 | + t.throws(() => decode(type), TypeError); |
87 | 61 | }
|
88 | 62 | });
|
0 commit comments