package product

import (
    "testing"
)

func TestNormalizeJSON(t *testing.T) {
    if normalizeJSON("") != "[]" {
        t.Fatalf("normalize empty")
    }
    if normalizeJSON("[\"a\",\"b\"]") != "[\"a\",\"b\"]" {
        t.Fatalf("normalize valid")
    }
    if normalizeJSON("not json") != "[]" {
        t.Fatalf("normalize invalid")
    }
}

func TestSplitImages(t *testing.T) {
    imgs := splitImages("[\"x\",\"y\"]")
    if len(imgs) != 2 || imgs[0] != "x" || imgs[1] != "y" {
        t.Fatalf("split images failed: %v", imgs)
    }
}

func TestFirstImage(t *testing.T) {
    if firstImage("[]") != "" {
        t.Fatalf("first empty")
    }
    if firstImage("[\"a\",\"b\"]") != "a" {
        t.Fatalf("first element")
    }
}