fix: adjust sub_rule to logic package, and fix not rule failed
This commit is contained in:
@ -2,16 +2,14 @@ package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Dreamacro/clash/constant"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
RC "github.com/Dreamacro/clash/rules/common"
|
||||
RP "github.com/Dreamacro/clash/rules/provider"
|
||||
"github.com/Dreamacro/clash/rules/sub_rule"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func ParseRule(tp, payload, target string, params []string, subRules *map[string][]C.Rule) (parsed constant.Rule, parseErr error) {
|
||||
func ParseRule(tp, payload, target string, params []string, subRules *map[string][]C.Rule) (parsed C.Rule, parseErr error) {
|
||||
switch tp {
|
||||
case "DOMAIN":
|
||||
parsed = RC.NewDomain(payload, target)
|
||||
@ -49,7 +47,7 @@ func ParseRule(tp, payload, target string, params []string, subRules *map[string
|
||||
case "IN-TYPE":
|
||||
parsed, parseErr = RC.NewInType(payload, target)
|
||||
case "SUB-RULE":
|
||||
parsed, parseErr = sub_rule.NewSubRule(payload, target, subRules, ParseRule)
|
||||
parsed, parseErr = NewSubRule(payload, target, subRules, ParseRule)
|
||||
case "AND":
|
||||
parsed, parseErr = NewAND(payload, target, ParseRule)
|
||||
case "OR":
|
||||
@ -74,10 +72,10 @@ func TestAND(t *testing.T) {
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "DIRECT", and.adapter)
|
||||
assert.Equal(t, false, and.ShouldResolveIP())
|
||||
m, _ := and.Match(&constant.Metadata{
|
||||
m, _ := and.Match(&C.Metadata{
|
||||
Host: "baidu.com",
|
||||
AddrType: constant.AtypDomainName,
|
||||
NetWork: constant.TCP,
|
||||
AddrType: C.AtypDomainName,
|
||||
NetWork: C.TCP,
|
||||
DstPort: "20000",
|
||||
})
|
||||
assert.Equal(t, true, m)
|
||||
@ -92,7 +90,7 @@ func TestAND(t *testing.T) {
|
||||
func TestNOT(t *testing.T) {
|
||||
not, err := NewNOT("((DST-PORT,6000-6500))", "REJECT", ParseRule)
|
||||
assert.Equal(t, nil, err)
|
||||
m, _ := not.Match(&constant.Metadata{
|
||||
m, _ := not.Match(&C.Metadata{
|
||||
DstPort: "6100",
|
||||
})
|
||||
assert.Equal(t, false, m)
|
||||
@ -107,8 +105,8 @@ func TestNOT(t *testing.T) {
|
||||
func TestOR(t *testing.T) {
|
||||
or, err := NewOR("((DOMAIN,baidu.com),(NETWORK,TCP),(DST-PORT,10001-65535))", "DIRECT", ParseRule)
|
||||
assert.Equal(t, nil, err)
|
||||
m, _ := or.Match(&constant.Metadata{
|
||||
NetWork: constant.TCP,
|
||||
m, _ := or.Match(&C.Metadata{
|
||||
NetWork: C.TCP,
|
||||
})
|
||||
assert.Equal(t, true, m)
|
||||
assert.Equal(t, false, or.ShouldResolveIP())
|
||||
|
Reference in New Issue
Block a user