Skip to content

Commit

Permalink
tests: use strict equality
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 16, 2018
1 parent d3a9dd5 commit 2febdb7
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var contentDisposition = require('..')

describe('contentDisposition()', function () {
it('should create an attachment header', function () {
assert.equal(contentDisposition(), 'attachment')
assert.strictEqual(contentDisposition(), 'attachment')
})
})

Expand All @@ -15,66 +15,66 @@ describe('contentDisposition(filename)', function () {
})

it('should create a header with file name', function () {
assert.equal(contentDisposition('plans.pdf'),
assert.strictEqual(contentDisposition('plans.pdf'),
'attachment; filename="plans.pdf"')
})

it('should use the basename of the string', function () {
assert.equal(contentDisposition('/path/to/plans.pdf'),
assert.strictEqual(contentDisposition('/path/to/plans.pdf'),
'attachment; filename="plans.pdf"')
})

describe('when "filename" is US-ASCII', function () {
it('should only include filename parameter', function () {
assert.equal(contentDisposition('plans.pdf'),
assert.strictEqual(contentDisposition('plans.pdf'),
'attachment; filename="plans.pdf"')
})

it('should escape quotes', function () {
assert.equal(contentDisposition('the "plans".pdf'),
assert.strictEqual(contentDisposition('the "plans".pdf'),
'attachment; filename="the \\"plans\\".pdf"')
})
})

describe('when "filename" is ISO-8859-1', function () {
it('should only include filename parameter', function () {
assert.equal(contentDisposition('«plans».pdf'),
assert.strictEqual(contentDisposition('«plans».pdf'),
'attachment; filename="«plans».pdf"')
})

it('should escape quotes', function () {
assert.equal(contentDisposition('the "plans" (1µ).pdf'),
assert.strictEqual(contentDisposition('the "plans" (1µ).pdf'),
'attachment; filename="the \\"plans\\" (1µ).pdf"')
})
})

describe('when "filename" is Unicode', function () {
it('should include filename* parameter', function () {
assert.equal(contentDisposition('планы.pdf'),
assert.strictEqual(contentDisposition('планы.pdf'),
'attachment; filename="?????.pdf"; filename*=UTF-8\'\'%D0%BF%D0%BB%D0%B0%D0%BD%D1%8B.pdf')
})

it('should include filename fallback', function () {
assert.equal(contentDisposition('£ and € rates.pdf'),
assert.strictEqual(contentDisposition('£ and € rates.pdf'),
'attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf')
assert.equal(contentDisposition('€ rates.pdf'),
assert.strictEqual(contentDisposition('€ rates.pdf'),
'attachment; filename="? rates.pdf"; filename*=UTF-8\'\'%E2%82%AC%20rates.pdf')
})

it('should encode special characters', function () {
assert.equal(contentDisposition('€\'*%().pdf'),
assert.strictEqual(contentDisposition('€\'*%().pdf'),
'attachment; filename="?\'*%().pdf"; filename*=UTF-8\'\'%E2%82%AC%27%2A%25%28%29.pdf')
})
})

describe('when "filename" contains hex escape', function () {
it('should include filename* parameter', function () {
assert.equal(contentDisposition('the%20plans.pdf'),
assert.strictEqual(contentDisposition('the%20plans.pdf'),
'attachment; filename="the%20plans.pdf"; filename*=UTF-8\'\'the%2520plans.pdf')
})

it('should handle Unicode', function () {
assert.equal(contentDisposition('€%20£.pdf'),
assert.strictEqual(contentDisposition('€%20£.pdf'),
'attachment; filename="?%20£.pdf"; filename*=UTF-8\'\'%E2%82%AC%2520%C2%A3.pdf')
})
})
Expand All @@ -88,30 +88,30 @@ describe('contentDisposition(filename, options)', function () {
})

it('should default to true', function () {
assert.equal(contentDisposition('€ rates.pdf'),
assert.strictEqual(contentDisposition('€ rates.pdf'),
'attachment; filename="? rates.pdf"; filename*=UTF-8\'\'%E2%82%AC%20rates.pdf')
})

describe('when "false"', function () {
it('should not generate ISO-8859-1 fallback', function () {
assert.equal(contentDisposition('£ and € rates.pdf', { fallback: false }),
assert.strictEqual(contentDisposition('£ and € rates.pdf', { fallback: false }),
'attachment; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf')
})

it('should keep ISO-8859-1 filename', function () {
assert.equal(contentDisposition('£ rates.pdf', { fallback: false }),
assert.strictEqual(contentDisposition('£ rates.pdf', { fallback: false }),
'attachment; filename="£ rates.pdf"')
})
})

describe('when "true"', function () {
it('should generate ISO-8859-1 fallback', function () {
assert.equal(contentDisposition('£ and € rates.pdf', { fallback: true }),
assert.strictEqual(contentDisposition('£ and € rates.pdf', { fallback: true }),
'attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf')
})

it('should pass through ISO-8859-1 filename', function () {
assert.equal(contentDisposition('£ rates.pdf', { fallback: true }),
assert.strictEqual(contentDisposition('£ rates.pdf', { fallback: true }),
'attachment; filename="£ rates.pdf"')
})
})
Expand All @@ -123,35 +123,35 @@ describe('contentDisposition(filename, options)', function () {
})

it('should use as ISO-8859-1 fallback', function () {
assert.equal(contentDisposition('£ and € rates.pdf', { fallback: '£ and EURO rates.pdf' }),
assert.strictEqual(contentDisposition('£ and € rates.pdf', { fallback: '£ and EURO rates.pdf' }),
'attachment; filename="£ and EURO rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf')
})

it('should use as fallback even when filename is ISO-8859-1', function () {
assert.equal(contentDisposition('"£ rates".pdf', { fallback: '£ rates.pdf' }),
assert.strictEqual(contentDisposition('"£ rates".pdf', { fallback: '£ rates.pdf' }),
'attachment; filename="£ rates.pdf"; filename*=UTF-8\'\'%22%C2%A3%20rates%22.pdf')
})

it('should do nothing if equal to filename', function () {
assert.equal(contentDisposition('plans.pdf', { fallback: 'plans.pdf' }),
assert.strictEqual(contentDisposition('plans.pdf', { fallback: 'plans.pdf' }),
'attachment; filename="plans.pdf"')
})

it('should use the basename of the string', function () {
assert.equal(contentDisposition('€ rates.pdf', { fallback: '/path/to/EURO rates.pdf' }),
assert.strictEqual(contentDisposition('€ rates.pdf', { fallback: '/path/to/EURO rates.pdf' }),
'attachment; filename="EURO rates.pdf"; filename*=UTF-8\'\'%E2%82%AC%20rates.pdf')
})

it('should do nothing without filename option', function () {
assert.equal(contentDisposition(undefined, { fallback: 'plans.pdf' }),
assert.strictEqual(contentDisposition(undefined, { fallback: 'plans.pdf' }),
'attachment')
})
})
})

describe('with "type" option', function () {
it('should default to attachment', function () {
assert.equal(contentDisposition(),
assert.strictEqual(contentDisposition(),
'attachment')
})

Expand All @@ -166,17 +166,17 @@ describe('contentDisposition(filename, options)', function () {
})

it('should create a header with inline type', function () {
assert.equal(contentDisposition(undefined, { type: 'inline' }),
assert.strictEqual(contentDisposition(undefined, { type: 'inline' }),
'inline')
})

it('should create a header with inline type & filename', function () {
assert.equal(contentDisposition('plans.pdf', { type: 'inline' }),
assert.strictEqual(contentDisposition('plans.pdf', { type: 'inline' }),
'inline; filename="plans.pdf"')
})

it('should normalize type', function () {
assert.equal(contentDisposition(undefined, { type: 'INLINE' }),
assert.strictEqual(contentDisposition(undefined, { type: 'INLINE' }),
'inline')
})
})
Expand Down

0 comments on commit 2febdb7

Please sign in to comment.