github.com/exercism/configlet@v3.9.3-0.20200318193232-c70be6269e71+incompatible/track/exercise_readme_test.go (about) 1 package track 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestNewExerciseReadme(t *testing.T) { 11 root := filepath.FromSlash("../fixtures") 12 13 readme, err := NewExerciseReadme(root, "numbers", "one") 14 assert.NoError(t, err) 15 assert.Equal(t, "This is one.\n", readme.Spec.Description) 16 assert.Equal(t, "", readme.Hints) 17 assert.Equal(t, "Track insert.\n", readme.TrackInsert) 18 assert.Equal(t, "The {{ .Spec.Name }} exercise (from shared template).\n", readme.template) 19 20 readme, err = NewExerciseReadme(root, "numbers", "two") 21 assert.NoError(t, err) 22 assert.Equal(t, "This is two, customized.\n", readme.Spec.Description) 23 assert.Equal(t, "Hinting about two.\n", readme.Hints) 24 assert.Equal(t, "Track insert.\n", readme.TrackInsert) 25 assert.Equal(t, "{{ .Spec.Name }} has its own template with description:\n\n{{ .Spec.Description }}\n", readme.template) 26 } 27 28 func TestGenerateExerciseReadme(t *testing.T) { 29 tests := []struct { 30 desc string 31 Spec *ProblemSpecification 32 expected string 33 }{ 34 { 35 desc: "readme with title inferred from slug", 36 Spec: &ProblemSpecification{ 37 Slug: "hello-kitty", 38 Description: "The description.\n", 39 }, 40 expected: "# Hello Kitty\n\nThe description.\n", 41 }, 42 { 43 desc: "readme with a specified title", 44 Spec: &ProblemSpecification{ 45 Slug: "rna-transcription", 46 Title: "RNA Transcription", 47 Description: "The description.\n", 48 }, 49 expected: "# RNA Transcription\n\nThe description.\n", 50 }, 51 } 52 for _, test := range tests { 53 readme := ExerciseReadme{ 54 Spec: test.Spec, 55 template: "# {{ .Spec.Name }}\n\n{{ .Spec.Description -}}", 56 } 57 58 s, err := readme.Generate() 59 assert.NoError(t, err) 60 assert.Equal(t, test.expected, s, test.desc) 61 } 62 } 63 64 func TestExerciseReadmeTrackInsertDeprecation(t *testing.T) { 65 root := filepath.FromSlash("../fixtures/deprecated") 66 67 tests := []struct { 68 trackID string 69 expected string 70 }{ 71 {"inserts-both", "real insert\n"}, 72 {"inserts-old", "deprecated insert\n"}, 73 } 74 75 originalSpecPath := ProblemSpecificationsPath 76 ProblemSpecificationsPath = filepath.FromSlash("../fixtures/problem-specifications") 77 defer func() { ProblemSpecificationsPath = originalSpecPath }() 78 for _, test := range tests { 79 readme, err := NewExerciseReadme(root, test.trackID, "fake") 80 assert.NoError(t, err) 81 assert.Equal(t, test.expected, readme.TrackInsert) 82 } 83 } 84 85 func TestExerciseReadmeHintsDeprecation(t *testing.T) { 86 root := filepath.FromSlash("../fixtures/deprecated") 87 88 tests := []struct { 89 trackID string 90 expected string 91 }{ 92 {"hints-both", "real hints\n"}, 93 {"hints-old", "deprecated hints\n"}, 94 } 95 96 originalSpecPath := ProblemSpecificationsPath 97 ProblemSpecificationsPath = filepath.FromSlash("../fixtures/problem-specifications") 98 defer func() { ProblemSpecificationsPath = originalSpecPath }() 99 for _, test := range tests { 100 readme, err := NewExerciseReadme(root, test.trackID, "fake") 101 assert.NoError(t, err) 102 assert.Equal(t, test.expected, readme.Hints) 103 } 104 }