|
|
@ -37,7 +37,7 @@ module.exports.tests.text_parser = function(test, common) { |
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
t.deepEquals(clean, expected_clean); |
|
|
|
t.deepEquals(clean, expected_clean); |
|
|
|
t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0'], 'no errors'); |
|
|
|
t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0']); |
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
@ -46,6 +46,78 @@ module.exports.tests.text_parser = function(test, common) { |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should trim whitespace', t => { |
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
|
|
|
var raw = { text: ` test \n ` }; |
|
|
|
|
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equals(clean.text, 'test'); |
|
|
|
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should trim double quotes', t => { |
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
|
|
|
var raw = { text: ` "test" \n ` }; |
|
|
|
|
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equals(clean.text, 'test'); |
|
|
|
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should trim single quotes', t => { |
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
|
|
|
var raw = { text: ` 'test' \n ` }; |
|
|
|
|
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equals(clean.text, 'test'); |
|
|
|
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should trim German quotes', t => { |
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
|
|
|
var raw = { text: ` „test“ \n ` }; |
|
|
|
|
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equals(clean.text, 'test'); |
|
|
|
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should trim guillemets', t => { |
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
|
|
|
var raw = { text: ` »test« \n ` }; |
|
|
|
|
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equals(clean.text, 'test'); |
|
|
|
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should trim Chinese quotes', t => { |
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
|
|
|
var raw = { text: ` ﹁「test」﹂ \n ` }; |
|
|
|
|
|
|
|
const messages = sanitizer.sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equals(clean.text, 'test'); |
|
|
|
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('return an array of expected parameters in object form for validation', (t) => { |
|
|
|
test('return an array of expected parameters in object form for validation', (t) => { |
|
|
|
const expected = [{ name: 'text' }]; |
|
|
|
const expected = [{ name: 'text' }]; |
|
|
|
const validParameters = sanitizer.expected(); |
|
|
|
const validParameters = sanitizer.expected(); |
|
|
|