UNPKG

@2toad/profanity

Version:

A JavaScript profanity filter

142 lines 7.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const _1 = require("."); describe('Profanity', () => { describe('exists (wholeWord = true)', () => { it('should return true when profanity exists in a sentence', () => { chai_1.expect(_1.profanity.exists('I like big butts and I cannot lie')).to.equal(true); }); it('should return true when profanity exists as a single word', () => { chai_1.expect(_1.profanity.exists('butt')).to.equal(true); }); it('should return false when profanity is not a whole word in a sentence', () => { chai_1.expect(_1.profanity.exists('Should we censor the word arsenic?')).to.equal(false); }); it('should return true when profanity exists within multiple lines', () => { chai_1.expect(_1.profanity.exists(` Nothing profane on line 1. Censoring butt on line 2. Nothing profane on line 3. `)).to.equal(true); }); it('should return false when profanity does not exist', () => { chai_1.expect(_1.profanity.exists('I like big glutes and I cannot lie')).to.equal(false); }); }); describe('exists (wholeWord = false)', () => { const options = new _1.ProfanityOptions(); options.wholeWord = false; const customProfanity = new _1.Profanity(options); it('should return true when profanity is part of a word in a sentence', () => { chai_1.expect(customProfanity.exists('Should we censor the word arsenic?')).to.equal(true); }); it('should return true when profanity is part of a word, within multiple lines', () => { chai_1.expect(customProfanity.exists(` Nothing profane on line 1. Censoring arsenic on line 2. Nothing profane on line 3. `)).to.equal(true); }); it('should return false when profanity does not exist', () => { chai_1.expect(customProfanity.exists('I like big glutes and I cannot lie')).to.equal(false); }); it('should return true when profanity exists as part of a single word', () => { chai_1.expect(customProfanity.exists('arsenic')).to.equal(true); }); }); describe('censor', () => { it('should replace profanity with grawlix in a sentence', () => { const censored = _1.profanity.censor('I like big butts and I cannot lie'); chai_1.expect(censored.includes(_1.profanity.options.grawlix)).to.equal(true); }); it('should remove profanity from a sentence', () => { const censored = _1.profanity.censor('I like big butts (aka arses) and I cannot lie'); chai_1.expect(_1.profanity.exists(censored)).to.equal(false); }); it('should remove profanity from multiple lines', () => { const censored = _1.profanity.censor(` Nothing profane on line 1. Censoring butt on line 2. Nothing profane on line 3. `); chai_1.expect(_1.profanity.exists(censored)).to.equal(false); }); it('should not alter sentence without profanity', () => { const original = 'I like big glutes and I cannot lie'; const censored = _1.profanity.censor(original); chai_1.expect(censored).to.equal(original); }); it('should remove profanity when profanity exists as a single word', () => { const censored = _1.profanity.censor('butt'); chai_1.expect(_1.profanity.exists(censored)).to.equal(false); }); }); describe('addWords', () => { it('should add a single word to the list of profane words', () => { const customProfanity = new _1.Profanity(); customProfanity.addWords(['aardvark']); chai_1.expect(customProfanity.exists('Should we censor the word aardvark?')).to.equal(true); }); it('should add mulitple words to the list of profane words', () => { const customProfanity = new _1.Profanity(); customProfanity.addWords(['aardvark', 'zebra']); chai_1.expect(customProfanity.exists('Should we censor the word aardvark and zebra?')).to.equal(true); }); }); describe('removeWords', () => { it('should remove a single word from the list of profane words', () => { const customProfanity = new _1.Profanity(); customProfanity.removeWords(['butts']); chai_1.expect(customProfanity.exists('I like big butts and I cannot lie')).to.equal(false); }); it('should remove mulitple words from the list of profane words', () => { const customProfanity = new _1.Profanity(); customProfanity.removeWords(['butts', 'arses']); chai_1.expect(customProfanity.exists('I like big butts (aka arses) and I cannot lie')).to.equal(false); }); }); describe('Whitelist (wholeWord = true)', () => { it('should whitelist a single word', () => { const customProfanity = new _1.Profanity(); customProfanity.whitelist.addWords(['butt']); chai_1.expect(customProfanity.exists('Should we censor the word butt?')).to.equal(false); }); it('should whitelist multiple words', () => { const customProfanity = new _1.Profanity(); customProfanity.whitelist.addWords(['butt', 'arse']); chai_1.expect(customProfanity.exists('Should we censor the word butt or arse?')).to.equal(false); }); }); describe('Whitelist (wholeWord = false)', () => { const options = new _1.ProfanityOptions(); options.wholeWord = false; it('should whitelist a single word', () => { const customProfanity = new _1.Profanity(options); customProfanity.whitelist.addWords(['buttocks']); chai_1.expect(customProfanity.exists('Should we censor the word buttocks?')).to.equal(false); }); it('should whitelist multiple words', () => { const customProfanity = new _1.Profanity(options); customProfanity.whitelist.addWords(['buttocks', 'arsenic']); chai_1.expect(customProfanity.exists('Should we censor the word buttocks or arsenic?')).to.equal(false); }); }); describe('Whitelist - removeWords', () => { it('should remove a single word from the whitelist', () => { const customProfanity = new _1.Profanity(); customProfanity.whitelist.addWords(['butts', 'arses']); chai_1.expect(customProfanity.exists('I like big butts and I cannot lie')).to.equal(false); customProfanity.whitelist.removeWords(['butts']); chai_1.expect(customProfanity.exists('I like big butts and I cannot lie')).to.equal(true); }); it('should remove multiple words from the whitelist', () => { const customProfanity = new _1.Profanity(); customProfanity.whitelist.addWords(['butts', 'arses']); chai_1.expect(customProfanity.exists('I like big butts (aka arses) and I cannot lie')).to.equal(false); customProfanity.whitelist.removeWords(['butts']); chai_1.expect(customProfanity.exists('I like big butts (aka arses) and I cannot lie')).to.equal(true); }); }); }); //# sourceMappingURL=profanity.spec.js.map