예제 #1
0
func TestRegress(t *testing.T) {
	s := suggest.New(testing.Verbose())

	testDirs := flag.Args()
	if len(testDirs) == 0 {
		var err error
		testDirs, err = filepath.Glob("testdata/test.*")
		if err != nil {
			t.Fatal(err)
		}
	}

	failed := 0
	for _, testDir := range testDirs {
		if !testRegress(t, s, testDir) {
			failed++
		}
	}
	if failed != 0 {
		t.Errorf("%d failed / %d total", failed, len(testDirs))
	}
}
예제 #2
0
func (s *Server) AutoComplete(req *AutoCompleteRequest, res *AutoCompleteReply) error {
	defer func() {
		if err := recover(); err != nil {
			fmt.Printf("panic: %s\n\n", err)
			debug.PrintStack()

			res.Candidates = []suggest.Candidate{
				{Class: "PANIC", Name: "PANIC", Type: "PANIC"},
			}
		}
	}()
	if *g_debug {
		var buf bytes.Buffer
		log.Printf("Got autocompletion request for '%s'\n", req.Filename)
		log.Printf("Cursor at: %d\n", req.Cursor)
		buf.WriteString("-------------------------------------------------------\n")
		buf.Write(req.Data[:req.Cursor])
		buf.WriteString("#")
		buf.Write(req.Data[req.Cursor:])
		log.Print(buf.String())
		log.Println("-------------------------------------------------------")
	}
	now := time.Now()
	var imp types.Importer = gbimporter.New(&req.Context, req.Filename)
	candidates, d := suggest.New(*g_debug).Suggest(imp, req.Filename, req.Data, req.Cursor)
	elapsed := time.Since(now)
	if *g_debug {
		log.Printf("Elapsed duration: %v\n", elapsed)
		log.Printf("Offset: %d\n", res.Len)
		log.Printf("Number of candidates found: %d\n", len(candidates))
		log.Printf("Candidates are:\n")
		for _, c := range candidates {
			log.Printf("  %s\n", c.String())
		}
		log.Println("=======================================================")
	}
	res.Candidates, res.Len = candidates, d
	return nil
}