Name: js-handler/node_modules/restify/node_modules/negotiator/test/encoding.js
| 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: | ]; |
| 60: | |
| 61: | for (_i = 0, _len = testConfigurations.length; _i < _len; _i++) { |
| 62: | configuration = testConfigurations[_i]; |
| 63: | testCorrectEncoding(configuration); |
| 64: | } |
| 65: | |
| 66: | }).call(this); |
