Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"remark": "^15.0.1",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"tree-sitter-wasms": "^0.1.13",
"ts-morph": "^27.0.2",
"unified": "^11.0.5"
"unified": "^11.0.5",
"web-tree-sitter": "^0.25.10"
}
}
16 changes: 16 additions & 0 deletions packages/core/src/scanner/__tests__/fixtures/go/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions packages/core/src/scanner/__tests__/fixtures/go/methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Package example demonstrates methods with receivers.
package example

import (
"context"
"fmt"
"time"
)

// ExpBackoff helps implement exponential backoff for retries.
// It is useful in distributed systems for retrying operations.
type ExpBackoff struct {
initialWait time.Duration
maxWait time.Duration
multiplier float64
numFailures int
}

// NewExpBackoff creates a new ExpBackoff instance.
func NewExpBackoff(initial, max time.Duration, mult float64) *ExpBackoff {
return &ExpBackoff{
initialWait: initial,
maxWait: max,
multiplier: mult,
}
}

// Success resets the backoff state after a successful operation.
func (e *ExpBackoff) Success() {
e.numFailures = 0
}

// MarkFailAndGetWait increments failure count and returns wait duration.
// This uses a pointer receiver because it modifies state.
func (e *ExpBackoff) MarkFailAndGetWait() time.Duration {
e.numFailures++
return e.calculateWait()
}

// calculateWait computes the wait time (unexported method).
func (e *ExpBackoff) calculateWait() time.Duration {
// Implementation details...
return e.initialWait
}

// String returns a string representation (value receiver).
func (e ExpBackoff) String() string {
return fmt.Sprintf("ExpBackoff{failures: %d}", e.numFailures)
}

// Connection represents a network connection.
type Connection struct {
host string
port int
timeout time.Duration
isActive bool
}

// Connect establishes a connection to the remote host.
func (c *Connection) Connect(ctx context.Context) error {
c.isActive = true
return nil
}

// Close terminates the connection.
func (c *Connection) Close() error {
c.isActive = false
return nil
}

// IsActive returns whether the connection is currently active.
// Uses value receiver since it doesn't modify state.
func (c Connection) IsActive() bool {
return c.isActive
}

// Host returns the connection host.
func (c Connection) Host() string {
return c.host
}

91 changes: 91 additions & 0 deletions packages/core/src/scanner/__tests__/fixtures/go/simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Package example provides example Go code for scanner testing.
package example

import (
"context"
"fmt"
)

// MaxRetries is the maximum number of retry attempts.
const MaxRetries = 3

// DefaultTimeout is the default timeout duration.
const DefaultTimeout = 30

// privateConst should not be extracted (unexported).
const privateConst = "hidden"

// Config holds application configuration.
type Config struct {
Host string
Port int
Timeout int
}

// Server represents a server instance.
// It handles incoming requests and manages connections.
type Server struct {
config *Config
running bool
}

// Reader defines the interface for reading data.
type Reader interface {
// Read reads data into the provided buffer.
Read(p []byte) (n int, err error)
}

// Writer defines the interface for writing data.
type Writer interface {
Write(p []byte) (n int, err error)
}

// ReadWriter combines Reader and Writer interfaces.
type ReadWriter interface {
Reader
Writer
}

// ID is a type alias for string identifiers.
type ID string

// Handler is a function type for request handlers.
type Handler func(ctx context.Context, req Request) Response

// Request represents an incoming request.
type Request struct {
ID ID
Payload []byte
}

// Response represents an outgoing response.
type Response struct {
ID ID
Status int
Body []byte
}

// NewServer creates a new server with the given configuration.
// It initializes all internal state and validates the config.
func NewServer(cfg *Config) *Server {
return &Server{
config: cfg,
running: false,
}
}

// Start begins the server and starts accepting connections.
func Start(ctx context.Context) error {
fmt.Println("Starting server...")
return nil
}

// processRequest handles a single request.
// This is an unexported function.
func processRequest(req Request) Response {
return Response{
ID: req.ID,
Status: 200,
Body: []byte("OK"),
}
}
29 changes: 29 additions & 0 deletions packages/core/src/scanner/__tests__/fixtures/go/simple_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Package example contains tests for the example package.
package example

import (
"testing"
)

// TestNewServer tests server creation.
func TestNewServer(t *testing.T) {
cfg := &Config{Host: "localhost", Port: 8080}
server := NewServer(cfg)
if server == nil {
t.Error("expected server to be created")
}
}

// TestProcessRequest tests request processing.
func TestProcessRequest(t *testing.T) {
req := Request{ID: "test-1", Payload: []byte("hello")}
resp := processRequest(req)
if resp.Status != 200 {
t.Errorf("expected status 200, got %d", resp.Status)
}
}

// helperFunction is a test helper (unexported).
func helperFunction() string {
return "helper"
}
Loading