add tests

This commit is contained in:
Meo597
2026-09-26 06:16:54 +08:00
parent 235843c5d2
commit 72d9ab50b9
6 changed files with 600 additions and 0 deletions
+19
View File
@@ -40,3 +40,22 @@ func TestLuaDomainMatcherUsesNativeMatcher(t *testing.T) {
t.Fatal(err)
}
}
func TestLuaMatchersRejectInvalidRules(t *testing.T) {
for _, tc := range []struct {
name string
script string
}{
{"IP rule", `require("xray.geodata").ipMatcher({"not-an-ip"})`},
{"non-string domain rule", `require("xray.geodata").domainMatcher({true})`},
} {
t.Run(tc.name, func(t *testing.T) {
L := lua.NewState()
defer L.Close()
RegisterLua(L)
if err := L.DoString(tc.script); err == nil {
t.Fatal("invalid geodata rule was accepted")
}
})
}
}