fix: whereins defaulting to lower case

This commit is contained in:
Benjamin Ramser 2024-05-27 22:54:55 +02:00
parent 51e6862797
commit a47f02b02d
3 changed files with 124 additions and 1 deletions

View File

@ -354,7 +354,7 @@ func (s *Server) parseSearchScanBaseTokens(
valArr[i] = field.ValueOf(valStr)
}
t.whereins = append(t.whereins, whereinT{
name: strings.ToLower(name),
name: name,
valArr: valArr,
})
continue

View File

@ -3,6 +3,8 @@ package server
import (
"strings"
"testing"
"github.com/tidwall/tile38/internal/field"
)
func TestLowerCompare(t *testing.T) {
@ -29,6 +31,118 @@ func TestLowerCompare(t *testing.T) {
}
}
func TestParseWhereins(t *testing.T) {
s := &Server{}
type tcase struct {
inputWhereins []whereinT
expWhereins []whereinT
}
fn := func(tc tcase) func(t *testing.T) {
return func(t *testing.T) {
_, tout, err := s.parseSearchScanBaseTokens(
"scan",
searchScanBaseTokens{
whereins: tc.inputWhereins,
},
[]string{"key"},
)
got := tout.whereins
exp := tc.expWhereins
if err != nil {
t.Fatalf("unexpected error while parsing search scan base tokens")
}
if len(got) != len(exp) {
t.Fatalf("expected equal length whereins")
}
for i := range got {
if got[i].name != exp[i].name {
t.Fatalf("expected equal field names")
}
for j := range exp[i].valArr {
if !got[i].match(exp[i].valArr[j]) {
t.Fatalf("expected matching value arrays")
}
}
}
}
}
tests := map[string]tcase{
"upper case": {
inputWhereins: []whereinT{
{
name: "TEST",
valArr: []field.Value{
field.ValueOf("1"),
field.ValueOf("1"),
},
},
},
expWhereins: []whereinT{
{
name: "TEST",
valArr: []field.Value{
field.ValueOf("1"),
field.ValueOf("1"),
},
},
},
},
"lower case": {
inputWhereins: []whereinT{
{
name: "test",
valArr: []field.Value{
field.ValueOf("1"),
field.ValueOf("1"),
},
},
},
expWhereins: []whereinT{
{
name: "test",
valArr: []field.Value{
field.ValueOf("1"),
field.ValueOf("1"),
},
},
},
},
"mixed case": {
inputWhereins: []whereinT{
{
name: "teSt",
valArr: []field.Value{
field.ValueOf("1"),
field.ValueOf("1"),
},
},
},
expWhereins: []whereinT{
{
name: "teSt",
valArr: []field.Value{
field.ValueOf("1"),
field.ValueOf("1"),
},
},
},
},
}
for name, tc := range tests {
t.Run(name, fn(tc))
}
}
// func testParseFloat(t testing.TB, s string, f float64, invalid bool) {
// n, err := parseFloat(s)
// if err != nil {

View File

@ -514,6 +514,15 @@ func keys_FIELDS_test(mc *mockServer) error {
Do("SET", "fleet", "truck1", "FIELD", "speed", "2", "POINT", "-112", "33").JSON().OK(),
Do("GET", "fleet", "truck1", "WITHFIELDS").JSON().Str(`{"ok":true,"object":{"type":"Point","coordinates":[33,-112]},"fields":{"speed":2}}`),
// Do some whereins queries
Do("SET", "whereins", "id1", "FIELD", "test", "2", "POINT", "-112", "33").JSON().OK(),
Do("SET", "whereins", "id2", "FIELD", "TEST", "3", "POINT", "-111", "32").JSON().OK(),
Do("SET", "whereins", "id3", "FIELD", "teSt", "4", "POINT", "-110", "31").JSON().OK(),
Do("SCAN", "whereins", "WHEREIN", "test", "1", "2", "OBJECTS").JSON().Str(`{"ok":true,"fields":["test"],"objects":[{"id":"id1","object":{"type":"Point","coordinates":[33,-112]},"fields":[2]}],"count":1,"cursor":0}`),
Do("SCAN", "whereins", "WHEREIN", "TEST", "1", "3", "OBJECTS").JSON().Str(`{"ok":true,"fields":["TEST"],"objects":[{"id":"id2","object":{"type":"Point","coordinates":[32,-111]},"fields":[3]}],"count":1,"cursor":0}`),
Do("SCAN", "whereins", "WHEREIN", "teSt", "1", "4", "OBJECTS").JSON().Str(`{"ok":true,"fields":["teSt"],"objects":[{"id":"id3","object":{"type":"Point","coordinates":[31,-110]},"fields":[4]}],"count":1,"cursor":0}`),
Do("SCAN", "whereins", "OBJECTS").JSON().Str(`{"ok":true,"fields":["TEST","teSt","test"],"objects":[{"id":"id1","object":{"type":"Point","coordinates":[33,-112]},"fields":[0,0,2]},{"id":"id2","object":{"type":"Point","coordinates":[32,-111]},"fields":[3,0,0]},{"id":"id3","object":{"type":"Point","coordinates":[31,-110]},"fields":[0,4,0]}],"count":3,"cursor":0}`),
// Do some GJSON queries.
Do("SET", "fleet", "truck2", "FIELD", "hello", `{"world":"tom"}`, "POINT", "-112", "33").JSON().OK(),
Do("SCAN", "fleet", "WHERE", "hello", `{"world":"tom"}`, `{"world":"tom"}`, "COUNT").JSON().Str(`{"ok":true,"count":1,"cursor":0}`),