func TestJSONInputFrontend(t *testing.T) { pipes := plumbing.New() buf := new(bytes.Buffer) go fakeInterpreter(pipes) Write(pipes, buf) if got := buf.String(); got != expectedJSON { t.Error( "Error generating output JSON file. Expected "+expectedJSON+" rows. Got:", got, ) } }
func TestCsvInputFrontend(t *testing.T) { pipes := plumbing.New() buf := new(bytes.Buffer) go fakeInterpreter(pipes) Write(pipes, buf) if got := buf.String(); got != expectedCsv { t.Error( "Error generating output CSV file. Expected Q1,A question,No rows. Got:", got, ) } }
func TestJSONinputFrontend(t *testing.T) { pipes := plumbing.New() expectedAnswers := make(chan map[string]string) fakeInterpreter(pipes, expectedAnswers) go Read(pipes, strings.NewReader(fakeCsv)) got := <-expectedAnswers rowcount := len(got) if rowcount != 2 { t.Error( "Error parsing input JSON file. Expected 2 rows. Got:", rowcount, ) } }
// New starts interpreter with an AST (*ast.Questionaire) and with // channels to communicate with Frontend process. func New(q *ast.QuestionaireNode) *plumbing.Pipes { typecheck(q) pipes := plumbing.New() st := symboltable.New() v := &interpreter{ questionaire: q, send: pipes.ToFrontend(), receive: pipes.FromFrontend(), execute: execute.New(pipes.ToFrontend(), st), draw: draw.New(pipes.ToFrontend()), symbols: st, } go v.loop() return pipes }