~ubuntu-branches/ubuntu/trusty/node-negotiator/trusty-proposed

« back to all changes in this revision

Viewing changes to test/encoding.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-10-20 17:33:37 UTC
  • Revision ID: package-import@ubuntu.com-20131020173337-75k05okhr2qhqcy1
Tags: upstream-0.3.0
Import upstream version 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function() {
 
2
  var configuration, preferredEncodings, testConfigurations, testCorrectEncoding, _i, _len,
 
3
    _this = this;
 
4
 
 
5
  preferredEncodings = require('../lib/encoding').preferredEncodings;
 
6
 
 
7
  this["Should return identity encoding when no encoding is provided"] = function(test) {
 
8
    test.deepEqual(preferredEncodings(null), ['identity']);
 
9
    return test.done();
 
10
  };
 
11
 
 
12
  this["Should include the identity encoding even if not explicity listed"] = function(test) {
 
13
    test.ok(preferredEncodings('gzip').indexOf('identity') !== -1);
 
14
    return test.done();
 
15
  };
 
16
 
 
17
  this["Should not return identity encoding if q = 0"] = function(test) {
 
18
    test.ok(preferredEncodings('identity;q=0').indexOf('identity') === -1);
 
19
    return test.done();
 
20
  };
 
21
 
 
22
  testCorrectEncoding = function(c) {
 
23
    return _this["Should return " + c.selected + " for accept-encoding header " + c.accept + " with provided encoding " + c.provided] = function(test) {
 
24
      test.deepEqual(preferredEncodings(c.accept, c.provided), c.selected);
 
25
      return test.done();
 
26
    };
 
27
  };
 
28
 
 
29
  testConfigurations = [
 
30
    {
 
31
      accept: 'gzip',
 
32
      provided: ['identity', 'gzip'],
 
33
      selected: ['gzip', 'identity']
 
34
    }, {
 
35
      accept: 'gzip, compress',
 
36
      provided: ['compress'],
 
37
      selected: ['compress']
 
38
    }, {
 
39
      accept: 'deflate',
 
40
      provided: ['gzip', 'identity'],
 
41
      selected: ['identity']
 
42
    }, {
 
43
      accept: '*',
 
44
      provided: ['identity', 'gzip'],
 
45
      selected: ['identity', 'gzip']
 
46
    }, {
 
47
      accept: 'gzip, compress',
 
48
      provided: ['compress', 'identity'],
 
49
      selected: ['compress', 'identity']
 
50
    }, {
 
51
      accept: 'gzip;q=0.8, identity;q=0.5, *;q=0.3',
 
52
      provided: ['identity', 'gzip', 'compress'],
 
53
      selected: ['gzip', 'identity', 'compress']
 
54
    }, {
 
55
      accept: 'gzip;q=0.8, compress',
 
56
      provided: ['gzip', 'compress'],
 
57
      selected: ['compress', 'gzip']
 
58
    }, {
 
59
      accept: 'gzip;q=0.8, compress',
 
60
      provided: null,
 
61
      selected: ['compress', 'gzip', 'identity']
 
62
    }
 
63
  ];
 
64
 
 
65
  for (_i = 0, _len = testConfigurations.length; _i < _len; _i++) {
 
66
    configuration = testConfigurations[_i];
 
67
    testCorrectEncoding(configuration);
 
68
  }
 
69
 
 
70
}).call(this);