mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-20 09:37:26 -05:00
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
This minimizes side effects of import/require across the codebase, and lets the caller be responsible of initializing child processeses, as well as other async logic, such as restoring saved battles.
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const { makeUser, destroyUser } = require('../../users-utils');
|
|
const assert = require('../../assert');
|
|
|
|
describe("Hangman", () => {
|
|
let Hangman = null;
|
|
|
|
before(function () {
|
|
Hangman = require('../../../dist/server/chat-plugins/hangman').Hangman;
|
|
this.creator = makeUser('dawoblefet');
|
|
this.guesser = makeUser('mathy');
|
|
});
|
|
|
|
after(function () {
|
|
destroyUser(this.creator);
|
|
destroyUser(this.guesser);
|
|
});
|
|
|
|
function createHangman(creator, word, hint) {
|
|
return new Hangman(Rooms.lobby, creator, word, hint);
|
|
}
|
|
|
|
it("should reject impossible guesses", function () {
|
|
const game = createHangman(this.creator, "Wynaut", "Why write unit tests?");
|
|
const errorRegex = /Your guess "[A-Za-z ]+" is invalid./;
|
|
const testInvalidGuess = guess => {
|
|
assert.throws(() => {
|
|
game.choose(this.guesser, guess);
|
|
}, errorRegex, `Guess should have been invalid: "${guess}"`);
|
|
};
|
|
|
|
testInvalidGuess('wobbuffet'); // wrong length
|
|
|
|
game.choose(this.guesser, 'z');
|
|
testInvalidGuess('zekrom'); // 'z' already guessed
|
|
|
|
game.choose(this.guesser, 't');
|
|
// _ _ _ _ _ t
|
|
testInvalidGuess('beldum'); // wrong letters
|
|
game.choose(this.guesser, 'furret'); // should be valid
|
|
testInvalidGuess('chatot'); // only one 't'
|
|
|
|
game.choose(this.guesser, 'a');
|
|
game.choose(this.guesser, 'n');
|
|
// _ _ n a _ t
|
|
testInvalidGuess('durant'); // 'n' in wrong spot
|
|
|
|
game.choose(this.guesser, 'wynaut'); // we did it!
|
|
});
|
|
});
|