use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityTest method testTypeMatchWithServesAs.
/**
* Test the function of the SERVESAS token with type matching
* @throws PersistenceLayerException
*/
public void testTypeMatchWithServesAs() throws PersistenceLayerException {
Ability pa = TestHelper.makeAbility("Power Attack", AbilityCategory.FEAT, "Fighter");
Ability ab2 = TestHelper.makeAbility("Dancer", "BARDIC", "General.Bardic");
ab2.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
ab2.addToListFor(ListKey.SERVES_AS_ABILITY, CDOMDirectSingleRef.getRef(pa));
PlayerCharacter character = getCharacter();
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.BARDIC,TYPE.General", false, false);
assertFalse("Test general type match with no abilities.", PrereqHandler.passes(prereq, character, null));
Prerequisite prereq2 = parser.parse("ability", "1,CATEGORY.BARDIC,TYPE.Bardic", false, false);
assertFalse("Test bardic type match with no abilities.", PrereqHandler.passes(prereq2, character, null));
Prerequisite prereq3 = parser.parse("ability", "1,CATEGORY.BARDIC,TYPE.Fighter", false, false);
assertFalse("Test fighter type match with no abilities.", PrereqHandler.passes(prereq3, character, null));
addAbility(TestHelper.getAbilityCategory(ab2), ab2);
assertTrue("Test general type match with an ability.", PrereqHandler.passes(prereq, character, null));
assertTrue("Test bardic type match with an ability.", PrereqHandler.passes(prereq2, character, null));
assertTrue("Test fighter type match with SERVESAS ability.", PrereqHandler.passes(prereq3, character, null));
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityTest method testCategoryMatch.
/**
* Test the function of the category matching
* @throws PersistenceLayerException
*/
public void testCategoryMatch() 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 prereq2 = parser.parse("ability", "1,CATEGORY.BARDIC,ANY", false, false);
assertFalse("Test bardic match with no abilities.", PrereqHandler.passes(prereq2, character, null));
Prerequisite prereq3 = parser.parse("ability", "1,CATEGORY.FEAT,ANY", false, false);
assertFalse("Test feat match with no abilities.", PrereqHandler.passes(prereq3, character, null));
addAbility(TestHelper.getAbilityCategory(ab2), ab2);
assertTrue("Test bardic match with an ability.", PrereqHandler.passes(prereq2, character, null));
assertFalse("Test feat match with an ability.", PrereqHandler.passes(prereq3, character, null));
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityTest method testKeyMatchWithServesAs.
/**
* Test the function of the SERVESAS token with direct key matching
* @throws PersistenceLayerException
*/
public void testKeyMatchWithServesAs() throws PersistenceLayerException {
Ability fd = TestHelper.makeAbility("Dancer", AbilityCategory.FEAT, "General");
Ability ab2 = TestHelper.makeAbility("Dancer", "BARDIC", "General.Bardic");
Ability strangeness = TestHelper.makeAbility("Strangeness", "BARDIC", "General");
ab2.addToListFor(ListKey.SERVES_AS_ABILITY, CDOMDirectSingleRef.getRef(fd));
ab2.addToListFor(ListKey.SERVES_AS_ABILITY, CDOMDirectSingleRef.getRef(strangeness));
ab2.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
PlayerCharacter character = getCharacter();
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.BARDIC,KEY_Dancer", false, false);
assertFalse("Test any match with no abilities.", PrereqHandler.passes(prereq, character, null));
Prerequisite prereq2 = parser.parse("ability", "1,CATEGORY.BARDIC,KEY_Alertness", false, false);
assertFalse("Test bardic match with no abilities.", PrereqHandler.passes(prereq2, character, null));
Prerequisite prereq3 = parser.parse("ability", "1,CATEGORY.FEAT,KEY_Dancer", false, false);
assertFalse("Test feat match with no abilities.", PrereqHandler.passes(prereq3, character, null));
addAbility(TestHelper.getAbilityCategory(ab2), ab2);
assertTrue("Test any match with an ability.", PrereqHandler.passes(prereq, character, null));
assertFalse("Servesas non existant ability should not cause match.", PrereqHandler.passes(prereq2, character, null));
assertTrue("Servesas should cause match.", PrereqHandler.passes(prereq3, character, null));
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityParserTest method testCategoryInterpretation.
/**
* @throws Exception
*/
@Test
public void testCategoryInterpretation() throws Exception {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,Sneak Attack", false, false);
assertEquals("Category specified for single key", "<prereq operator=\"GTEQ\" operand=\"1\" >\n" + "<prereq kind=\"ability\" count-multiples=\"true\" category=\"Mutation\" key=\"Sneak Attack\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n" + "", prereq.toString());
prereq = parser.parse("ability", "2,CATEGORY=Mutation,Foo,Bar", false, false);
assertEquals("Category specified for multiple keys", "<prereq operator=\"GTEQ\" operand=\"2\" >\n" + "<prereq kind=\"ability\" count-multiples=\"true\" category=\"Mutation\" key=\"Foo\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "<prereq kind=\"ability\" count-multiples=\"true\" category=\"Mutation\" key=\"Bar\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n" + "", prereq.toString());
prereq = parser.parse("ability", "1,CATEGORY.ANY,Sneak Attack", false, false);
assertEquals("Category of ANY specified for single key", "<prereq operator=\"GTEQ\" operand=\"1\" >\n" + "<prereq kind=\"ability\" count-multiples=\"true\" key=\"Sneak Attack\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n" + "", prereq.toString());
prereq = parser.parse("ability", "1,CATEGORY.ANY,Foo,Bar", false, false);
assertEquals("Category specified for multiple key", "<prereq operator=\"GTEQ\" operand=\"1\" >\n" + "<prereq kind=\"ability\" count-multiples=\"true\" key=\"Foo\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "<prereq kind=\"ability\" count-multiples=\"true\" key=\"Bar\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n" + "", prereq.toString());
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityParserTest method testNegates.
/**
* @throws Exception
*/
@Test
public void testNegates() throws Exception {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,Sneak Attack,[Alertness]", false, false);
assertEquals("Negated entry should be parsed", "<prereq operator=\"GTEQ\" operand=\"2\" >\n" + "<prereq kind=\"ability\" count-multiples=\"true\" key=\"Sneak Attack\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "<prereq kind=\"ability\" count-multiples=\"true\" key=\"Alertness\" operator=\"LT\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n", prereq.toString());
}
Aggregations