summaryrefslogtreecommitdiff
path: root/lib/converter_test.go
diff options
context:
space:
mode:
authoropenai-code-agent[bot] <[email protected]>2026-03-06 20:57:16 +0000
committeropenai-code-agent[bot] <[email protected]>2026-03-06 20:57:16 +0000
commitc2ca6487add435663073d714b0d5f2792f977e55 (patch)
treeec3ae30539110bb57fe8f9cbed926639256d4482 /lib/converter_test.go
parent23a7bbf963aca608ce1344f2f1986034020ad8c3 (diff)
test: add comprehensive lib package coveragecodex/add-unit-tests-lib-package
Diffstat (limited to 'lib/converter_test.go')
-rw-r--r--lib/converter_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/converter_test.go b/lib/converter_test.go
new file mode 100644
index 00000000..9c92a569
--- /dev/null
+++ b/lib/converter_test.go
@@ -0,0 +1,44 @@
+package lib
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestRegisterInputConverter(t *testing.T) {
+ resetInputConverters()
+ if err := RegisterInputConverter("json", mockInputConverter{typ: "json", action: ActionAdd}); err != nil {
+ t.Fatalf("RegisterInputConverter() error = %v", err)
+ }
+ if err := RegisterInputConverter("json", mockInputConverter{}); err != ErrDuplicatedConverter {
+ t.Fatalf("expected ErrDuplicatedConverter, got %v", err)
+ }
+}
+
+func TestRegisterOutputConverter(t *testing.T) {
+ resetOutputConverters()
+ if err := RegisterOutputConverter("txt", mockOutputConverter{typ: "txt", action: ActionOutput}); err != nil {
+ t.Fatalf("RegisterOutputConverter() error = %v", err)
+ }
+ if err := RegisterOutputConverter("txt", mockOutputConverter{}); err != ErrDuplicatedConverter {
+ t.Fatalf("expected ErrDuplicatedConverter, got %v", err)
+ }
+}
+
+func TestListConverters(t *testing.T) {
+ resetInputConverters()
+ resetOutputConverters()
+
+ _ = RegisterInputConverter("b", mockInputConverter{typ: "b", desc: "second"})
+ _ = RegisterInputConverter("a", mockInputConverter{typ: "a", desc: "first"})
+ _ = RegisterOutputConverter("x", mockOutputConverter{typ: "x", desc: "out"})
+
+ out := captureOutput(t, func() {
+ ListInputConverter()
+ ListOutputConverter()
+ })
+
+ if !strings.Contains(out, "a") || !strings.Contains(out, "b") || !strings.Contains(out, "x") {
+ t.Fatalf("unexpected output: %s", out)
+ }
+}