Skip to content

Commit

Permalink
fix: Fix example code
Browse files Browse the repository at this point in the history
  • Loading branch information
chonla committed Oct 17, 2024
1 parent 5e28d30 commit 6cdb8f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@ func main() {
fmt.Println(cellwalker.At("ZZZ2").ColumnOffset(5).RowOffset(10).String()) // XFD12

// Range walking apply other boundary to walker
cellwalker.Within("C2:H3").At("C3").Right().Below().String()) // C4
fmt.Println(cellwalker.Within("C2:H3").At("C3").Right().Below().String()) // D3

// Too far jump in a new boundary
cellwalker.Within("C2:H3").At("ZZZ2").ColumnOffset(5).RowOffset(10).String()) // H3
fmt.Println(cellwalker.Within("C2:H3").At("ZZZ2").ColumnOffset(5).RowOffset(10).String()) // XFD12

// Range traversal
result1 := cellwalker.Within("B3:E5").At("C4") // Define range and initial cell position
result2 := result1.Tour() // result2 = D4
result3 := result2.Tour() // result3 = E4
result4 := result3.Tour() // result4 = B5
result5 := result4.Tour() // result5 = C5
result6 := result5.Tour() // result6 = D5
result7 := result6.Tour() // result7 = E5
result8 := result7.Tour() // nil
fmt.Println(result1.String()) // C4
result2 := result1.Tour()
fmt.Println(result2.String()) // D4
result3 := result2.Tour()
fmt.Println(result3.String()) // E4
result4 := result3.Tour()
fmt.Println(result4.String()) // B5
result5 := result4.Tour()
fmt.Println(result5.String()) // C5
result6 := result5.Tour()
fmt.Println(result6.String()) // D5
result7 := result6.Tour()
fmt.Println(result7.String()) // E5
result8 := result7.Tour()
fmt.Println(result8 == nil) // true
}
```

Expand Down
8 changes: 8 additions & 0 deletions cellwalker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,11 @@ func TestRowIndex(t *testing.T) {

assert.Equal(t, 4, result)
}

func TestChainTraversal(t *testing.T) {
result := Within("C2:H3").At("C3").
Right(). // Cannot move further right, hit the boundary
Below() // Move down

assert.Equal(t, "D3", result.String())
}

0 comments on commit 6cdb8f7

Please sign in to comment.