Пример #1
0
func TestAll(t *testing.T) {
	for _, v := range Tests {
		cc, e := parser.Parse([]byte(v.c))
		if e != nil {
			t.Log(e)
			t.Fail()
		}
		fb := gap.New([]byte(v.i))
		f, _ := New(fb)
		e = f.Run(cc)
		if e != nil {
			t.Log(e)
			t.Fail()
		}
		// Check so that the output is correct
		bs, _ := f.f.Get(0, f.f.Length())
		so := string(bs)
		if len(so) == len(v.o) {
			for i := range so {
				if so[i] != v.o[i] {
					goto Fail
				}
			}
			// goto Fail
			continue
		}
	Fail:
		t.Log(v.desc)
		t.Log("Not equal output")
		t.Log("Expected: `", v.o, "`")
		t.Log("Got:      `", so, "`")
		t.FailNow()
	}
}
Пример #2
0
func createFile(size int) *File {
	// Keep filling with random runes, ensuring that we have somewhat reasonable line lengths
	buf := make([]byte, size)
	var added int
	for added = 0; added < size-2; {
		var r rune

		// Get a random from letters
		lets := unicode.Categories["L"].R16
		cid := rand.Intn(len(lets) - 1)
		re := lets[cid]
		// And get a random one from this stride!
		num := rand.Intn(int((re.Hi - re.Lo) / re.Stride))
		r = rune(re.Lo + uint16(num)*re.Stride)
		//
		// So now encode the rune into our slice!
		f := rand.Float32()
		if f < 1.0/40.0 {
			r = '\n'
		}
		le := utf8.EncodeRune(buf[added:], r)
		added += le
	}
	// Fill with something we know for sure is 1 byte long
	for i := added; i < len(buf); i++ {
		buf[i] = byte('a')
	}
	f, _ := New(gap.New(buf))
	return f
}
Пример #3
0
package test

import (
	"github.com/vron/sem/memfile"
	"io/ioutil"
	//"sams/memfile/blocks"
	"github.com/vron/sem/memfile/gap"
	//	"github.com/vron/sem/memfile/slice"
	"testing"
)

var imp = []memfile.File{
	gap.New(nil),
	//	slice.New(nil),
}

// TODO: This testing should be made much more rigorous!! (It is an important building block..)

// Test all implementations of memfiles!
func TestAll(t *testing.T) {
	for _, f := range imp {
		// Do some operations and check that we get what we expect!
		f.Change(0, 0, []byte("12345"))
		f.Change(0, 0, []byte("0"))
		f.Change(6, 6, []byte("6"))
		f.Change(1, 5, nil)
		expect(t, f, "056")
		// Add some rows so we may test also the other funcitons
		f.Change(2, 2, []byte("\n"))
		f.Change(1, 1, []byte("\n"))
		f.Change(5, 5, []byte("\nrow"))