Skip to content

Commit

Permalink
tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
xt0fer committed Nov 29, 2018
1 parent 079bd24 commit 21fb748
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
22 changes: 14 additions & 8 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

// Buffer main struct
type Buffer struct {
Point int
data []rune
postLen int
Point int
postLen int
data []rune

Next *Buffer
Mark int
OrigPoint int /* b_cpoint the original current point, used for mutliple window displaying */
Expand Down Expand Up @@ -50,12 +51,13 @@ func (bp *Buffer) setText(s string) {
bp.data = []rune(s)
bp.Point = 0
bp.postLen = len(bp.data)
bp.TextSize = bp.Point + bp.postLen
}

// getText xxx
func (bp *Buffer) getText() string {
bp.TextSize = bp.Point + bp.postLen
ret := make([]rune, bp.TextSize)
//bp.TextSize = bp.Point + bp.postLen
ret := make([]rune, bp.Point+bp.postLen)
copy(ret, bp.data)
copy(ret[bp.Point:], bp.data[bp.postStart():])
return string(ret)
Expand Down Expand Up @@ -133,7 +135,8 @@ func (bp *Buffer) postStart() int {

// CollapseGap moves the gap to the end of the buffer for replacement
func (bp *Buffer) CollapseGap() {
for i := bp.Point; bp.postLen > 0; i++ {
//for i := bp.Point; bp.postLen > 0; i++ {
for bp.postLen > 0 {
bp.data[bp.Point] = bp.data[len(bp.data)-bp.postLen]
bp.Point++
bp.postLen--
Expand Down Expand Up @@ -263,7 +266,9 @@ func (bp *Buffer) LineLenAtPoint(point int) int {
if point < 0 {
point = 0
}
return bp.LineEnd(point) - bp.LineStart(point) - 1
start := bp.LineStart(point) - 1
end := bp.LineEnd(point)
return end - start
}

// PointForLine return point for beginning of line ln
Expand All @@ -288,11 +293,12 @@ func (bp *Buffer) PointForLine(ln int) int {
// LineForPoint returns the line number of point (origin = 1)
func (bp *Buffer) LineForPoint(point int) (line int) {
line = 1
pt := 0
if point >= bp.TextSize {
point = bp.TextSize - 1
}
doIncr := false
for pt := 1; pt <= point; pt++ {
for pt = 0; pt <= point; pt++ {
if doIncr {
line++
doIncr = false
Expand Down
14 changes: 7 additions & 7 deletions buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestAddRune2(t *testing.T) {

gb.DebugPrint()

t.Error("End of Buffer")
//t.Error("End of Buffer")

}
func TestCollapseGap(t *testing.T) {
Expand All @@ -66,7 +66,7 @@ func TestCollapseGap(t *testing.T) {
gb.CollapseGap()

gb.DebugPrint()
t.Error("End of Buffer")
//t.Error("End of Buffer")

}

Expand All @@ -85,7 +85,7 @@ func TestTextLines(t *testing.T) {
fmt.Println("--- [2, 5)")
fmt.Printf("%v\n", gb.getTextForLines(2, 5))
gb.DebugPrint()
t.Error("force print")
//t.Error("force print")
}

func TestLineStart(t *testing.T) {
Expand Down Expand Up @@ -554,9 +554,9 @@ func TestSetPoint(t *testing.T) {
gb.AddRune('X')
gb.AddRune('X')
gb.DebugPrint()
assert.Equal(t, 10, gb.gapStart())
assert.Equal(t, 26, gb.gapLen())

assert.Equal(t, 12, gb.gapStart())
assert.Equal(t, 24, gb.gapLen())
gb.DebugPrint()
}

func TestRuneAt(t *testing.T) {
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestRuneAt(t *testing.T) {
}
fmt.Printf("\n*********\n")
gb.DebugPrint()
t.Error("End of Buffer")
//t.Error("End of Buffer")
}

func TestSegStart(t *testing.T) {
Expand Down

0 comments on commit 21fb748

Please sign in to comment.