func NewIntegerTypeNode(typeTokenLit attrib) (interfaces.IntegerType, error) {
	token := typeTokenLit.(*token.Token)
	expr := expr.NewIntegerType()
	expr.SetSourceInfo(token.Pos)

	return expr, nil
}
func TestNewVarDecl(t *testing.T) {
	varID := NewVarID("testVarID")
	valueType := expr.NewIntegerType()
	varDecl := NewVarDecl(varID, valueType)

	assert.Equal(t, varDecl.VariableIdentifier(), varID)
	assert.Equal(t, varDecl.ValueType(), valueType)
}
func TestComputedQuestion(t *testing.T) {
	exampleLabel := expr.NewStringLiteral("Value residue")
	exampleVarDecl := vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewIntegerType())
	exampleComputation := expr.NewSub(expr.NewIntegerLiteral(10), expr.NewIntegerLiteral(5))

	exampleQuestion := NewComputedQuestion(exampleLabel, exampleVarDecl, exampleComputation)

	assert.Equal(t, exampleQuestion.Label(), exampleLabel)
	assert.Equal(t, exampleQuestion.Computation(), exampleComputation)
}
func (suite *TypeCheckerTestSuite) TestUndefinedQuestionReferenceChecker() {
	computedQuestion := stmt.NewComputedQuestion(expr.NewStringLiteral("Value residue:"), vari.NewVarDecl(vari.NewVarID("valueResidue"), expr.NewIntegerType()), expr.NewSub(expr.NewIntegerLiteral(100), expr.NewVarExpr(vari.NewVarID("hasMaintLoan"))))
	exampleBody := stmt.NewStmtList([]interfaces.Question{computedQuestion}, []interfaces.Conditional{})
	exampleForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBody)

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForForm(exampleForm, errors.UndefinedQuestionReferenceError{}, 1)
}
func (suite *TypeCheckerTestSuite) TestThatCorrectFormYieldsNoErrorsOrWarnings() {
	firstQuestion := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewBoolType()))
	firstQuestionBody := stmt.NewInputQuestion(expr.NewStringLiteral("What was the selling price?"), vari.NewVarDecl(vari.NewVarID("sellingPrice"), expr.NewIntegerType()))
	ifBody := stmt.NewStmtList([]interfaces.Question{firstQuestionBody}, []interfaces.Conditional{})
	elseBody := stmt.NewStmtList([]interfaces.Question{firstQuestionBody}, []interfaces.Conditional{})
	ifExample := stmt.NewIfElse(expr.NewBoolLiteral(true), ifBody, elseBody)
	exampleBody := stmt.NewStmtList([]interfaces.Question{firstQuestion}, []interfaces.Conditional{ifExample})
	exampleForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBody)

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForForm(exampleForm, errors.TypeCheckError{}, 0)
}
func (suite *TypeCheckerTestSuite) TestDuplicateVarDeclChecker() {
	firstQuestion := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewBoolType()))
	secondQuestion := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewIntegerType()))
	exampleBody := stmt.NewStmtList([]interfaces.Question{firstQuestion, secondQuestion}, []interfaces.Conditional{})
	exampleForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBody)

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForForm(exampleForm, errors.QuestionRedeclaredWithDifferentTypesError{}, 1)
}
func TestFormIfElse(t *testing.T) {
	exampleFormInput := "form TestForm { \"Did you sell a house in 2010?\" hasSoldHouse: boolean if (true) { \"What was the selling price?\" sellingPrice: integer } else { \"What was the selling price?\" sellingPrice: integer } }"
	firstQuestionOutput := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewBoolType()))
	firstQuestionBodyInput := stmt.NewInputQuestion(expr.NewStringLiteral("What was the selling price?"), vari.NewVarDecl(vari.NewVarID("sellingPrice"), expr.NewIntegerType()))
	ifBodyOutput := stmt.NewStmtList([]interfaces.Question{firstQuestionBodyInput}, []interfaces.Conditional{})
	elseBodyOutput := stmt.NewStmtList([]interfaces.Question{firstQuestionBodyInput}, []interfaces.Conditional{})
	ifOutput := stmt.NewIfElse(expr.NewBoolLiteral(true), ifBodyOutput, elseBodyOutput)
	exampleBodyOutput := stmt.NewStmtList([]interfaces.Question{firstQuestionOutput}, []interfaces.Conditional{ifOutput})
	exampleOutputForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBodyOutput)

	testStmtParse(t, exampleFormInput, exampleOutputForm)
}
func TestFormComputedQuestion(t *testing.T) {
	exampleFormInput := "form TestForm { \"Did you sell a house in 2010?\" hasSoldHouse: integer \"Did you enter a loan?\" hasMaintLoan: integer \"Value residue:\" valueResidue: integer = (hasSoldHouse - hasMaintLoan) }"

	firstQuestionOutput := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewIntegerType()))
	secondQuestionOutput := stmt.NewInputQuestion(expr.NewStringLiteral("Did you enter a loan?"), vari.NewVarDecl(vari.NewVarID("hasMaintLoan"), expr.NewIntegerType()))
	computedQuestion := stmt.NewComputedQuestion(expr.NewStringLiteral("Value residue:"), vari.NewVarDecl(vari.NewVarID("valueResidue"), expr.NewIntegerType()), expr.NewSub(expr.NewVarExpr(vari.NewVarID("hasSoldHouse")), expr.NewVarExpr(vari.NewVarID("hasMaintLoan"))))
	exampleBodyOutput := stmt.NewStmtList([]interfaces.Question{firstQuestionOutput, secondQuestionOutput, computedQuestion}, []interfaces.Conditional{})
	exampleOutputForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBodyOutput)

	testStmtParse(t, exampleFormInput, exampleOutputForm)
}
func TestIfElse(t *testing.T) {
	ifQuestionExample := NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewBoolType()))
	ifBodyExample := NewStmtList([]interfaces.Question{ifQuestionExample}, []interfaces.Conditional{})
	ifCondExample := expr.NewBoolLiteral(true)

	elseQuestionExample := NewInputQuestion(expr.NewStringLiteral("What was the selling price?"), vari.NewVarDecl(vari.NewVarID("sellingPrice"), expr.NewIntegerType()))
	elseBodyExample := NewStmtList([]interfaces.Question{elseQuestionExample}, []interfaces.Conditional{})

	ifElseExample := NewIfElse(ifCondExample, ifBodyExample, elseBodyExample)

	assert.True(t, util.AreStmtListsEqual(ifElseExample.IfBody(), ifBodyExample))
	assert.True(t, util.AreStmtListsEqual(ifElseExample.ElseBody(), elseBodyExample))
	assert.Equal(t, ifElseExample.Condition(), ifCondExample)
	assert.Equal(t, true, ifElseExample.EvalConditionAsBool(nil))
}
func TestIf(t *testing.T) {
	questionExample := NewInputQuestion(expr.NewStringLiteral("What was the selling price?"), vari.NewVarDecl(vari.NewVarID("sellingPrice"), expr.NewIntegerType()))
	ifBodyExample := NewStmtList([]interfaces.Question{questionExample}, []interfaces.Conditional{})
	ifCondExample := expr.NewBoolLiteral(true)
	ifExample := NewIf(ifCondExample, ifBodyExample)

	assert.True(t, util.AreStmtListsEqual(ifExample.Body(), ifBodyExample))
	assert.Equal(t, ifExample.Condition(), ifCondExample)
	assert.Equal(t, true, ifExample.EvalConditionAsBool(nil))
}
func TestFormWithNonEmptyContent(t *testing.T) {
	identifier := vari.NewVarID("TestForm")
	questionExample := NewInputQuestion(expr.NewStringLiteral("What was the selling price?"), vari.NewVarDecl(vari.NewVarID("sellingPrice"), expr.NewIntegerType()))
	questionsListExample := []interfaces.Question{questionExample}
	stmtListExample := NewStmtList(questionsListExample, []interfaces.Conditional{})
	exampleForm := NewForm(identifier, stmtListExample)

	assert.Equal(t, len(exampleForm.Content().Questions()), 1)
	assert.True(t, util.AreStmtListsEqual(exampleForm.Content(), stmtListExample))
}