mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 17:00:37 +00:00
Simplify constant initialization in unit tests
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
"github.com/pikami/cosmium/parsers/nosql"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
// For Parser Debugging
|
||||
@@ -102,20 +103,8 @@ func Test_Parse(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"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_StringFunctions(t *testing.T) {
|
||||
@@ -23,20 +24,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: "123",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -61,13 +50,7 @@ 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: "123",
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
nil,
|
||||
},
|
||||
},
|
||||
@@ -93,13 +76,7 @@ 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: "123",
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "pk"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
@@ -128,20 +105,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: "123",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -166,20 +131,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: "123",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -204,20 +157,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: "123",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeBoolean,
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("123"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -242,20 +183,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.ConstantTypeInteger,
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("2"),
|
||||
testutils.SelectItem_Constant_Int(1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -352,13 +281,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 5,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(5),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -431,20 +354,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: "old",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "new",
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_String("old"),
|
||||
testutils.SelectItem_Constant_String("new"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -469,13 +380,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 3,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(3),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -524,13 +429,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 3,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(3),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -579,20 +478,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.ConstantTypeInteger,
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeInteger,
|
||||
Value: 5,
|
||||
},
|
||||
},
|
||||
testutils.SelectItem_Constant_Int(1),
|
||||
testutils.SelectItem_Constant_Int(5),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Parse_Were(t *testing.T) {
|
||||
@@ -22,10 +23,7 @@ func Test_Parse_Were(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),
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -51,18 +49,12 @@ func Test_Parse_Were(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: "12345"},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_String("12345"),
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "pk"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeInteger, Value: 123},
|
||||
},
|
||||
Right: testutils.SelectItem_Constant_Int(123),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -87,10 +79,7 @@ func Test_Parse_Were(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,
|
||||
@@ -98,18 +87,12 @@ func Test_Parse_Were(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"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -135,43 +118,28 @@ func Test_Parse_Were(t *testing.T) {
|
||||
Filters: parsers.LogicalExpression{
|
||||
Expressions: []interface{}{
|
||||
parsers.ComparisonExpression{
|
||||
Left: parsers.SelectItem{Path: []string{"c", "boolean"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
|
||||
},
|
||||
Left: parsers.SelectItem{Path: []string{"c", "boolean"}},
|
||||
Right: testutils.SelectItem_Constant_Bool(true),
|
||||
Operation: "=",
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Left: parsers.SelectItem{Path: []string{"c", "integer"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeInteger, Value: 1},
|
||||
},
|
||||
Left: parsers.SelectItem{Path: []string{"c", "integer"}},
|
||||
Right: testutils.SelectItem_Constant_Int(1),
|
||||
Operation: "=",
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Left: parsers.SelectItem{Path: []string{"c", "float"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeFloat, Value: 6.9},
|
||||
},
|
||||
Left: parsers.SelectItem{Path: []string{"c", "float"}},
|
||||
Right: testutils.SelectItem_Constant_Float(6.9),
|
||||
Operation: "=",
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Left: parsers.SelectItem{Path: []string{"c", "string"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "hello"},
|
||||
},
|
||||
Left: parsers.SelectItem{Path: []string{"c", "string"}},
|
||||
Right: testutils.SelectItem_Constant_String("hello"),
|
||||
Operation: "=",
|
||||
},
|
||||
parsers.ComparisonExpression{
|
||||
Left: parsers.SelectItem{Path: []string{"c", "param"}},
|
||||
Right: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{Type: parsers.ConstantTypeParameterConstant, Value: "@param_id1"},
|
||||
},
|
||||
Left: parsers.SelectItem{Path: []string{"c", "param"}},
|
||||
Right: testutils.SelectItem_Constant_Parameter("@param_id1"),
|
||||
Operation: "=",
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user