2023-07-10 13:23:46 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2023-11-13 21:01:12 +01:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2023-07-10 13:23:46 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/remogatto/prettytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testSuite struct {
|
|
|
|
prettytest.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunner(t *testing.T) {
|
|
|
|
prettytest.Run(
|
|
|
|
t,
|
|
|
|
new(testSuite),
|
|
|
|
)
|
|
|
|
}
|
2023-11-13 21:01:12 +01:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
quiz, _, err := MarkdownToQuiz(markdown)
|
|
|
|
t.Nil(err, fmt.Sprintf("Quiz should be parsed without errors: %v", err))
|
|
|
|
|
|
|
|
if !t.Failed() {
|
|
|
|
t.True(reflect.DeepEqual(quiz, expectedQuiz), fmt.Sprintf("Expected %+v, got %+v", expectedQuiz, quiz))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|