Beispiel #1
0
func TestCyclicDependencies(t *testing.T) {
	defer func() {
		recover()
	}()
	form := parser.ReadQL(
		strings.NewReader(`
		form SomeForm {
			"QuestionLabel" question1 string

			if(question3){
				"question2" question2 bool
			}

			if(question2){
				"question3" question3 bool
			}
		}
		`),
		"test.ql",
	)
	tc, st := New()
	tc.QuestionaireNode(form)
	if err := st.Err(); err == nil {
		t.Errorf("Typecheck error: cyclic dependencies should trigger error")
	}
}
Beispiel #2
0
func startInterpreter(srcReader io.Reader, srcFn string) (pipes *plumbing.Pipes,
	guiAppName string,
) {
	aQuestionaire := parser.ReadQL(srcReader, srcFn)
	pipes = interpreter.New(aQuestionaire)
	guiAppName = aQuestionaire.Label()
	return pipes, guiAppName
}
Beispiel #3
0
func TestDuplicatedIdentifier(t *testing.T) {
	form := parser.ReadQL(
		strings.NewReader(`form SomeForm {
			"QuestionLabel" question1 string
			"QuestionLabel" question1 string
		}`),
		"test.ql",
	)
	tc, st := New()
	tc.QuestionaireNode(form)
	if err := st.Err(); err == nil {
		t.Errorf("Typecheck error: duplicated identifiers should trigger error")
	}
}
Beispiel #4
0
func TestRepeatedCaptions(t *testing.T) {
	form := parser.ReadQL(
		strings.NewReader(`form SomeForm {
			"QuestionLabel" question1 string
			"QuestionLabel" question2 numeric
		}`),
		"test.ql",
	)
	tc, st := New()
	tc.QuestionaireNode(form)
	if warn := st.Warn(); warn == nil {
		t.Errorf("Typecheck error: duplicated captions should trigger warnings")
	}
}
Beispiel #5
0
func TestInvalidOperands(t *testing.T) {
	defer func() {
		recover()
	}()
	form := parser.ReadQL(
		strings.NewReader(`form SomeForm {
			"QuestionLabel" question1 string
			if (question1 + "string"){}
		}`),
		"test.ql",
	)
	tc, st := New()
	tc.QuestionaireNode(form)
	if err := st.Err(); err == nil {
		t.Errorf("Typecheck error: invalid operations should trigger error")
	}
}
Beispiel #6
0
func TestDuplicatedIdentifierInIfBlocks(t *testing.T) {
	form := parser.ReadQL(
		strings.NewReader(`form SomeForm {
			"QuestionLabel" question1 bool
			if (question1){
				"QuestionLabel2 - True" question2 string
			}
			if (!question1){
				"QuestionLabel2 - False" question2 string
			}
		}`),
		"test.ql",
	)
	tc, st := New()
	tc.QuestionaireNode(form)
	if err := st.Err(); err == nil {
		t.Errorf("Typecheck error: duplicated identifiers should trigger error")
	}
}
func runForm(source string) *plumbing.Pipes {
	form := parser.ReadQL(strings.NewReader(source), "test.ql")
	return New(form)
}