"""Unit tests for product registry utilities."""
from __future__ import annotations

import pytest

from market.scrape.product.registry import merge_missing


class TestMergeMissing:
    def test_fills_empty_dict(self):
        dst = {}
        merge_missing(dst, {"a": 1, "b": "hello"})
        assert dst == {"a": 1, "b": "hello"}

    def test_existing_value_not_overwritten(self):
        dst = {"a": "original"}
        merge_missing(dst, {"a": "new"})
        assert dst["a"] == "original"

    def test_none_overwritten(self):
        dst = {"a": None}
        merge_missing(dst, {"a": "filled"})
        assert dst["a"] == "filled"

    def test_empty_string_overwritten(self):
        dst = {"a": ""}
        merge_missing(dst, {"a": "filled"})
        assert dst["a"] == "filled"

    def test_empty_list_overwritten(self):
        dst = {"a": []}
        merge_missing(dst, {"a": [1, 2]})
        assert dst["a"] == [1, 2]

    def test_empty_dict_overwritten(self):
        dst = {"a": {}}
        merge_missing(dst, {"a": {"key": "val"}})
        assert dst["a"] == {"key": "val"}

    def test_zero_not_overwritten(self):
        dst = {"a": 0}
        merge_missing(dst, {"a": 42})
        assert dst["a"] == 0

    def test_false_not_overwritten(self):
        dst = {"a": False}
        merge_missing(dst, {"a": True})
        assert dst["a"] is False

    def test_none_src(self):
        dst = {"a": 1}
        merge_missing(dst, None)
        assert dst == {"a": 1}

    def test_new_keys_added(self):
        dst = {"a": 1}
        merge_missing(dst, {"b": 2})
        assert dst == {"a": 1, "b": 2}
