"""Tests for core types."""
import pytest
from paper2md.types import BBox, Span, TextLine, BlockType, PipelineConfig


class TestBBox:
    def test_properties(self):
        bb = BBox(10, 20, 110, 70)
        assert bb.width == 100
        assert bb.height == 50
        assert bb.area == 5000
        assert bb.midx == 60
        assert bb.midy == 45

    def test_overlaps(self):
        a = BBox(0, 0, 100, 100)
        b = BBox(50, 50, 150, 150)
        assert a.overlaps(b, threshold=0.1)

    def test_no_overlap(self):
        a = BBox(0, 0, 10, 10)
        b = BBox(50, 50, 60, 60)
        assert not a.overlaps(b)

    def test_from_tuple(self):
        bb = BBox.from_tuple((1, 2, 3, 4))
        assert bb.x0 == 1 and bb.y1 == 4


class TestSpan:
    def test_is_bold(self):
        s = Span("text", "NimbusRomNo9L-Medi", 12.0, 0, 0, BBox(0, 0, 10, 10))
        assert s.is_bold

    def test_not_bold(self):
        s = Span("text", "NimbusRomNo9L-Regu", 12.0, 0, 0, BBox(0, 0, 10, 10))
        assert not s.is_bold

    def test_is_italic(self):
        s = Span("text", "NimbusRomNo9L-ReguItalic", 12.0, 0, 0, BBox(0, 0, 10, 10))
        assert s.is_italic


class TestTextLine:
    def test_text(self):
        spans = [
            Span("Hello ", "Font", 12, 0, 0, BBox(0, 0, 30, 10)),
            Span("World", "Font", 12, 0, 0, BBox(30, 0, 60, 10)),
        ]
        line = TextLine(spans=spans, bbox=BBox(0, 0, 60, 10))
        assert line.text == "Hello World"

    def test_dominant_size(self):
        spans = [
            Span("Hello World this is long", "Font", 12, 0, 0, BBox(0, 0, 100, 10)),
            Span("x", "Font", 8, 0, 0, BBox(100, 0, 105, 10)),
        ]
        line = TextLine(spans=spans, bbox=BBox(0, 0, 105, 10))
        assert line.dominant_size == 12
