github.com/exercism/configlet@v3.9.3-0.20200318193232-c70be6269e71+incompatible/track/exercise_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 TestExerciseSlug(t *testing.T) {
    11  	path := filepath.FromSlash("../fixtures/fake-exercise")
    12  
    13  	ex, err := NewExercise(path, PatternGroup{})
    14  	assert.NoError(t, err)
    15  	assert.Equal(t, "fake-exercise", ex.Slug)
    16  }
    17  
    18  func TestExerciseSolutionPaths(t *testing.T) {
    19  	tests := []struct {
    20  		PatternGroup
    21  		path string
    22  	}{
    23  		{
    24  			// It finds files in the root of the exercise directory.
    25  			PatternGroup{SolutionPattern: "[Ee]xample"},
    26  			"example.ext",
    27  		},
    28  		{
    29  			// It finds files in a subdirectory.
    30  			PatternGroup{SolutionPattern: "solution"},
    31  			"subdir/solution.ext",
    32  		},
    33  		{
    34  			// It only matches files, not directories.
    35  			PatternGroup{SolutionPattern: "subdir"},
    36  			"subdir/solution.ext",
    37  		},
    38  		// It finds hidden files.
    39  		{
    40  			PatternGroup{SolutionPattern: "secret-solution"},
    41  			"subdir/.secret-solution.ext",
    42  		},
    43  		// it finds files in hidden directories
    44  		{
    45  			PatternGroup{SolutionPattern: "hidden.file\\.ext"},
    46  			".hidden/file.ext",
    47  		},
    48  	}
    49  
    50  	path := filepath.FromSlash("../fixtures/fake-exercise")
    51  
    52  	for _, test := range tests {
    53  		ex, err := NewExercise(path, test.PatternGroup)
    54  		assert.NoError(t, err)
    55  
    56  		assert.Equal(t, test.path, ex.SolutionPath)
    57  	}
    58  }
    59  func TestExerciseTestSuitePaths(t *testing.T) {
    60  	tests := []struct {
    61  		PatternGroup
    62  		path string
    63  	}{
    64  		{
    65  			// It finds files in the root of the exercise directory.
    66  			PatternGroup{TestPattern: "(?i)test"},
    67  			"fake_test.ext",
    68  		},
    69  		{
    70  			// It finds files in a subdirectory.
    71  			PatternGroup{TestPattern: "specs"},
    72  			"specs/file.ext",
    73  		},
    74  	}
    75  
    76  	path := filepath.FromSlash("../fixtures/fake-exercise")
    77  
    78  	for _, test := range tests {
    79  		ex, err := NewExercise(path, test.PatternGroup)
    80  		assert.NoError(t, err)
    81  
    82  		assert.Equal(t, test.path, ex.TestSuitePath)
    83  	}
    84  }