Search in sources :

Example 6 with PreAbilityParser

use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.

the class PreAbilityParserTest method testSingleEntry.

/**
	 * @throws Exception
	 */
@Test
public void testSingleEntry() throws Exception {
    PreAbilityParser parser = new PreAbilityParser();
    Prerequisite prereq = parser.parse("ability", "1,Sneak Attack", false, false);
    assertEquals("Category not specified for single key", "<prereq kind=\"ability\" key=\"Sneak Attack\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "", prereq.toString());
}
Also used : PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 7 with PreAbilityParser

use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.

the class PreAbilityParserTest method testInvalidCharacter.

/**
	 * Test that an error is produced if separators are incorrect
	 * @throws Exception
	 */
@Test
public void testInvalidCharacter() throws Exception {
    try {
        PreAbilityParser parser = new PreAbilityParser();
        Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,KEY_a|Key_b", false, false);
        fail("Should have thrown a PersistenceLayerException.");
    } catch (PersistenceLayerException e) {
    // Ignore, this is the expected result.
    }
}
Also used : PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 8 with PreAbilityParser

use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.

the class PreAbilityParserTest method testInvalidSeparators.

/**
	 * Test that an error is produced if separators are incorrect
	 * @throws Exception
	 */
@Test
public void testInvalidSeparators() throws Exception {
    try {
        PreAbilityParser parser = new PreAbilityParser();
        Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,,KEY_a", false, false);
        fail("Should have thrown a PersistenceLayerException.");
    } catch (PersistenceLayerException e) {
    // Ignore, this is the expected result.
    }
}
Also used : PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 9 with PreAbilityParser

use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.

the class PreAbilityParserTest method testNoKey.

/**
	 * @throws Exception
	 */
@Test
public void testNoKey() throws Exception {
    PreAbilityParser parser = new PreAbilityParser();
    Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation", false, false);
    assertEquals("Category specified for no key", "<prereq kind=\"ability\" category=\"Mutation\" key=\"ANY\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "", prereq.toString());
}
Also used : PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 10 with PreAbilityParser

use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.

the class PreAbilityTest method testAnyMatch.

/**
	 * Test the function of the ANY key 
	 * @throws PersistenceLayerException
	 */
public void testAnyMatch() throws PersistenceLayerException {
    Ability ab2 = TestHelper.makeAbility("Dancer", "BARDIC", "General.Bardic");
    ab2.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
    PlayerCharacter character = getCharacter();
    PreAbilityParser parser = new PreAbilityParser();
    Prerequisite prereq = parser.parse("ability", "1,CATEGORY.BARDIC,ANY", false, false);
    assertFalse("Test any match with no abilities.", PrereqHandler.passes(prereq, character, null));
    addAbility(TestHelper.getAbilityCategory(ab2), ab2);
    assertTrue("Test any match with an ability.", PrereqHandler.passes(prereq, character, null));
}
Also used : Ability(pcgen.core.Ability) PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) PlayerCharacter(pcgen.core.PlayerCharacter)

Aggregations

PreAbilityParser (plugin.pretokens.parser.PreAbilityParser)17 Ability (pcgen.core.Ability)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 Prerequisite (pcgen.core.prereq.Prerequisite)8 Test (org.junit.Test)7 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)3 AbilityFacade (pcgen.facade.core.AbilityFacade)1 PreAbilityWriter (plugin.pretokens.writer.PreAbilityWriter)1