<commit_before>
import RG from '../../../client/src/rg';
import chai from 'chai';

import {Objects} from '../../../client/data/battles_objects';
import {RGTest} from '../../roguetest';
import {RGUnitTests} from '../../rg.unit-tests';
import {Effects} from '../../../client/data/effects';
import {chaiBattles} from '../../helpers/chai-battles';
import {SentientActor } from '../../../client/src/actor';
import {ObjectShell} from '../../../client/src/objectshellparser';
import {FactoryActor} from '../../../client/src/factory.actors';
import {FactoryLevel} from '../../../client/src/factory.level';
import {FactoryBase as Factory} from '../../../client/src/factory';
import {FromJSON} from '../../../client/src/game.fromjson';

const expect = chai.expect;
chai.use(chaiBattles);

const Parser = ObjectShell.Parser;
const Creator = ObjectShell.Creator;

const Actor = SentientActor;
RG.cellRenderArray = RG.cellRenderVisible;

const wolfShell = {
    name: 'wolf', attack: 15, defense: 10, damage: '1d6 + 2',
    hp: 9
};

const factLevel = new FactoryLevel();

//---------------------------------------------------------------------------
// PARSER TESTS
//---------------------------------------------------------------------------

describe('ObjectShell.Parser', () => {

    it('Returns base objects and supports also base', () => {
        const parser = new Parser();
        const wolfNew = parser.parseObjShell('actors', wolfShell);
        expect(wolfNew.attack).to.equal(15);
        expect(wolfNew.defense).to.equal(10);

        const wolves = parser.dbGet({categ: 'actors', danger: 3});
        expect(wolves.hasOwnProperty('superwolf')).to.equal(false);

        const superWolf = parser.parseObjShell('actors', {
            name: 'superwolf', base: 'wolf', defense: 20,
            damage: '2d6 + 3', danger: 3
        });
        expect(superWolf.attack).to.equal(15);
        expect(superWolf.defense).to.equal(20);

        const objWolf = parser.dbGet({name: 'wolf'})[0];
        expect(objWolf).to.equal(wolfNew);

        const wolfPack = parser.dbGet({categ: 'actors', danger: 3});
        expect(wolfPack.hasOwnProperty('superwolf')).to.equal(true);
        const wolf1 = wolfPack['superwolf'];
        expect(wolf1).to.equal(superWolf);

        // Create a reference actor
        const wolfObj = new Actor('wolf');
        wolfObj.setType('wolf');
        wolfObj.get('Combat').setAttack(15);
        wolfObj.get('Combat').setDefense(10);
        wolfObj.get('Combat').setDamageDie('1d6 + 2');
        wolfObj.get('Health').setHP(9);
        const wolfComp = wolfObj.get('Combat');

        // Create actor using parsed shell data
        const createdWolf = parser.createActualObj('actors', 'wolf');
        const cWolfComp = createdWolf.get('Combat');
        expect(cWolfComp.getAttack()).to.equal(wolfComp.getAttack());
        expect(cWolfComp.getDefense()).to.equal(wolfComp.getDefense());
        expect(createdWolf.getType()).to.equal(wolfObj.getType());

        RGTest.expectEqualHealth(createdWolf, wolfObj);

        const player = new FactoryActor().createPlayer('player', {});
        const cell = new Factory().createFloorCell();
        cell.setProp('actors', player);
        cell.setExplored(true);

        expect(RG.getCellChar(cell)).to.equal('X');

        const randWolf = parser.createRandomActor({danger: 3});
        expect(randWolf !== null).to.equal(true);
        expect(randWolf.get('Combat').getAttack()).to.equal(superWolf.attack);

        const punyWolf = parser.parseObjShell('actors', {name: '<NAME>',
            base: 'wolf', attack: 1, defense: 50}
        );
        expect(punyWolf.attack).to.equal(1);
<commit_msg>Corrected failing test by adding /[X@]/ as possible char for player.<commit_after>
import RG from '../../../client/src/rg';
import chai from 'chai';

import {Objects} from '../../../client/data/battles_objects';
import {RGTest} from '../../roguetest';
import {RGUnitTests} from '../../rg.unit-tests';
import {Effects} from '../../../client/data/effects';
import {chaiBattles} from '../../helpers/chai-battles';
import {SentientActor } from '../../../client/src/actor';
import {ObjectShell} from '../../../client/src/objectshellparser';
import {FactoryActor} from '../../../client/src/factory.actors';
import {FactoryLevel} from '../../../client/src/factory.level';
import {FactoryBase as Factory} from '../../../client/src/factory';
import {FromJSON} from '../../../client/src/game.fromjson';

const expect = chai.expect;
chai.use(chaiBattles);

const Parser = ObjectShell.Parser;
const Creator = ObjectShell.Creator;

const Actor = SentientActor;
RG.cellRenderArray = RG.cellRenderVisible;

const wolfShell = {
    name: 'wolf', attack: 15, defense: 10, damage: '1d6 + 2',
    hp: 9
};

const factLevel = new FactoryLevel();

//---------------------------------------------------------------------------
// PARSER TESTS
//---------------------------------------------------------------------------

describe('ObjectShell.Parser', () => {

    it('Returns base objects and supports also base', () => {
        const parser = new Parser();
        const wolfNew = parser.parseObjShell('actors', wolfShell);
        expect(wolfNew.attack).to.equal(15);
        expect(wolfNew.defense).to.equal(10);

        const wolves = parser.dbGet({categ: 'actors', danger: 3});
        expect(wolves.hasOwnProperty('superwolf')).to.equal(false);

        const superWolf = parser.parseObjShell('actors', {
            name: 'superwolf', base: 'wolf', defense: 20,
            damage: '2d6 + 3', danger: 3
        });
        expect(superWolf.attack).to.equal(15);
        expect(superWolf.defense).to.equal(20);

        const objWolf = parser.dbGet({name: 'wolf'})[0];
        expect(objWolf).to.equal(wolfNew);

        const wolfPack = parser.dbGet({categ: 'actors', danger: 3});
        expect(wolfPack.hasOwnProperty('superwolf')).to.equal(true);
        const wolf1 = wolfPack['superwolf'];
        expect(wolf1).to.equal(superWolf);

        // Create a reference actor
        const wolfObj = new Actor('wolf');
        wolfObj.setType('wolf');
        wolfObj.get('Combat').setAttack(15);
        wolfObj.get('Combat').setDefense(10);
        wolfObj.get('Combat').setDamageDie('1d6 + 2');
        wolfObj.get('Health').setHP(9);
        const wolfComp = wolfObj.get('Combat');

        // Create actor using parsed shell data
        const createdWolf = parser.createActualObj('actors', 'wolf');
        const cWolfComp = createdWolf.get('Combat');
        expect(cWolfComp.getAttack()).to.equal(wolfComp.getAttack());
        expect(cWolfComp.getDefense()).to.equal(wolfComp.getDefense());
        expect(createdWolf.getType()).to.equal(wolfObj.getType());

        RGTest.expectEqualHealth(createdWolf, wolfObj);

        const player = new FactoryActor().createPlayer('player', {});
        const cell = new Factory().createFloorCell();
        cell.setProp('actors', player);
        cell.setExplored(true);

        expect(RG.getCellChar(cell)).to.match(/[@X]/);

        const randWolf = parser.createRandomActor({danger: 3});
        expect(randWolf !== null).to.equal(true);
        expect(randWolf.get('Combat').getAttack()).to.equal(superWolf.attack);

        const punyWolf = parser.parseObjShell('actors', {name: '<NAME>',
            base: 'wolf', attack: 1, defense: 50}
        );
        expect(punyWolf.attack).to.equal(1);

{'fraction_non_alphanumeric': 0.21253369272237196, 'fraction_numerical': 0.01078167115902965, 'mean_word_length': 2.6024271844660194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1878824', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2159, 'n_words': 434}