-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use correct plural and singular forms based on count (#462)
- Loading branch information
Showing
6 changed files
with
144 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package output | ||
|
||
// Form returns the singular or plural form that should be used based on the given count | ||
func Form(count int, singular, plural string) string { | ||
if count == 1 { | ||
return singular | ||
} | ||
|
||
return plural | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package output_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/osv-scanner/internal/output" | ||
) | ||
|
||
func TestForm(t *testing.T) { | ||
t.Parallel() | ||
|
||
type args struct { | ||
count int | ||
singular string | ||
plural string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "", | ||
args: args{ | ||
count: 0, | ||
singular: "package", | ||
plural: "packages", | ||
}, | ||
want: "packages", | ||
}, | ||
{ | ||
name: "", | ||
args: args{ | ||
count: 1, | ||
singular: "package", | ||
plural: "packages", | ||
}, | ||
want: "package", | ||
}, | ||
{ | ||
name: "", | ||
args: args{ | ||
count: 2, | ||
singular: "package", | ||
plural: "packages", | ||
}, | ||
want: "packages", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if got := output.Form(tt.args.count, tt.args.singular, tt.args.plural); got != tt.want { | ||
t.Errorf("Form() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters