Files
昔念 685069fded feat(cool): 添加敏感词过滤功能
- 引入 go-sensitive-word 敏感词过滤库
- 在全局初始化中加载敏感词库并配置过滤器
- 在创建玩家时应用敏感词过滤,替换不合适的昵称内容
2025-09-09 01:11:10 +08:00

49 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package go_sensitive_word
import (
"fmt"
"testing"
)
func TestEmail(t *testing.T) {
input := "我的邮箱是example@example.com你的是test@test.com。"
if HasEmail(input) {
masked := MaskEmail(input)
fmt.Println("替换后的字符串:", masked)
} else {
fmt.Println("字符串中不存在邮箱。")
}
}
func TestURL(t *testing.T) {
input := "我的网址是http://example.com你的是https://test.com。"
if HasURL(input) {
masked := MaskURL(input)
fmt.Println("替换后的字符串:", masked)
} else {
fmt.Println("字符串中不存在网址。")
}
}
func TestDigit(t *testing.T) {
input := "我的手机号码是1234567890你的是9876543210。"
if HasDigit(input, 3) {
masked := MaskDigit(input)
fmt.Println("替换后的字符串:", masked)
} else {
fmt.Println("字符串中不存在指定个数的数字。")
}
}
func TestWechat(t *testing.T) {
input := "我的是my_wechat123你的微信是your-wechat-789。"
if HasWechatID(input) {
masked := MaskWechatID(input)
fmt.Println("替换后的字符串:", masked)
} else {
fmt.Println("字符串中不存在微信号。")
}
}