36 lines
1012 B
Python
36 lines
1012 B
Python
from __future__ import annotations
|
|
|
|
from src.engine import StoryEngine
|
|
from src.parser import parse_story
|
|
|
|
|
|
def test_branch_and_effects() -> None:
|
|
parsed = parse_story("data/main_story.yaml")
|
|
engine = StoryEngine(parsed.story)
|
|
|
|
assert engine.current_node_id == "intro"
|
|
|
|
intro_options = engine.get_visible_options()
|
|
assert len(intro_options) == 2
|
|
|
|
# Choose alley, then pick lamp.
|
|
engine.choose(1)
|
|
assert engine.current_node_id == "alley"
|
|
engine.choose(0)
|
|
assert engine.current_node_id == "gate"
|
|
|
|
options = engine.get_visible_options()
|
|
option_texts = [o.text for o in options]
|
|
assert "用油灯照亮告示" in option_texts
|
|
|
|
|
|
def test_condition_hides_option() -> None:
|
|
parsed = parse_story("data/main_story.yaml")
|
|
engine = StoryEngine(parsed.story)
|
|
|
|
# intro -> gate without taking lamp
|
|
engine.choose(0)
|
|
options = engine.get_visible_options()
|
|
option_texts = [o.text for o in options]
|
|
assert "用油灯照亮告示" not in option_texts
|