Пример #1
0
func BenchmarkTransformTranscribe(b *testing.B) {
	b.StopTimer()
	w := GetEditor().NewWindow()
	defer w.Close()

	v := w.NewFile()

	defer func() {
		v.SetScratch(true)
		v.Close()
	}()

	sc, err := textmate.LoadTheme("../packages/themes/TextMate-Themes/GlitterBomb.tmTheme")
	if err != nil {
		b.Fatal(err)
	}

	v.Settings().Set("syntax", "textmate/testdata/Go.tmLanguage")

	d, err := ioutil.ReadFile("view.go")
	if err != nil {
		b.Fatal(err)
	}
	var wg sync.WaitGroup
	wg.Add(1)
	v.Settings().AddOnChange("benchmark", func(key string) {
		if key == "lime.syntax.updated" {
			wg.Done()
		}
	})
	e := v.BeginEdit()
	v.Insert(e, 0, string(d))
	v.EndEdit(e)
	wg.Wait()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		v.Transform(sc, text.Region{A: 0, B: v.Buffer().Size()}).Transcribe()
	}
	fmt.Println(util.Prof.String())
}
Пример #2
0
func TestTransform(t *testing.T) {
	w := GetEditor().NewWindow()
	defer w.Close()

	v := w.NewFile()
	defer func() {
		v.SetScratch(true)
		v.Close()
	}()

	sc, err := textmate.LoadTheme("../packages/themes/TextMate-Themes/GlitterBomb.tmTheme")
	if err != nil {
		t.Fatal(err)
	}

	d, err := ioutil.ReadFile("view.go")
	if err != nil {
		t.Fatal(err)
	}
	e := v.BeginEdit()
	v.Insert(e, 0, string(d))
	v.EndEdit(e)

	if v.Transform(sc, text.Region{A: 0, B: 100}) != nil {
		t.Error("Expected view.Transform return nil when the syntax isn't set yet")
	}

	v.Settings().Set("syntax", "textmate/testdata/Go.tmLanguage")

	time.Sleep(time.Second)
	a := v.Transform(sc, text.Region{A: 0, B: 100}).Transcribe()
	v.Transform(sc, text.Region{A: 100, B: 200}).Transcribe()
	c := v.Transform(sc, text.Region{A: 0, B: 100}).Transcribe()
	if !reflect.DeepEqual(a, c) {
		t.Errorf("not equal:\n%v\n%v", a, c)
	}
}