Skip to content

Commit

Permalink
test: add more coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
  • Loading branch information
fzipi committed Sep 21, 2024
1 parent ceb3e46 commit df968f9
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/quantitative/leipzig/corpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ func (s *leipzigCorpusTestSuite) TestWithSize() {
s.Require().Equal("300K", s.corpus.Size())
}

func (s *leipzigCorpusTestSuite) TestWithYear() {
s.corpus.WithYear("2024")
s.Require().Equal("2024", s.corpus.Year())
}

func (s *leipzigCorpusTestSuite) TestWithSource() {
s.corpus.WithSource("news")
s.Require().Equal("news", s.corpus.Source())
}

func (s *leipzigCorpusTestSuite) TestWithLanguage() {
s.corpus.WithLanguage("eng")
s.Require().Equal("eng", s.corpus.Language())
}

func (s *leipzigCorpusTestSuite) TestWithURL() {
s.corpus.WithURL("https://downloads.wortschatz-leipzig.de/corpora")
s.Require().Equal("https://downloads.wortschatz-leipzig.de/corpora", s.corpus.URL())
}

func (s *leipzigCorpusTestSuite) TestGetIterator() {
s.corpus.WithSize("10K")
s.cache = s.corpus.FetchCorpusFile()
Expand Down
182 changes: 182 additions & 0 deletions internal/quantitative/leipzig/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package leipzig

import (
"github.com/coreruleset/go-ftw/experimental/corpus"
"reflect"
"testing"
)

func TestFile_CacheDir(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir",
filePath: "filePath",
},
want: "cacheDir",
},
{
name: "Test 2",
fields: fields{
cacheDir: "cacheDir2",
filePath: "filePath2",
},
want: "cacheDir2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.CacheDir(); got != tt.want {
t.Errorf("CacheDir() = %v, want %v", got, tt.want)
}
})
}
}

func TestFile_FilePath(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir",
filePath: "filePath",
},
want: "filePath",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.FilePath(); got != tt.want {
t.Errorf("FilePath() = %v, want %v", got, tt.want)
}
})
}
}

func TestFile_WithCacheDir(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
type args struct {
cacheDir string
}
tests := []struct {
name string
fields fields
args args
want corpus.File
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir1",
filePath: "filePath",
},
args: args{
cacheDir: "cacheDir10",
},
want: File{
cacheDir: "cacheDir10",
filePath: "filePath",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.WithCacheDir(tt.args.cacheDir); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithCacheDir() = %v, want %v", got, tt.want)
}
})
}
}

func TestFile_WithFilePath(t *testing.T) {
type fields struct {
cacheDir string
filePath string
}
type args struct {
filePath string
}
tests := []struct {
name string
fields fields
args args
want corpus.File
}{
{
name: "Test 1",
fields: fields{
cacheDir: "cacheDir",
filePath: "filePath1",
},
args: args{
filePath: "filePath2",
},
want: File{
cacheDir: "cacheDir",
filePath: "filePath2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := File{
cacheDir: tt.fields.cacheDir,
filePath: tt.fields.filePath,
}
if got := f.WithFilePath(tt.args.filePath); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithFilePath() = %v, want %v", got, tt.want)
}
})
}
}

func TestNewFile(t *testing.T) {
tests := []struct {
name string
want corpus.File
}{
{
name: "Test 1",
want: File{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewFile(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewFile() = %v, want %v", got, tt.want)
}
})
}
}
Loading

0 comments on commit df968f9

Please sign in to comment.