-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting And/Or cases when there is only one expression passed as a…
…n argument (#654)
- Loading branch information
1 parent
7278464
commit b31fc8f
Showing
2 changed files
with
72 additions
and
0 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,66 @@ | ||
package query | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" | ||
) | ||
|
||
func Test_AndOrEdgeCases(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expressions []Expression | ||
constructor func(expressions ...Expression) Expression | ||
expected Expression | ||
}{ | ||
{ | ||
name: "And with no expressions", | ||
constructor: And, | ||
expected: And(), | ||
}, | ||
{ | ||
name: "Or with no expressions", | ||
constructor: Or, | ||
expected: Or(), | ||
}, | ||
{ | ||
name: "And with one expression", | ||
expressions: []Expression{TxHash("txHash")}, | ||
constructor: And, | ||
expected: TxHash("txHash"), | ||
}, | ||
{ | ||
name: "Or with one expression", | ||
expressions: []Expression{TxHash("txHash")}, | ||
constructor: Or, | ||
expected: TxHash("txHash"), | ||
}, | ||
{ | ||
name: "And with multiple expressions", | ||
expressions: []Expression{TxHash("txHash"), Block(123, primitives.Eq)}, | ||
constructor: And, | ||
expected: And( | ||
TxHash("txHash"), | ||
Block(123, primitives.Eq), | ||
), | ||
}, | ||
{ | ||
name: "Or with multiple expressions", | ||
expressions: []Expression{TxHash("txHash"), Block(123, primitives.Eq)}, | ||
constructor: Or, | ||
expected: Or( | ||
TxHash("txHash"), | ||
Block(123, primitives.Eq), | ||
), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := tt.constructor(tt.expressions...) | ||
require.Equal(t, tt.expected, got) | ||
}) | ||
} | ||
} |