pokemon-showdown/test/server/chat-plugins/responder.js
Guangcong Luo 78439b4a02
Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00

42 lines
1.3 KiB
JavaScript

/**
* Tests for the Help room auto-answerer.
* Written by Mia.
* @author mia-pi-git
*/
'use strict';
const assert = require('assert').strict;
const Responder = require('../../../dist/server/chat-plugins/responder').AutoResponder;
const room = Rooms.createChatRoom('etheria');
const Help = new Responder(room);
describe('Autoresponder', () => {
it('should only return true on added regexes', () => {
Help.data.pairs.catra = [];
Help.data.pairs.catra.push(Help.stringRegex(`Hey & Adora`));
assert(Help.test('Hey, Adora', 'catra'));
assert(!Help.test('Hello, Adora', 'catra'));
});
it('should produce valid regexes', () => {
const regexString = Help.stringRegex(`uwu & awa`);
assert.equal(regexString, "(?=.*?(uwu))(?=.*?(awa))");
const regex = new RegExp(regexString);
assert(regex.test('uwu awa'));
});
it('should handle |, &, and ! correctly', () => {
const and = new RegExp(Help.stringRegex(`Horde & Prime`));
assert(and.test('Horde Prime'));
assert(!and.test('Horde'));
const or = new RegExp(Help.stringRegex(`she-ra|sea-ra`));
assert(or.test('sea-ra'));
assert(or.test(`she-ra`));
assert(!or.test('ADVENTURE'));
const ignore = new RegExp(Help.stringRegex(`!Hordak`));
assert(ignore.test(`FOR THE HONOR OF GREYSKULL`));
assert(!ignore.test('Hordak'));
});
});