ServerBrowser/Filter: Return result of group node
Some checks are pending
Build CI / build (push) Waiting to run

This commit is contained in:
Palapeli
2025-03-05 11:24:27 -05:00
parent c01f080f2c
commit f1741b0718
2 changed files with 18 additions and 6 deletions

View File

@@ -37,18 +37,17 @@ func (this *expression) eval(basenode *TreeNode) int64 {
return this.getNumber(node)
case CatOther:
this.switchOther(node)
return this.switchOther(node)
}
}
panic("eval failed")
}
func (this *expression) switchOther(node *TreeNode) {
func (this *expression) switchOther(node *TreeNode) int64 {
switch v1 := node.Value.(type) {
case *GroupToken:
if v1.GroupType == "()" {
this.eval(node)
return
return this.eval(node)
}
}
panic("invalid node " + node.String())

View File

@@ -1,6 +1,7 @@
package serverbrowser
import (
"fmt"
"testing"
"wwfc/serverbrowser/filter"
)
@@ -26,15 +27,27 @@ func evalFilter(t *testing.T, expression string, queryGame string, context map[s
return 0, err
}
fmt.Printf("ret: %d\n", ret)
return ret, err
}
func TestParseFilter(t *testing.T) {
parseFilter(t, `dwc_mver = 3 and dwc_pid != 1000004498 and maxplayers = 3 and numplayers < 3 and dwc_mtype = 0 and dwc_mresv != dwc_pid and (((20=auth)AND((1&mskdif)=mskdif)AND((14&mskstg)=mskstg)))`)
evalFilter(t, `dwc_mver = 3 and dwc_pid != 1000004498 and maxplayers = 3 and numplayers < 3 and dwc_mtype = 0 and dwc_mresv != dwc_pid and (((20=auth)AND((1&mskdif)=mskdif)AND((14&mskstg)=mskstg)))`, "fstarzerods", map[string]string{})
evalFilter(t, `dwc_mver = 3 and dwc_pid != 1000004499 and maxplayers = 3 and numplayers < 3 and dwc_mtype = 0 and dwc_mresv != dwc_pid and (((20=auth)AND((1&mskdif)=mskdif)AND((14&mskstg)=mskstg)))`, "fstarzerods", map[string]string{
"dwc_mver": "3",
"dwc_pid": "1",
"maxplayers": "3",
"numplayers": "2",
"dwc_mtype": "0",
"dwc_mresv": "0",
"auth": "20",
"mskdif": "0",
"mskstg": "0",
})
evalFilter(t, `1&mskdif`, "fstarzerods", map[string]string{
evalFilter(t, `(1&mskdif)`, "fstarzerods", map[string]string{
"mskdif": "1",
})
}