From 845a230b34e8d7bd7eda0371376f41d22c40c164 Mon Sep 17 00:00:00 2001 From: crStiv Date: Fri, 27 Dec 2024 03:09:08 +0100 Subject: [PATCH] Create api_test.go --- frontend/api_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 frontend/api_test.go diff --git a/frontend/api_test.go b/frontend/api_test.go new file mode 100644 index 000000000..25493586b --- /dev/null +++ b/frontend/api_test.go @@ -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) +}