github.com/fredbi/git-chglog@v0.0.0-20190706071416-d35c598eac81/commit_filter_test.go (about)

     1  package chglog
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCommitFilter(t *testing.T) {
    10  	assert := assert.New(t)
    11  
    12  	pickCommitSubjects := func(arr []*Commit) []string {
    13  		res := make([]string, len(arr))
    14  		for i, commit := range arr {
    15  			res[i] = commit.Subject
    16  		}
    17  		return res
    18  	}
    19  
    20  	fixtures := []*Commit{
    21  		&Commit{
    22  			Type:    "foo",
    23  			Scope:   "hoge",
    24  			Subject: "1",
    25  		},
    26  		&Commit{
    27  			Type:    "foo",
    28  			Scope:   "fuga",
    29  			Subject: "2",
    30  		},
    31  		&Commit{
    32  			Type:    "bar",
    33  			Scope:   "hoge",
    34  			Subject: "3",
    35  		},
    36  		&Commit{
    37  			Type:    "bar",
    38  			Scope:   "fuga",
    39  			Subject: "4",
    40  		},
    41  	}
    42  
    43  	assert.Equal(
    44  		[]string{
    45  			"1",
    46  			"2",
    47  			"3",
    48  			"4",
    49  		},
    50  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{})),
    51  	)
    52  
    53  	assert.Equal(
    54  		[]string{
    55  			"1",
    56  			"2",
    57  			"3",
    58  			"4",
    59  		},
    60  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    61  			"Type": {"foo", "bar"},
    62  		})),
    63  	)
    64  
    65  	assert.Equal(
    66  		[]string{
    67  			"1",
    68  			"2",
    69  		},
    70  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    71  			"Type": {"foo"},
    72  		})),
    73  	)
    74  
    75  	assert.Equal(
    76  		[]string{
    77  			"3",
    78  			"4",
    79  		},
    80  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    81  			"Type": {"bar"},
    82  		})),
    83  	)
    84  
    85  	assert.Equal(
    86  		[]string{
    87  			"2",
    88  			"4",
    89  		},
    90  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    91  			"Scope": {"fuga"},
    92  		})),
    93  	)
    94  
    95  	assert.Equal(
    96  		[]string{
    97  			"3",
    98  		},
    99  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   100  			"Type":  {"bar"},
   101  			"Scope": {"hoge"},
   102  		})),
   103  	)
   104  
   105  	assert.Equal(
   106  		[]string{
   107  			"1",
   108  			"2",
   109  		},
   110  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   111  			"Type":  {"foo"},
   112  			"Scope": {"fuga", "hoge"},
   113  		})),
   114  	)
   115  }