Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 5, 2019
1 parent 8d35bb8 commit d3fc645
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,62 @@ var french = require('./fr')
var english = require('.')

test('profanities', function(t) {
t.plan(12)

retext()
.use(english)
.process('Shit!', function(err, file) {
t.deepEqual([err].concat(file.messages), [
null,
{
message: 'Don’t use “Shit”, it’s profane',
name: '1:1-1:5',
reason: 'Don’t use “Shit”, it’s profane',
line: 1,
column: 1,
location: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 5, offset: 4}
},
source: 'retext-profanities',
ruleId: 'shit',
fatal: false,
profanitySeverity: 2,
actual: 'Shit',
expected: null
}
])
t.deepEqual(
[err].concat(file.messages),
[
null,
{
message: 'Don’t use “Shit”, it’s profane',
name: '1:1-1:5',
reason: 'Don’t use “Shit”, it’s profane',
line: 1,
column: 1,
location: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 5, offset: 4}
},
source: 'retext-profanities',
ruleId: 'shit',
fatal: false,
profanitySeverity: 2,
actual: 'Shit',
expected: null
}
],
'should warn'
)
})

retext()
.use(french)
.process('Merde!', function(err, file) {
t.deepEqual([err].concat(file.messages), [
null,
{
message: 'Don’t use “Merde”, it’s profane',
name: '1:1-1:6',
reason: 'Don’t use “Merde”, it’s profane',
line: 1,
column: 1,
location: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 6, offset: 5}
},
source: 'retext-profanities-fr',
ruleId: 'merde',
fatal: false,
profanitySeverity: 2,
actual: 'Merde',
expected: null
}
])
t.deepEqual(
[err].concat(file.messages),
[
null,
{
message: 'Don’t use “Merde”, it’s profane',
name: '1:1-1:6',
reason: 'Don’t use “Merde”, it’s profane',
line: 1,
column: 1,
location: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 6, offset: 5}
},
source: 'retext-profanities-fr',
ruleId: 'merde',
fatal: false,
profanitySeverity: 2,
actual: 'Merde',
expected: null
}
],
'should support other languages'
)
})

retext()
Expand All @@ -67,11 +73,10 @@ test('profanities', function(t) {
'The kidnapper was the mother, an addict.'
].join('\n'),
function(err, file) {
t.ifError(err, 'should not fail (#1)')

t.deepEqual(
file.messages.map(String),
[err].concat(file.messages.map(String)),
[
null,
'1:33-1:37: Be careful with “butt”, it’s profane in some cases',
'2:9-2:15: Don’t use “asshat”, it’s profane',
'3:34-3:40: Reconsider using “addict”, it may be profane'
Expand All @@ -86,11 +91,9 @@ test('profanities', function(t) {
.process(
['He’s pretty set on beating your butt for sheriff.'].join('\n'),
function(err, file) {
t.ifError(err, 'should not fail (#2)')

t.deepEqual(
file.messages.map(String),
[],
[err].concat(file.messages.map(String)),
[null],
'should not warn for `ignore`d phrases'
)
}
Expand All @@ -101,11 +104,12 @@ test('profanities', function(t) {
.process(
['When he’ll freeze over, hell freezes over.'].join('\n'),
function(err, file) {
t.ifError(err, 'should not fail (#3)')

t.deepEqual(
file.messages.map(String),
['1:25-1:29: Be careful with “hell”, it’s profane in some cases'],
[err].concat(file.messages.map(String)),
[
null,
'1:25-1:29: Be careful with “hell”, it’s profane in some cases'
],
'should correctly depend on apostrophes'
)
}
Expand All @@ -114,20 +118,15 @@ test('profanities', function(t) {
retext()
.use(english)
.process('slave slaves', function(err, file) {
t.deepEqual([err].concat(file.messages.map(String)), [
null,
'1:1-1:6: Don’t use “slave”, it’s profane',
'1:7-1:13: Don’t use “slaves”, it’s profane'
])
})

retext()
.use(french)
.process('Euh, merde!', function(err, file) {
t.deepEqual([err].concat(file.messages.map(String)), [
null,
'1:6-1:11: Don’t use “merde”, it’s profane'
])
t.deepEqual(
[err].concat(file.messages.map(String)),
[
null,
'1:1-1:6: Don’t use “slave”, it’s profane',
'1:7-1:13: Don’t use “slaves”, it’s profane'
],
'should support plurals and singulars'
)
})

retext()
Expand All @@ -139,16 +138,17 @@ test('profanities', function(t) {
'The kidnapper was the mother, an addict.'
].join('\n'),
function(err, file) {
t.ifError(err, 'should not fail (#1)')

t.deepEqual(
file.messages.map(String),
[err].concat(file.messages.map(String)),
[
null,
'2:9-2:15: Don’t use “asshat”, it’s profane',
'3:34-3:40: Reconsider using “addict”, it may be profane'
],
'should warn about profanities'
)
}
)

t.end()
})

0 comments on commit d3fc645

Please sign in to comment.