mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-02 05:46:39 +00:00
lua: standardize hooks and host APIs on PascalCase
This commit is contained in:
+13
-13
@@ -18,11 +18,11 @@ func TestLuaIPMatcher(t *testing.T) {
|
||||
ips.Value = []net.IP{ip.Value.(net.IP), net.ParseIP("8.8.8.8")}
|
||||
L.SetGlobal("ips", ips)
|
||||
if err := L.DoString(`
|
||||
local matcher = require("xray.geodata").ipMatcher("127.0.0.0/8", "::1")
|
||||
assert(matcher:match(ip))
|
||||
assert(matcher:anyMatch(ips))
|
||||
assert(not matcher:matches(ips))
|
||||
local matched, unmatched = matcher:filterIPs(ips)
|
||||
local matcher = require("xray.geodata").IPMatcher("127.0.0.0/8", "::1")
|
||||
assert(matcher:Match(ip))
|
||||
assert(matcher:AnyMatch(ips))
|
||||
assert(not matcher:Matches(ips))
|
||||
local matched, unmatched = matcher:FilterIPs(ips)
|
||||
assert(type(matched) == "userdata" and type(unmatched) == "userdata")
|
||||
assert(#matched == 1 and #unmatched == 1)
|
||||
`); err != nil {
|
||||
@@ -35,12 +35,12 @@ func TestLuaDomainMatcher(t *testing.T) {
|
||||
defer L.Close()
|
||||
RegisterLua(L)
|
||||
if err := L.DoString(`
|
||||
local matcher = require("xray.geodata").domainMatcher("example.com", "full:other.com")
|
||||
assert(matcher:matchAny("example.com"))
|
||||
assert(matcher:matchAny("www.example.com"))
|
||||
assert(matcher:matchAny("other.com"))
|
||||
assert(not matcher:matchAny("www.other.com"))
|
||||
assert(#(matcher:match("www.example.com")) == 1)
|
||||
local matcher = require("xray.geodata").DomainMatcher("example.com", "full:other.com")
|
||||
assert(matcher:MatchAny("example.com"))
|
||||
assert(matcher:MatchAny("www.example.com"))
|
||||
assert(matcher:MatchAny("other.com"))
|
||||
assert(not matcher:MatchAny("www.other.com"))
|
||||
assert(#(matcher:Match("www.example.com")) == 1)
|
||||
`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -51,8 +51,8 @@ func TestLuaMatchersRejectInvalidRules(t *testing.T) {
|
||||
name string
|
||||
script string
|
||||
}{
|
||||
{"IP rule", `require("xray.geodata").ipMatcher("not-an-ip")`},
|
||||
{"non-string domain rule", `require("xray.geodata").domainMatcher("example.com", true)`},
|
||||
{"IP rule", `require("xray.geodata").IPMatcher("not-an-ip")`},
|
||||
{"non-string domain rule", `require("xray.geodata").DomainMatcher("example.com", true)`},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
L := lua.NewState()
|
||||
|
||||
Reference in New Issue
Block a user