Exemple #1
0
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,
		)
	}
}
Exemple #2
0
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,
		)
	}
}
Exemple #3
0
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,
		)
	}
}
Exemple #4
0
// 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
}