spudplate
Template scaffolding compiler for spudlang .spud files
Loading...
Searching...
No Matches
spudplate::ScriptedPrompter Class Reference

Test prompter: replays a fixed sequence of canned answers. More...

#include <interpreter.h>

Inheritance diagram for spudplate::ScriptedPrompter:
spudplate::Prompter

Public Member Functions

 ScriptedPrompter (std::vector< std::string > answers)
 Construct with the canned answers prompt will replay in order.
 
std::string prompt (const PromptRequest &req) override
 Display the prompt described by req and return the user's raw answer.
 
bool authorize (const std::string &summary) override
 Display a security summary and return whether to proceed.
 
const std::optional< PromptRequest > & last_request () const
 Most recent request seen, for assertions on rendering inputs.
 
const std::vector< PromptRequest > & requests () const
 Every request seen so far, in order.
 
void set_authorize_response (bool value)
 Set what authorize returns.
 
const std::optional< std::string > & last_authorize_summary () const
 Most recent authorize summary seen, for assertions.
 

Detailed Description

Test prompter: replays a fixed sequence of canned answers.

Constructed with a vector of strings; each call to prompt consumes the next answer. Calling prompt after the queue is exhausted throws std::logic_error, so test retry-loop bugs cannot hang.

Member Function Documentation

◆ prompt()

std::string spudplate::ScriptedPrompter::prompt ( const PromptRequest req)
overridevirtual

Display the prompt described by req and return the user's raw answer.

The interpreter parses the returned string, validates it against type and options, and on rejection calls back with previous_error set. Implementations deliver one raw line per call.

Implements spudplate::Prompter.

◆ authorize()

bool spudplate::ScriptedPrompter::authorize ( const std::string &  summary)
overridevirtual

Display a security summary and return whether to proceed.

Called once, before any statement runs, when the program contains run clauses. The summary is multi-line and lists every literal command that may execute. Returning false aborts the run cleanly with no side effects.

Implements spudplate::Prompter.

◆ requests()

const std::vector< PromptRequest > & spudplate::ScriptedPrompter::requests ( ) const
inline

Every request seen so far, in order.

Useful for asserting on counter, indent, or iteration sequences across a multi-prompt run.

◆ set_authorize_response()

void spudplate::ScriptedPrompter::set_authorize_response ( bool  value)
inline

Set what authorize returns.

Defaults to true (accept).