Spaces:
Sleeping
Sleeping
File size: 1,782 Bytes
2113a6a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import sys
import os
# Add project root to sys.path
sys.path.append(os.getcwd())
from compiler.parser_v2 import AbilityParserV2
from engine.models.ability import TriggerType, EffectType, TargetType, ConditionType
def test_negation():
parser = AbilityParserV2()
text = "TRIGGER: ON_PLAY\nCONDITION: !MOVED_THIS_TURN\nEFFECT: DRAW(1)"
abilities = parser.parse(text)
ability = abilities[0]
condition = ability.conditions[0]
print(f"Condition: {condition.type.name}, Negated: {condition.is_negated}")
assert condition.is_negated == True
def test_variable_targeting():
parser = AbilityParserV2()
# Sequence: Look Deck to Hand -> Draw for Target
text = "TRIGGER: ON_PLAY\nEFFECT: LOOK_DECK(3) -> CARD_HAND; DRAW(1) -> TARGET"
abilities = parser.parse(text)
effects = abilities[0].effects
print(f"Effect 0 Target: {effects[0].target.name}")
print(f"Effect 1 Target: {effects[1].target.name}")
assert effects[1].target == TargetType.CARD_HAND
def test_aliases():
parser = AbilityParserV2()
text = "TRIGGER: ON_YELL_SUCCESS\nEFFECT: CHARGE_SELF(1)"
abilities = parser.parse(text)
ability = abilities[0]
print(f"Trigger: {ability.trigger.name}")
print(f"Effect: {ability.effects[0].effect_type.name}, Target: {ability.effects[0].target.name}")
assert ability.trigger == TriggerType.ON_REVEAL
assert ability.effects[0].effect_type == EffectType.ENERGY_CHARGE
assert ability.effects[0].target == TargetType.MEMBER_SELF
if __name__ == "__main__":
try:
test_negation()
test_variable_targeting()
test_aliases()
print("All tests passed!")
except Exception as e:
print(f"Test failed: {e}")
import traceback
traceback.print_exc()
|