代码拉取完成,页面将自动刷新
同步操作将从 烈冰/go_sexy 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// main_test
package main
import (
"net/url"
"testing"
)
type toAbsTest struct {
pageURL, href, result string
}
var toAbsTestData = []toAbsTest{
{"http://blog.hoday.cn", "?page=1", "http://blog.hoday.cn/?page=1"},
{"http://blog.hoday.cn", "/tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn", "tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn", "http://blog.hoday.cn/post/java.html", "http://blog.hoday.cn/post/java.html"},
{"http://blog.hoday.cn", "../tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn/index.html", "?page=1", "http://blog.hoday.cn/index.html?page=1"},
{"http://blog.hoday.cn/index.html", "/tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn/index.html", "tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn/index.html", "http://blog.hoday.cn/post/java.html", "http://blog.hoday.cn/post/java.html"},
{"http://blog.hoday.cn/index.html", "../tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn/post/golang.html", "?page=1", "http://blog.hoday.cn/post/golang.html?page=1"},
{"http://blog.hoday.cn/post/golang.html", "/tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
{"http://blog.hoday.cn/post/golang.html", "tag/coding.html", "http://blog.hoday.cn/post/tag/coding.html"},
{"http://blog.hoday.cn/post/golang.html", "http://blog.hoday.cn/post/java.html", "http://blog.hoday.cn/post/java.html"},
{"http://blog.hoday.cn/post/golang.html", "../tag/coding.html", "http://blog.hoday.cn/tag/coding.html"},
}
var toAbsBenchmark = []string{"?page=1", "/tag/coding.html", "tag/coding.html","http://blog.hoday.cn/post/java.html","../tag/coding.html"}
func TestToAbs(t *testing.T) {
for _, test := range toAbsTestData {
p, err := url.Parse(test.pageURL)
if err != nil {
t.Fatalf("url.Parse(%q) %q", test.pageURL, err) //调用Fatal后会中断当前的测试函数
}
if u := toAbs(p, test.href); u.String() != test.result {
t.Errorf("toAbs(%q, %q) = %q, 期望值 %q", p, test.href, u, test.result) //调用Error不会中断
}
}
}
func BenchmarkToAbs(b *testing.B) {
b.StopTimer()
pageURL := "http://blog.hoday.cn/post/golang.html"
p, err := url.Parse(pageURL)
if err != nil {
b.Fatalf("url.Parse(%q) %q", pageURL, err) //调用Fatal后会中断当前的测试函数
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for _, val := range toAbsBenchmark{
if u := toAbs(p, val); u == nil {
b.Fatalf("toAbs(%q, %q) 出错", p, val) //调用Error不会中断
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。