mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-01-11 01:29:00 +08:00
Some checks failed
Test / test (1.20, macos-15-intel) (push) Has been cancelled
Test / test (1.20, macos-latest) (push) Has been cancelled
Test / test (1.20, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.20, ubuntu-latest) (push) Has been cancelled
Test / test (1.20, windows-latest) (push) Has been cancelled
Test / test (1.21, macos-15-intel) (push) Has been cancelled
Test / test (1.21, macos-latest) (push) Has been cancelled
Test / test (1.21, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.21, ubuntu-latest) (push) Has been cancelled
Test / test (1.21, windows-latest) (push) Has been cancelled
Test / test (1.22, macos-15-intel) (push) Has been cancelled
Test / test (1.22, macos-latest) (push) Has been cancelled
Test / test (1.22, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.22, ubuntu-latest) (push) Has been cancelled
Test / test (1.22, windows-latest) (push) Has been cancelled
Test / test (1.23, macos-15-intel) (push) Has been cancelled
Test / test (1.23, macos-latest) (push) Has been cancelled
Test / test (1.23, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.23, ubuntu-latest) (push) Has been cancelled
Test / test (1.23, windows-latest) (push) Has been cancelled
Test / test (1.24, macos-15-intel) (push) Has been cancelled
Test / test (1.24, macos-latest) (push) Has been cancelled
Test / test (1.24, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.24, ubuntu-latest) (push) Has been cancelled
Test / test (1.24, windows-latest) (push) Has been cancelled
Test / test (1.25, macos-15-intel) (push) Has been cancelled
Test / test (1.25, macos-latest) (push) Has been cancelled
Test / test (1.25, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.25, ubuntu-latest) (push) Has been cancelled
Test / test (1.25, windows-latest) (push) Has been cancelled
Test / test (1.26.0-rc.1, macos-15-intel) (push) Has been cancelled
Test / test (1.26.0-rc.1, macos-latest) (push) Has been cancelled
Test / test (1.26.0-rc.1, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.26.0-rc.1, ubuntu-latest) (push) Has been cancelled
Test / test (1.26.0-rc.1, windows-latest) (push) Has been cancelled
Trigger CMFA Update / trigger-CMFA-update (push) Has been cancelled
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package logic_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
// https://github.com/golang/go/wiki/CodeReviewComments#import-dot
|
|
. "github.com/metacubex/mihomo/rules/logic"
|
|
|
|
C "github.com/metacubex/mihomo/constant"
|
|
"github.com/metacubex/mihomo/rules"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var ParseRule = rules.ParseRule
|
|
|
|
func TestAND(t *testing.T) {
|
|
and, err := NewAND("((DOMAIN,baidu.com),(NETWORK,TCP),(DST-PORT,10001-65535))", "DIRECT", ParseRule)
|
|
assert.Equal(t, nil, err)
|
|
assert.Equal(t, "DIRECT", and.Adapter())
|
|
m, _ := and.Match(&C.Metadata{
|
|
Host: "baidu.com",
|
|
NetWork: C.TCP,
|
|
DstPort: 20000,
|
|
}, C.RuleMatchHelper{})
|
|
assert.Equal(t, true, m)
|
|
|
|
and, err = NewAND("(DOMAIN,baidu.com),(NETWORK,TCP),(DST-PORT,10001-65535))", "DIRECT", ParseRule)
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
and, err = NewAND("((AND,(DOMAIN,baidu.com),(NETWORK,TCP)),(NETWORK,TCP),(DST-PORT,10001-65535))", "DIRECT", ParseRule)
|
|
assert.Equal(t, nil, err)
|
|
}
|
|
|
|
func TestNOT(t *testing.T) {
|
|
not, err := NewNOT("((DST-PORT,6000-6500))", "REJECT", ParseRule)
|
|
assert.Equal(t, nil, err)
|
|
m, _ := not.Match(&C.Metadata{
|
|
DstPort: 6100,
|
|
}, C.RuleMatchHelper{})
|
|
assert.Equal(t, false, m)
|
|
|
|
_, err = NewNOT("(DST-PORT,5600-6666)", "DIRECT", ParseRule)
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
_, err = NewNOT("DST-PORT,5600-6666", "DIRECT", ParseRule)
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
_, err = NewNOT("((DST-PORT,5600-6666),(DOMAIN,baidu.com))", "DIRECT", ParseRule)
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
_, err = NewNOT("(())", "DIRECT", ParseRule)
|
|
assert.NotEqual(t, nil, err)
|
|
}
|
|
|
|
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(&C.Metadata{
|
|
NetWork: C.TCP,
|
|
}, C.RuleMatchHelper{})
|
|
assert.Equal(t, true, m)
|
|
}
|