Skip to content

Commit

Permalink
example: update order
Browse files Browse the repository at this point in the history
Signed-off-by: Iskander Sharipov <[email protected]>
  • Loading branch information
quasilyte committed Jan 25, 2019
1 parent b5dbf09 commit b1a996f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
28 changes: 8 additions & 20 deletions example/demo.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,20 @@
# Both packages have a func that implements strings.Repeat.
# Suppose we found 1 such place in our codebase and calls to it
# with strings.Repeat. But how maybe there are more such funcs?
#
# Note that their source code differs.
# One uses for loop, the other uses range form of loop.
# One uses const, the other don't.
cat mylib1/mylib1.go
cat mylib2/mylib2.go

# Normalized forms are more-or-less the same.
# Only variables names differ.
go-normalize mylib1/mylib1.go

go-normalize mylib2/mylib2.go

# Make normalized packages.
cat mylib1/mylib1.go
go-normalize mylib1/mylib1.go > mylib1n/mylib1.go
go-normalize mylib2/mylib2.go > mylib2n/mylib2.go

# Compare mylib1.go before and after normalization.
vimdiff mylib1/mylib1.go mylib1n/mylib1.go
diff mylib1/mylib1.go mylib1n/mylib1.go

# Compare normalized mylib1.go and normalized mylib2.go.
vimdiff mylib1n/mylib1.go mylib2n/mylib2.go
cat mylib2/mylib2.go
go-normalize mylib2/mylib2.go > mylib2n/mylib2.go
diff mylib2/mylib2.go mylib2n/mylib2.go

# Use grepfunc to create a pattern from Go code.
# With syntax patterns, we can now ignore variable
# names differences and find both functions
# by either of them.
grepfunc -input mylib1n/mylib1.go -pattern=makeString ./...
grepfunc -input mylib2n/mylib2.go -pattern=repeatString ./...
grepfunc -v -input mylib2n/mylib2.go -pattern=repeatString ./...

# For more examples see consult README file.
14 changes: 14 additions & 0 deletions example/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example

func _(xs []int) []int {
const toRemove = 10
var filtered []int
filtered = xs[0:0]
for i := int(0); i < len(xs); i++ {
x := xs[i]
if toRemove+1 != x {
filtered = append(filtered, x)
}
}
return (filtered)
}

0 comments on commit b1a996f

Please sign in to comment.