Skip to content

Commit

Permalink
Create api_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
crStiv authored Dec 27, 2024
1 parent 9a878c0 commit 845a230
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions frontend/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package api

import (
"testing"
"strings"

"github.com/your-project/frontend"
"github.com/stretchr/testify/require"
)

func TestPrintf(t *testing.T) {
assert := require.New(t)

var circuit struct {
X, Y frontend.Variable
Const frontend.Variable
}

api := NewTestAPI(t)

// Create a mock to capture output
var output strings.Builder
api.SetOutput(&output)

circuit.Const = 42
api.Printf("const decimal: %d\n", circuit.Const)
assert.Contains(output.String(), "const decimal: 42")

// Test variables
circuit.X = api.Add(10, 20)
circuit.Y = api.Mul(5, 5)

api.Printf("variables: %v %v\n", circuit.X, circuit.Y)

// Test special formats
api.Printf("coeff: %c var: %i\n", circuit.X, circuit.Y)

// Test mixed output
api.Printf("mixed: %d %x %v %c %i\n",
circuit.Const, circuit.X, circuit.Y, circuit.X, circuit.Y)

// Test edge cases
api.Printf("")
api.Printf("%")
api.Printf("%%")
api.Printf("%d")
api.Printf("%d%d", circuit.X)
}

0 comments on commit 845a230

Please sign in to comment.