Skip to content

Commit

Permalink
fix: remove dependency to slices package
Browse files Browse the repository at this point in the history
  • Loading branch information
halimath committed Nov 20, 2023
1 parent 40200c5 commit 4c32fd5
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions cmd/expect-migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"go/token"
"io"
"os"
"slices"
"strconv"
)

Expand Down Expand Up @@ -161,7 +160,7 @@ func (v *expectationRewriteVisitor) removeMarkedStatments(currentBlock *blockFra
stmts := make([]ast.Stmt, 0, len(currentBlock.block.List))

for i := range currentBlock.block.List {
if !slices.Contains(currentBlock.stmtsToRemove, i) {
if !contains(currentBlock.stmtsToRemove, i) {
stmts = append(stmts, currentBlock.block.List[i])
}
}
Expand All @@ -176,24 +175,7 @@ func (v *expectationRewriteVisitor) Visit(node ast.Node) ast.Visitor {

currentBlock, _ := v.blocks.Peek()

// if node == nil {
// if currentBlock != nil {
// if currentBlock.nestingCount == 0 {
// }
// }

// return nil
// }

// if currentBlock != nil {
// currentBlock.nestingCount++
// }

if b, ok := node.(*ast.BlockStmt); ok {
// if currentBlock != nil {
// currentBlock.nestingCount--
// }

v.blocks.Push(&blockFrame{
block: b,
currentStmtIndex: -1,
Expand Down Expand Up @@ -236,7 +218,7 @@ func (v *expectationRewriteVisitor) Visit(node ast.Node) ast.Visitor {
return v
}

if !slices.Contains(chainingMethodNames, sel.Sel.Name) {
if !contains(chainingMethodNames, sel.Sel.Name) {
if currentBlock != nil {
currentBlock.lastExpectation = nil
}
Expand Down Expand Up @@ -292,7 +274,6 @@ func (v *expectationRewriteVisitor) Visit(node ast.Node) ast.Visitor {
if len(expectThatCall.Args) != 2 {
if currentBlock != nil {
currentBlock.lastExpectation = nil
// currentBlock.nestingCount--
}

return nil
Expand Down Expand Up @@ -349,7 +330,6 @@ func (v *expectationRewriteVisitor) Visit(node ast.Node) ast.Visitor {
currentBlock.lastExpectation = call
}

// currentBlock.nestingCount--
return nil
}

Expand Down Expand Up @@ -379,3 +359,13 @@ func (s *Stack[T]) Peek() (v T, ok bool) {
ok = true
return
}

func contains[S ~[]E, E comparable](s S, v E) bool {
for i := range s {
if s[i] == v {
return true
}
}

return false
}

0 comments on commit 4c32fd5

Please sign in to comment.