Skip to content

Commit

Permalink
fix: append single word filter test case
Browse files Browse the repository at this point in the history
  • Loading branch information
appdevmania215 committed Jan 26, 2023
1 parent 7d55f51 commit 43c8530
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
13 changes: 0 additions & 13 deletions lib/badwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ class Filter {
.length > 0 || false;
}

/**
* Determine if a string contains profane language against the exclude array.
* @param {string} string - String to evaluate for profanity.
*/
isAnyProfane(string) {
return this.list
.filter((word) => {
const wordExp = new RegExp(`\\b${word.replace(/(\W)/g, '\\$1')}\\b`, 'gi');
return wordExp.test(string);
})
.length > 0 || false;
}

/**
* Replace a word with placeHolder characters;
* @param {string} string - String to replace.
Expand Down
37 changes: 21 additions & 16 deletions test/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,50 @@ var Filter = require('../lib/badwords.js'),
filter = new Filter(),
assert = require('better-assert');

describe('filter', function(){
describe('clean',function(){
it('Should replace a bad word within a sentence asterisks (******)',function(){
console.log(filter.clean('áéñóú'));
assert(filter.clean('áéñóú') === 'áéñóú');
describe('filter', function () {
describe('clean', function () {
it('Should replace a bad word within a sentence asterisks (******)', function () {
console.log(filter.clean('Don\'t be an ash0le'));
assert(filter.clean('Don\'t be an ash0le') === 'Don\'t be an ******');

});

it('Should replace multiple instances of any bad words within a sentence asterisks (******)',function(){
it('Should replace multiple instances of any bad words within a sentence asterisks (******)', function () {
assert(filter.clean('cnts ash0le knob xxx') === '**** ****** **** ***');
});

it('Should not replace anything within a sentence if there are no bad words',function(){
it('Should not replace anything within a sentence if there are no bad words', function () {
assert(filter.clean('The cat ran fast') === 'The cat ran fast');
});

it('Should replace a string with proper placeholder when overridden', function(){
var customFilter = new Filter({ placeHolder: 'x'});
it('Should replace a string with proper placeholder when overridden', function () {
var customFilter = new Filter({ placeHolder: 'x' });
assert(customFilter.clean('This is a hells good test') === 'This is a xxxxx good test');
});

it('Should allow an instance of filter with an empty blacklist', function() {
it('Should allow an instance of filter with an empty blacklist', function () {
var customFilter = new Filter({
emptyList: true
});
assert(customFilter.clean('This is a hells good test') === 'This is a hells good test');
});

it('Should tokenize words according to regex word boundaries',function(){
it('Should tokenize words according to regex word boundaries', function () {
assert(filter.clean('what a bitch...fuck you') === 'what a *****...**** you');
assert(filter.clean('<p>Don\'t be an asshole</p>') === '<p>Don\'t be an *******</p>');
});

xit('Should filter words that are derivatives of words from the filter blacklist', function() {
xit('Should filter words that are derivatives of words from the filter blacklist', function () {
assert(filter.clean('shitshit') === '********');
});
});

it('Shouldn\'t filter words that aren\'t profane.', function() {
it('Shouldn\'t filter words that aren\'t profane.', function () {
assert(filter.clean('hello there') === 'hello there');
});
});

it('Should not replace anything of a single , multilingual and not profane word', function () {
assert(filter.clean('áéñóú') === 'áéñóú');
});

});
});
});

0 comments on commit 43c8530

Please sign in to comment.