This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from maurofran/develop
Develop
- Loading branch information
Showing
41 changed files
with
1,213 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Hamcrest for GO |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package comparator | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
|
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,51 @@ | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestEqualsTo_Matches(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ref int | ||
value int | ||
expected bool | ||
}{ | ||
{"equals", 5, 5, true}, | ||
{"lesser", 5, 4, false}, | ||
{"greater", 5, 6, false}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
// Given | ||
fixture := EqualsTo(test.ref) | ||
// When | ||
actual := fixture.Matches(test.value) | ||
// Then | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestEqualsTo_DescribeTo(t *testing.T) { | ||
// Given | ||
fixture := EqualsTo(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeTo(description) | ||
// Then | ||
assert.Equal(t, `a value equal to 5`, description.String()) | ||
} | ||
|
||
func TestEqualsTo_DescribeMismatch(t *testing.T) { | ||
// Given | ||
fixture := EqualsTo(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeMismatch(8, description) | ||
// Then | ||
assert.Equal(t, `8 was equal to 5`, description.String()) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package comparator | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/constraints" | ||
|
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,30 @@ | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/constraints" | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
) | ||
|
||
// GreaterThanOrEqualsTo creates a new matcher for grater than comparison. | ||
func GreaterThanOrEqualsTo[T constraints.Ordered](value T) matcher.Matcher[T] { | ||
return greaterThanOrEqualsTo[T]{ref: value} | ||
} | ||
|
||
type greaterThanOrEqualsTo[T constraints.Ordered] struct { | ||
ref T | ||
} | ||
|
||
func (e greaterThanOrEqualsTo[T]) Matches(value T) bool { | ||
return value >= e.ref | ||
} | ||
|
||
func (e greaterThanOrEqualsTo[T]) DescribeTo(description matcher.Description) { | ||
description.AppendText("a value greater than or equals to ") | ||
description.AppendValue(e.ref) | ||
} | ||
|
||
func (e greaterThanOrEqualsTo[T]) DescribeMismatch(actual T, description matcher.Description) { | ||
description.AppendValue(actual) | ||
description.AppendText(" was greater than or equals to ") | ||
description.AppendValue(e.ref) | ||
} |
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,51 @@ | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGreaterThanOrEqualsTo_Matches(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ref int | ||
value int | ||
expected bool | ||
}{ | ||
{"equals", 5, 5, true}, | ||
{"lesser", 5, 4, false}, | ||
{"greater", 5, 6, true}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
// Given | ||
fixture := GreaterThanOrEqualsTo(test.ref) | ||
// When | ||
actual := fixture.Matches(test.value) | ||
// Then | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestGreaterOrEqualsToThan_DescribeTo(t *testing.T) { | ||
// Given | ||
fixture := GreaterThanOrEqualsTo(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeTo(description) | ||
// Then | ||
assert.Equal(t, `a value greater than or equals to 5`, description.String()) | ||
} | ||
|
||
func TestGreaterThanOrEqualsTo_DescribeMismatch(t *testing.T) { | ||
// Given | ||
fixture := GreaterThanOrEqualsTo(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeMismatch(8, description) | ||
// Then | ||
assert.Equal(t, `8 was greater than or equals to 5`, description.String()) | ||
} |
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,51 @@ | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGreaterThan_Matches(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ref int | ||
value int | ||
expected bool | ||
}{ | ||
{"equals", 5, 5, false}, | ||
{"lesser", 5, 4, false}, | ||
{"greater", 5, 6, true}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
// Given | ||
fixture := GreaterThan(test.ref) | ||
// When | ||
actual := fixture.Matches(test.value) | ||
// Then | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestGreaterThan_DescribeTo(t *testing.T) { | ||
// Given | ||
fixture := GreaterThan(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeTo(description) | ||
// Then | ||
assert.Equal(t, `a value greater than 5`, description.String()) | ||
} | ||
|
||
func TestGreaterThan_DescribeMismatch(t *testing.T) { | ||
// Given | ||
fixture := GreaterThan(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeMismatch(8, description) | ||
// Then | ||
assert.Equal(t, `8 was greater than 5`, description.String()) | ||
} |
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,30 @@ | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/constraints" | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
) | ||
|
||
// LessThanOrEqualsTo creates a new matcher for grater than comparison. | ||
func LessThanOrEqualsTo[T constraints.Ordered](value T) matcher.Matcher[T] { | ||
return lessThanOrEqualsTo[T]{ref: value} | ||
} | ||
|
||
type lessThanOrEqualsTo[T constraints.Ordered] struct { | ||
ref T | ||
} | ||
|
||
func (e lessThanOrEqualsTo[T]) Matches(value T) bool { | ||
return value <= e.ref | ||
} | ||
|
||
func (e lessThanOrEqualsTo[T]) DescribeTo(description matcher.Description) { | ||
description.AppendText("a value less than or equals to ") | ||
description.AppendValue(e.ref) | ||
} | ||
|
||
func (e lessThanOrEqualsTo[T]) DescribeMismatch(actual T, description matcher.Description) { | ||
description.AppendValue(actual) | ||
description.AppendText(" was less than or equals to ") | ||
description.AppendValue(e.ref) | ||
} |
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,51 @@ | ||
package compare | ||
|
||
import ( | ||
"github.com/maurofran/hamcrest4go/matcher" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestLessThanOrEqualsTo_Matches(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ref int | ||
value int | ||
expected bool | ||
}{ | ||
{"equals", 5, 5, true}, | ||
{"lesser", 5, 4, true}, | ||
{"greater", 5, 6, false}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
// Given | ||
fixture := LessThanOrEqualsTo(test.ref) | ||
// When | ||
actual := fixture.Matches(test.value) | ||
// Then | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestLessOrEqualsToThan_DescribeTo(t *testing.T) { | ||
// Given | ||
fixture := LessThanOrEqualsTo(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeTo(description) | ||
// Then | ||
assert.Equal(t, `a value less than or equals to 5`, description.String()) | ||
} | ||
|
||
func TestLessThanOrEqualsTo_DescribeMismatch(t *testing.T) { | ||
// Given | ||
fixture := LessThanOrEqualsTo(5) | ||
description := matcher.StringDescription() | ||
// When | ||
fixture.DescribeMismatch(8, description) | ||
// Then | ||
assert.Equal(t, `8 was less than or equals to 5`, description.String()) | ||
} |
Oops, something went wrong.