Repaired old unit tests. Added unit test for span buffers ... which currently fails. :-/

This commit is contained in:
Sascha L. Teichmann
2014-10-21 16:11:20 +02:00
parent a82d20f14b
commit e744390503
3 changed files with 76 additions and 7 deletions

View File

@@ -4,6 +4,11 @@
package common
import (
"bytes"
"fmt"
)
const chunkSize = 1024
type Span struct {
@@ -184,3 +189,31 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
return head
}
func (s *Span) Visit(v func(*Span)) {
for ; s != nil; s = s.Next {
v(s)
}
}
func (s *Span) Len() int {
n := 0
for ; s != nil; s = s.Next {
n++
}
return n
}
func (s *Span) String() string {
var buf bytes.Buffer
first := true
s.Visit(func(s1 *Span) {
if !first {
buf.WriteString(", ")
} else {
first = false
}
buf.WriteString(fmt.Sprintf("(%d, %d)", s1.From, s1.To))
})
return buf.String()
}