-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add debug functionality and false positive test
- Loading branch information
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package mirror | ||
|
||
import ( | ||
"fmt" | ||
"go/ast" | ||
"go/printer" | ||
"go/token" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// --- debug ------------------------------------------------------------------- | ||
|
||
func debug(f *token.FileSet) func(ast.Expr, string, ...any) { | ||
return func(node ast.Expr, format string, a ...any) { | ||
printer.Fprint(os.Stderr, f, node) | ||
fmt.Fprintln(os.Stderr, "\n"+strings.Repeat("^", 80)) | ||
fmt.Fprintf(os.Stderr, format, a...) | ||
} | ||
} | ||
|
||
func debugNoOp(_ ast.Expr, _ string, _ ...any) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"log" | ||
) | ||
|
||
// using function that accepts string and process it and then return []bytes | ||
func S1() { | ||
h := sha256.New() | ||
if _, err := h.Write([]byte("foobar")); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
contentBuf := bytes.NewBufferString("foo-bar\n") | ||
contentBuf.WriteString(hex.EncodeToString(h.Sum(nil))) // false postitve | ||
} |