github.com/brandonmanuel/git-chglog@v0.0.0-20200903004639-7a62fa08787a/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  		&Commit{
    42  			Type:    "Bar",
    43  			Scope:   "hogera",
    44  			Subject: "5",
    45  		},
    46  	}
    47  
    48  	assert.Equal(
    49  		[]string{
    50  			"1",
    51  			"2",
    52  			"3",
    53  			"4",
    54  			"5",
    55  		},
    56  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{}, false)),
    57  	)
    58  
    59  	assert.Equal(
    60  		[]string{
    61  			"1",
    62  			"2",
    63  			"3",
    64  			"4",
    65  		},
    66  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    67  			"Type": {"foo", "bar"},
    68  		}, false)),
    69  	)
    70  
    71  	assert.Equal(
    72  		[]string{
    73  			"1",
    74  			"2",
    75  			"3",
    76  			"4",
    77  			"5",
    78  		},
    79  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    80  			"Type": {"foo", "bar"},
    81  		}, true)),
    82  	)
    83  
    84  	assert.Equal(
    85  		[]string{
    86  			"1",
    87  			"2",
    88  		},
    89  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
    90  			"Type": {"foo"},
    91  		}, false)),
    92  	)
    93  
    94  	assert.Equal(
    95  		[]string{
    96  			"3",
    97  			"4",
    98  		},
    99  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   100  			"Type": {"bar"},
   101  		}, false)),
   102  	)
   103  
   104  	assert.Equal(
   105  		[]string{
   106  			"3",
   107  			"4",
   108  			"5",
   109  		},
   110  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   111  			"Type": {"bar"},
   112  		}, true)),
   113  	)
   114  
   115  	assert.Equal(
   116  		[]string{
   117  			"2",
   118  			"4",
   119  		},
   120  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   121  			"Scope": {"fuga"},
   122  		}, false)),
   123  	)
   124  
   125  	assert.Equal(
   126  		[]string{
   127  			"3",
   128  		},
   129  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   130  			"Type":  {"bar"},
   131  			"Scope": {"hoge"},
   132  		}, false)),
   133  	)
   134  
   135  	assert.Equal(
   136  		[]string{
   137  			"1",
   138  			"2",
   139  		},
   140  		pickCommitSubjects(commitFilter(fixtures, map[string][]string{
   141  			"Type":  {"foo"},
   142  			"Scope": {"fuga", "hoge"},
   143  		}, false)),
   144  	)
   145  }