本文整理匯總了Golang中github.com/nsf/gothic.Interpreter.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Interpreter.Set方法的具體用法?Golang Interpreter.Set怎麽用?Golang Interpreter.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nsf/gothic.Interpreter
的用法示例。
在下文中一共展示了Interpreter.Set方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: gocov_test
func gocov_test(ir *gothic.Interpreter) {
var buf bytes.Buffer
cmd := exec.Command("gocov", "test")
cmd.Stdout = &buf
err := cmd.Run()
if err != nil {
gocov_test_error(ir, err)
return
}
result := struct{ Packages []*gocov.Package }{}
err = json.Unmarshal(buf.Bytes(), &result)
if err != nil {
gocov_test_error(ir, err)
return
}
sel := ""
current = result.Packages
for pi, p := range result.Packages {
for fi, f := range p.Functions {
r := reached(f)
n := len(f.Statements)
fun := fmt.Sprintf("%s.%s", p.Name, f.Name)
cov := fmt.Sprintf("%.2f%% (%d/%d)", percentage(r, n), r, n)
file := fmt.Sprintf("%s/%s", p.Name, filepath.Base(f.File))
id := fmt.Sprintf("f_%d_%d", pi, fi)
if prevsel != "" && prevsel == fun {
sel = id
}
ir.Eval(`.f2.funcs insert {} end -id `, id,
` -values {`, strconv.Quote(fun),
` `, strconv.Quote(file),
` `, strconv.Quote(cov), `}`)
}
}
dir := filepath.Dir(current[0].Functions[0].File)
ir.Set("pathtext", dir)
done := 0
total := 0
for _, p := range result.Packages {
for _, f := range p.Functions {
done += reached(f)
total += len(f.Statements)
}
}
ir.Set("covtext", fmt.Sprintf("Overall coverage: %.2f%% (%d/%d)",
percentage(done, total), done, total))
if sel == "" {
sel = "f_0_0"
}
ir.Eval(".f2.funcs selection set ", sel)
}
示例2: gocov_selection
func gocov_selection(ir *gothic.Interpreter) {
var selection string
ir.EvalAs(&selection, ".f2.funcs selection")
var pi, fi int
_, err := fmt.Sscanf(selection, "f_%d_%d", &pi, &fi)
if err != nil {
panic(err)
}
f := current[pi].Functions[fi]
prevsel = fmt.Sprintf("%s.%s", current[pi].Name, f.Name)
data, err := ioutil.ReadFile(f.File)
if err != nil {
panic(err)
}
ir.Set("source", string(data[f.Start:f.End]))
ir.Eval(`
.f1.sourceview configure -state normal
.f1.sourceview delete 1.0 end
.f1.sourceview insert end $source
.f1.sourceview configure -state disabled
`)
for _, s := range f.Statements {
if s.Reached != 0 {
continue
}
ls, le := s.Start-f.Start, s.End-f.Start
ir.Eval(`.f1.sourceview tag add red {1.0 +`, ls, `chars} {1.0 +`, le, `chars}`)
}
if xsourceview != "" {
ir.Eval(".f1.sourceview xview moveto [lindex {", xsourceview, "} 0]")
ir.Eval(".f1.sourceview yview moveto [lindex {", ysourceview, "} 0]")
xsourceview = ""
ysourceview = ""
}
}