mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 00:40:47 +00:00
Simplify constant initialization in unit tests
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func testQueryExecute(
|
||||
@@ -111,20 +112,8 @@ func Test_Execute(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "123",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "456",
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
testutils.SelectItem_Constant_String("456"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_StringFunctions(t *testing.T) {
|
||||
@@ -33,20 +34,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "pk"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "aaa",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("aaa"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -81,13 +70,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "pk"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "aaa",
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("aaa"),
|
||||
nil,
|
||||
},
|
||||
},
|
||||
@@ -119,20 +102,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: " ",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: 123,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String(" "),
|
||||
testutils.SelectItem_Constant_Int(123),
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "pk"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
@@ -171,20 +142,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "2",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("2"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -219,20 +178,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "3",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("3"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -267,20 +214,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "1",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("1"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -315,20 +250,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "str"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "o",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 4,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("o"),
|
||||
testutils.SelectItem_Constant_Int(4),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -397,13 +320,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "str"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 3,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(3),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -506,20 +423,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "str"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "world",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "universe",
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("world"),
|
||||
testutils.SelectItem_Constant_String("universe"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -554,13 +459,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "str"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 3,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(3),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -629,13 +528,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "str"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 3,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(3),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -704,20 +597,8 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "str"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 2,
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 4,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(2),
|
||||
testutils.SelectItem_Constant_Int(4),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_Where(t *testing.T) {
|
||||
@@ -26,10 +27,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
Filters: parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
mockData,
|
||||
@@ -52,10 +50,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
Filters: parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeParameterConstant, Value: "@param_id"},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_Parameter("@param_id"),
|
||||
},
|
||||
Parameters: map[string]interface{}{
|
||||
"@param_id": "456",
|
||||
@@ -83,18 +78,12 @@ func Test_Execute_Where(t *testing.T) {
|
||||
parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "67890"},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_String("67890"),
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "pk"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeInteger, Value: 456},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_Int(456),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -120,10 +109,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
parsers.LogicalExpression{
|
||||
Operation: parsers.LogicalExpressionTypeOr,
|
||||
@@ -131,18 +117,12 @@ func Test_Execute_Where(t *testing.T) {
|
||||
parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "123"},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_String("123"),
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "456"},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_String("456"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user