docs: update homepage link http to https (#5920)
[express.git] / test / utils.js
blobaff3f03aa3322860d7b3a1112b068db2943d9a7f
1 'use strict'
3 var assert = require('assert');
4 var Buffer = require('safe-buffer').Buffer
5 var utils = require('../lib/utils');
7 describe('utils.etag(body, encoding)', function(){
8 it('should support strings', function(){
9 assert.strictEqual(utils.etag('express!'),
10 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
13 it('should support utf8 strings', function(){
14 assert.strictEqual(utils.etag('express❤', 'utf8'),
15 '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
18 it('should support buffer', function(){
19 assert.strictEqual(utils.etag(Buffer.from('express!')),
20 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
23 it('should support empty string', function(){
24 assert.strictEqual(utils.etag(''),
25 '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
29 describe('utils.setCharset(type, charset)', function () {
30 it('should do anything without type', function () {
31 assert.strictEqual(utils.setCharset(), undefined);
32 });
34 it('should return type if not given charset', function () {
35 assert.strictEqual(utils.setCharset('text/html'), 'text/html');
36 });
38 it('should keep charset if not given charset', function () {
39 assert.strictEqual(utils.setCharset('text/html; charset=utf-8'), 'text/html; charset=utf-8');
40 });
42 it('should set charset', function () {
43 assert.strictEqual(utils.setCharset('text/html', 'utf-8'), 'text/html; charset=utf-8');
44 });
46 it('should override charset', function () {
47 assert.strictEqual(utils.setCharset('text/html; charset=iso-8859-1', 'utf-8'), 'text/html; charset=utf-8');
48 });
49 });
51 describe('utils.wetag(body, encoding)', function(){
52 it('should support strings', function(){
53 assert.strictEqual(utils.wetag('express!'),
54 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
57 it('should support utf8 strings', function(){
58 assert.strictEqual(utils.wetag('express❤', 'utf8'),
59 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
62 it('should support buffer', function(){
63 assert.strictEqual(utils.wetag(Buffer.from('express!')),
64 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
67 it('should support empty string', function(){
68 assert.strictEqual(utils.wetag(''),
69 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')