TableTower/tests/test_demos.gd

47 lines
2 KiB
GDScript3
Raw Normal View History

extends TestBase
## Help's demo spreads: every demo builds and rolls cleanly, Help links to
## them, and opening one shows it unsaved with a way back.
## Run: godot --headless --path . -s res://tests/test_demos.gd -- --sample
func _init() -> void:
if not require_sample():
return
_test_builds()
if not await start_main():
return
await _test_open()
finish()
func _test_builds() -> void:
var rng := RandomNumberGenerator.new()
for key: String in DemoSpreads.TITLES:
var b := DemoSpreads.build(key)
_check(not b.tables.is_empty() and b.id == "demo-" + key, "demo %s builds" % key)
var start := b.tables[0] if b.tables[0].kind != RollTable.KIND_VARIABLE else b.tables[1]
var tree := Roller.roll(b, start.id, rng)
var bad := Roller.flatten(tree, []).filter(func(s: Dictionary) -> bool: return s.get("stop", false) and not s.get("deck_empty", false))
_check(bad.is_empty(), "demo %s rolls cleanly: %s" % [key, str(bad.map(func(s: Dictionary) -> String: return str(s.get("text", ""))))])
var book := DemoSpreads.build("book")
_check(book.page_uses("p_sword") == 2, "the Book demo links two results to its page")
var linked := book.get_table("goblin").entries[1]
book.sync_page("p_sword")
_check(linked.text.contains("Holy Light"), "and they show the page's text")
var help := FileAccess.get_file_as_string("res://help/topics.txt")
var re := RegEx.create_from_string("\\[demo\\]([a-z_]+)\\[/demo\\]")
for m in re.search_all(help):
_check(DemoSpreads.has(m.get_string(1)), "help's demo link %s exists" % m.get_string(1))
_check(HelpDialog._inline("[demo]deck[/demo]").contains("url=demo:deck"), "a demo marker becomes a link")
func _test_open() -> void:
var before := main.data.id
main.demo.open("deck")
await _frames(3)
_check(main.data.id == "demo-deck" and main.demo.active() and not main._saving_enabled, "a demo opens unsaved, with its bar")
main.demo.back()
await _frames(3)
_check(not main.demo.active() and main.data.id == before, "Back to my spread returns")