"""Tests para to_jsonl."""

import json

from to_jsonl import to_jsonl


def test_lista_de_dicts_jsonl():
    rows = [{"a": 1}, {"b": 2}]
    result = to_jsonl(rows)
    lines = result.split("\n")
    assert len(lines) == 2
    assert json.loads(lines[0]) == {"a": 1}
    assert json.loads(lines[1]) == {"b": 2}


def test_valores_unicode_none_nested():
    rows = [{"emoji": "🔥", "nulo": None, "nested": {"x": 1}}]
    result = to_jsonl(rows)
    parsed = json.loads(result)
    assert parsed["emoji"] == "🔥"
    assert parsed["nulo"] is None
    assert parsed["nested"] == {"x": 1}


def test_lista_vacia_retorna_string_vacio():
    assert to_jsonl([]) == ""


def test_cada_linea_es_json_parseable():
    rows = [{"k": i} for i in range(5)]
    result = to_jsonl(rows)
    for i, line in enumerate(result.split("\n")):
        assert json.loads(line) == {"k": i}
