<commit_before>'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Choice parser', function () {
	afterEach(() => battle.destroy());
	describe('Team Preview requests', function () {
		it('should accept only `team` choices', function () {
			battle = common.createBattle({preview: true}, [
				[{species: "Mew", ability: 'synchronize', moves: ['recover']}],
				[{species: "Rhydon", ability: 'prankster', moves: ['splash']}],
			]);

			const validChoice = 'team 1';
			assert(battle.choose('p1', validChoice));
			battle.p1.clearChoice();
			assert(battle.choose('p2', validChoice));
			battle.p1.clearChoice();

			const badChoices = ['move 1', 'move 2 mega', 'switch 1', 'pass', 'shift'];
			for (const badChoice of badChoices) {
				assert.false(battle.choose('p1', badChoice), `Choice '${badChoice}' should be rejected`);
			}
		});

		it('should reject non-numerical choice details', function () {
			battle = common.createBattle({preview: true}, [
				[{species: "Mew", ability: 'synchronize', moves: ['recover']}],
				[{species: "Rhydon", ability: 'prankster', moves: ['splash']}],
			]);

			for (const side of battle.sides) {
				assert.false(battle.choose(side.id, 'team Rhydon'));
				assert.false(battle.choose(side.id, 'team Mew'));
				assert.false(battle.choose(side.id, 'team first'));
			}
		});
	});

	describe('Switch requests', function () {
		describe('Generic', function () {
			it('should reject non-numerical input for `switch` choices', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [
					{species: "Mew", ability: 'synchronize', moves: ['lunardance']},
					{species: "Bulbasaur", ability: 'overgrow', moves: ['tackle', 'growl']},
				]);
				battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['splash']}]);

				battle.makeChoices('move lunardance', 'move splash');

				assert.false(battle.choose('p1', 'switch first'));
				assert.false(battle.choose('p1', 'switch second'));
			});
		});

		describe('Singles', function () {
			it('should accept only `switch` choices', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [
					{species: "Mew", ability: 'synchronize', moves: ['lunardance']},
					{species: "Bulbasaur", ability: 'overgrow', moves: ['tackle', 'growl']},
				]);
				battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['splash']}]);

				battle.makeChoices('move lunardance', 'move splash');

				const badChoices = ['move 1', 'move 2 mega', 'team 1', 'pass', 'shift'];
				for (const badChoice of badChoices) {
					assert.false(battle.p1.choose(badChoice), `Choice '${badChoice}' should be rejected`);
				}

				const validChoice = 'switch Bulbasaur';
				assert(battle.p1.choose(validChoice));
				battle.p1.clearChoice();
			});
		});

		describe('Doubles/Triples', function () {
			it('should accept only `switch` and `pass` choices', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Pineco", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Geodude", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Koffing", ability: 'levitate', moves: ['smog']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Skarmory", ability: 'sturdy', moves: ['roost']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
					{species: "Ekans", ability: 'shedskin', moves: ['wrap']},
				]);
				battle.makeChoices('move selfdestruct, move selfdestruct', 'move roost, move irondefense'); // Both p1 active Pokémon faint

				const badChoices = ['move 1', 'move 2 mega', 'team 1', 'shift'];
				for (const badChoice of badChoices) {
					assert.false(battle.p1.choose(badChoice), `Choice '${badChoice}' should be rejected`);
				}

				assert(battle.p1.choose(`pass, switch 3`), `Choice 'pass, switch 3' should be valid`);
			});

			it('should reject choice details for `pass` choices', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Pineco", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Geodude", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Koffing", ability: 'levitate', moves: ['smog']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Skarmory", ability: 'sturdy', moves: ['roost']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
					{species: "Ekans", ability: 'shedskin', moves: ['wrap']},
				]);
				battle.makeChoices('move selfdestruct, move selfdestruct', 'move roost, move irondefense'); // Both p1 active Pokémon faint

				const switchChoice = 'switch 3';
				const passChoice = 'pass';

				assert.false(battle.choose('p1', `${switchChoice}, ${passChoice} 1`));
				assert.false(battle.choose('p1', `${passChoice} 1, ${switchChoice}`));
				assert.false(battle.choose('p1', `${switchChoice}, ${passChoice} a`));
				assert.false(battle.choose('p1', `${passChoice} a, ${switchChoice}`));
			});
		});
	});

	describe('Move requests', function () {
		describe('Generic', function () {
			it('should reject `pass` choices for non-fainted Pokémon', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [{species: "Mew", ability: 'synchronize', moves: ['recover']}]);
				battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['splash']}]);

				for (const side of battle.sides) {
					assert.false(battle.choose(side.id, 'pass'));
				}
			});

			it('should allow mega evolving and targeting in the same move in either order', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Gengar", ability: 'cursedbody', item: 'gengarite', moves: ['shadowball']},
					{species: "Porygon", ability: 'download', moves: ['conversion2']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Porygon-Z", ability: 'adaptability', item: 'normaliumz', moves: ['conversion2']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
				]);

				const badChoices = [`move 1 1 2`, `move 1 1 mega ultra`, `move 1 mega zmove 2`];
				for (const badChoice of badChoices) {
					const choice = `${badChoice}, move Conversion 2`;
					assert.false(battle.choose('p1', choice), `Choice '${choice}' should be rejected`);
				}

				assert.ok(battle.choose('p1', `move 1 1 mega, move Conversion 2 1`));
				assert.ok(battle.choose('p2', `move Conversion 2 1 zmove, move irondefense`));
			});
		});

		describe('Singles', function () {
			it('should accept only `move` and `switch` choices', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [
					{species: "Mew", ability: 'synchronize', moves: ['lunardance', 'recover']},
					{species: "Bulbasaur", ability: 'overgrow', moves: ['tackle', 'growl']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Rhydon", ability: 'prankster', moves: ['splash', 'horndrill']},
					{species: "Charmander", ability: 'blaze', moves: ['tackle', 'growl']},
				]);

				const validChoices = ['move 1', 'move 2', 'switch 2'];
				for (const action of validChoices) {
					assert(battle.choose('p1', action), `Choice '${action}' should be valid`);
					battle.p1.clearChoice();
				}

				const badChoices = ['move 1 zmove', 'move 2 mega', 'team 1', 'pass', 'shift'];<commit_msg>Split out 'Conversion 2' tests from targeting<commit_after>'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Choice parser', function () {
	afterEach(() => battle.destroy());
	describe('Team Preview requests', function () {
		it('should accept only `team` choices', function () {
			battle = common.createBattle({preview: true}, [
				[{species: "Mew", ability: 'synchronize', moves: ['recover']}],
				[{species: "Rhydon", ability: 'prankster', moves: ['splash']}],
			]);

			const validChoice = 'team 1';
			assert(battle.choose('p1', validChoice));
			battle.p1.clearChoice();
			assert(battle.choose('p2', validChoice));
			battle.p1.clearChoice();

			const badChoices = ['move 1', 'move 2 mega', 'switch 1', 'pass', 'shift'];
			for (const badChoice of badChoices) {
				assert.false(battle.choose('p1', badChoice), `Choice '${badChoice}' should be rejected`);
			}
		});

		it('should reject non-numerical choice details', function () {
			battle = common.createBattle({preview: true}, [
				[{species: "Mew", ability: 'synchronize', moves: ['recover']}],
				[{species: "Rhydon", ability: 'prankster', moves: ['splash']}],
			]);

			for (const side of battle.sides) {
				assert.false(battle.choose(side.id, 'team Rhydon'));
				assert.false(battle.choose(side.id, 'team Mew'));
				assert.false(battle.choose(side.id, 'team first'));
			}
		});
	});

	describe('Switch requests', function () {
		describe('Generic', function () {
			it('should reject non-numerical input for `switch` choices', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [
					{species: "Mew", ability: 'synchronize', moves: ['lunardance']},
					{species: "Bulbasaur", ability: 'overgrow', moves: ['tackle', 'growl']},
				]);
				battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['splash']}]);

				battle.makeChoices('move lunardance', 'move splash');

				assert.false(battle.choose('p1', 'switch first'));
				assert.false(battle.choose('p1', 'switch second'));
			});
		});

		describe('Singles', function () {
			it('should accept only `switch` choices', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [
					{species: "Mew", ability: 'synchronize', moves: ['lunardance']},
					{species: "Bulbasaur", ability: 'overgrow', moves: ['tackle', 'growl']},
				]);
				battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['splash']}]);

				battle.makeChoices('move lunardance', 'move splash');

				const badChoices = ['move 1', 'move 2 mega', 'team 1', 'pass', 'shift'];
				for (const badChoice of badChoices) {
					assert.false(battle.p1.choose(badChoice), `Choice '${badChoice}' should be rejected`);
				}

				const validChoice = 'switch Bulbasaur';
				assert(battle.p1.choose(validChoice));
				battle.p1.clearChoice();
			});
		});

		describe('Doubles/Triples', function () {
			it('should accept only `switch` and `pass` choices', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Pineco", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Geodude", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Koffing", ability: 'levitate', moves: ['smog']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Skarmory", ability: 'sturdy', moves: ['roost']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
					{species: "Ekans", ability: 'shedskin', moves: ['wrap']},
				]);
				battle.makeChoices('move selfdestruct, move selfdestruct', 'move roost, move irondefense'); // Both p1 active Pokémon faint

				const badChoices = ['move 1', 'move 2 mega', 'team 1', 'shift'];
				for (const badChoice of badChoices) {
					assert.false(battle.p1.choose(badChoice), `Choice '${badChoice}' should be rejected`);
				}

				assert(battle.p1.choose(`pass, switch 3`), `Choice 'pass, switch 3' should be valid`);
			});

			it('should reject choice details for `pass` choices', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Pineco", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Geodude", ability: 'sturdy', moves: ['selfdestruct']},
					{species: "Koffing", ability: 'levitate', moves: ['smog']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Skarmory", ability: 'sturdy', moves: ['roost']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
					{species: "Ekans", ability: 'shedskin', moves: ['wrap']},
				]);
				battle.makeChoices('move selfdestruct, move selfdestruct', 'move roost, move irondefense'); // Both p1 active Pokémon faint

				const switchChoice = 'switch 3';
				const passChoice = 'pass';

				assert.false(battle.choose('p1', `${switchChoice}, ${passChoice} 1`));
				assert.false(battle.choose('p1', `${passChoice} 1, ${switchChoice}`));
				assert.false(battle.choose('p1', `${switchChoice}, ${passChoice} a`));
				assert.false(battle.choose('p1', `${passChoice} a, ${switchChoice}`));
			});
		});
	});

	describe('Move requests', function () {
		describe('Generic', function () {
			it('should reject `pass` choices for non-fainted Pokémon', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [{species: "Mew", ability: 'synchronize', moves: ['recover']}]);
				battle.join('p2', 'Guest 2', 1, [{species: "Rhydon", ability: 'prankster', moves: ['splash']}]);

				for (const side of battle.sides) {
					assert.false(battle.choose(side.id, 'pass'));
				}
			});

			it('should allow mega evolving and targeting in the same move in either order', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Gengar", ability: 'cursedbody', item: 'gengarite', moves: ['shadowball']},
					{species: "Zigzagoon", ability: 'pickup', moves: ['tackle']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Blaziken", ability: 'blaze', item: 'firiumz', moves: ['blazekick']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
				]);

				const badChoices = [`move 1 1 2`, `move 1 1 mega ultra`, `move 1 mega zmove 2`];
				for (const badChoice of badChoices) {
					const choice = `${badChoice}, move tackle 1`;
					assert.false(battle.choose('p1', choice), `Choice '${choice}' should be rejected`);
				}

				assert(battle.choose('p1', `move 1 1 mega, move tackle 1`));
				assert(battle.choose('p2', `move Blaze Kick zmove 1, move irondefense`));
			});

			it('should handle Conversion 2', function () {
				battle = common.createBattle({gameType: 'doubles'});
				battle.join('p1', 'Guest 1', 1, [
					{species: "Porygon-Z", ability: 'adaptability', item: 'normaliumz', moves: ['conversion', 'conversion2']},
					{species: "Porygon", ability: 'download', moves: ['conversion', 'conversion2']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Gengar", ability: 'cursedbody', moves: ['lick']},
					{species: "Aggron", ability: 'sturdy', moves: ['irondefense']},
				]);

				assert(battle.choose('p1', `move 1, move Conversion 2 2`));
				assert.strictEqual(battle.p1.getChoice(), `move conversion, move conversion2 2`);
				battle.p1.clearChoice();

				assert.false(battle.choose('p1', `move 1, move Conversion -2`));
				battle.p1.clearChoice();

				assert(battle.choose('p1', `move Conversion 2 zmove 2, move 1`));
				assert.strictEqual(battle.p1.getChoice(), `move conversion2 2 zmove, move conversion`);
				battle.p1.clearChoice();
			});
		});

		describe('Singles', function () {
			it('should accept only `move` and `switch` choices', function () {
				battle = common.createBattle();
				battle.join('p1', 'Guest 1', 1, [
					{species: "Mew", ability: 'synchronize', moves: ['lunardance', 'recover']},
					{species: "Bulbasaur", ability: 'overgrow', moves: ['tackle', 'growl']},
				]);
				battle.join('p2', 'Guest 2', 1, [
					{species: "Rhydon", ability: 'prankster', moves: ['splash', 'horndrill']},
					{species: "Charmander", ability: 'blaze', moves: ['tackle', 'growl']},
				]);

				const validChoices = ['move 1', 'move 2', 'switch 2'];
				for (const action of validChoices) {
					assert(battle.choose('p1', action), `Choice '${action}' should be valid`);
					battle.p1.clearChoice();
				}

				const badChoices = ['move 1 zmove', 'move 2 mega', 'team 1', 'pass', 'shift'];
{'fraction_non_alphanumeric': 0.20396088933175563, 'fraction_numerical': 0.01432397085383322, 'mean_word_length': 4.181671506937722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '508113', 'n_tokens_mistral': 6672, 'n_tokens_neox': 5337, 'n_words': 1381}