package models import ( "fmt" "reflect" "testing" "github.com/remogatto/prettytest" ) type testSuite struct { prettytest.Suite } func TestRunner(t *testing.T) { prettytest.Run( t, new(testSuite), new(groupTestSuite), ) } func (t *testSuite) TestQuizFromMarkdown() { markdown := `Question text (1). Question text (2). Question text with #tag1 #tag2 (3). * Answer 1 * Answer 2 * Answer 3 * Answer 4` expectedQuiz := &Quiz{ Question: &Question{Text: "Question text (1).\n\nQuestion text (2).\n\nQuestion text with #tag1 #tag2 (3)."}, Answers: []*Answer{ {Text: "Answer 1"}, {Text: "Answer 2"}, {Text: "Answer 3"}, {Text: "Answer 4"}, }, CorrectPos: 0, } q := new(Quiz) err := MarkdownToQuiz(q, markdown) t.Nil(err, fmt.Sprintf("Quiz should be parsed without errors: %v", err)) if !t.Failed() { t.True(reflect.DeepEqual(q, expectedQuiz), fmt.Sprintf("Expected %+v got %+v", expectedQuiz, q)) } } func (t *testSuite) TestMarkdownFromQuiz() { quiz := &Quiz{ Question: &Question{Text: "Newly created question text."}, Answers: []*Answer{ {Text: "Answer 1"}, {Text: "Answer 2"}, {Text: "Answer 3"}, {Text: "Answer 4"}, }, CorrectPos: 0, } md, err := QuizToMarkdown(quiz) t.Nil(err, fmt.Sprintf("Conversion to markdown should not raise an error: %v", err)) if !t.Failed() { t.Equal(`Newly created question text. * Answer 1 * Answer 2 * Answer 3 * Answer 4 `, md) } }