Coverage work found a 3rd real bug: isMacOS() compared os.name against the legacy 'Mac OS' string, but ua-parser-js v2 reports 'macOS' — so it was dead, and Mac users saw "Ctrl + k" instead of "⌘ + k" in the editor toolbar, search, and settings shortcut hints. Now accepts both 'macOS' and 'Mac OS'. Suites (via subagent, verified): via-servers (10 — power/popularity server selection), bad-words (9), syntaxHighlight tokenize (14), plugins/utils getEmoticonSearchStr (5), imageCompression formatFileSize/isCompressible (5), user-agent (6, now asserting the fixed behavior). Full suite now 501 tests, all passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { testBadWords, BAD_WORDS_REGEX } from './bad-words';
|
|
|
|
test('testBadWords returns false for clean text', () => {
|
|
assert.equal(testBadWords('hello world'), false);
|
|
assert.equal(testBadWords('this is clean text'), false);
|
|
assert.equal(testBadWords(''), false);
|
|
});
|
|
|
|
test('testBadWords matches custom additions', () => {
|
|
// 'torture' and 't0rture' are appended in additionalBadWords
|
|
assert.equal(testBadWords('torture'), true);
|
|
assert.equal(testBadWords('t0rture'), true);
|
|
});
|
|
|
|
test('testBadWords is case-insensitive', () => {
|
|
assert.equal(testBadWords('Torture'), true);
|
|
assert.equal(testBadWords('TORTURE'), true);
|
|
assert.equal(testBadWords('DamN'), true);
|
|
});
|
|
|
|
test('testBadWords matches words from the base list', () => {
|
|
assert.equal(testBadWords('damn'), true);
|
|
assert.equal(testBadWords('hell'), true);
|
|
assert.equal(testBadWords('crap'), true);
|
|
});
|
|
|
|
test('testBadWords respects word boundaries (no match inside a larger word)', () => {
|
|
// alphanumeric extension on either side prevents a match
|
|
assert.equal(testBadWords('tortured'), false);
|
|
assert.equal(testBadWords('tortures'), false);
|
|
assert.equal(testBadWords('damning'), false);
|
|
assert.equal(testBadWords('hello'), false);
|
|
assert.equal(testBadWords('shell'), false);
|
|
assert.equal(testBadWords('crappy'), false);
|
|
});
|
|
|
|
test('testBadWords does not match a bad word as a substring of an unrelated word', () => {
|
|
assert.equal(testBadWords('class'), false);
|
|
assert.equal(testBadWords('pass'), false);
|
|
assert.equal(testBadWords('grass'), false);
|
|
});
|
|
|
|
test('underscore acts as a word boundary', () => {
|
|
// surrounding underscores still allow a match, since `_` is a boundary char
|
|
assert.equal(testBadWords('word_torture_word'), true);
|
|
// but an alphanumeric char glued directly to the word still blocks it
|
|
assert.equal(testBadWords('tor_ture'), false);
|
|
});
|
|
|
|
test('testBadWords matches a bad word embedded in a sentence with spaces', () => {
|
|
assert.equal(testBadWords('what the hell is this'), true);
|
|
assert.equal(testBadWords('I think this is fine'), false);
|
|
});
|
|
|
|
test('BAD_WORDS_REGEX is a global regex; reuse it via String.match', () => {
|
|
// testBadWords lowercases the input before matching
|
|
assert.ok('torture'.toLowerCase().match(BAD_WORDS_REGEX));
|
|
assert.equal('innocent'.toLowerCase().match(BAD_WORDS_REGEX), null);
|
|
});
|