File size: 1,474 Bytes
18e58fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Tests for utility functions."""

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

from api.utils import parse_citations, format_score


def test_parse_citations_uae_law():
    result = parse_citations("Under Federal Decree-Law No. 8 of 2017")
    assert "[" in result
    assert "elaws.moj.gov.ae" in result


def test_parse_citations_india_law():
    # "Income Tax Act" needs space between Income and Tax matched
    result = parse_citations("Under the Income-Tax Act, 1961")
    assert "[" in result
    assert "indiankanoon.org" in result


def test_parse_citations_section():
    result = parse_citations("Section 194 of the Act")
    assert "[" in result


def test_no_double_wrapping():
    result = parse_citations("Already [linked](https://example.com) text")
    # Should not double-wrap
    
    import re
    # Count the number of markdown links
    links = re.findall(r'\[([^\]]+)\]\(([^\)]+)\)', result)
    # Should have at most 1 link
    assert len(links) >= 1


def test_format_score_high():
    assert format_score(0.9) == "High"


def test_format_score_medium():
    assert format_score(0.6) == "Medium"


def test_format_score_low():
    assert format_score(0.3) == "Low"


def test_format_score_boundary_high():
    # > 0.8 for High, so 0.8 is Medium
    assert format_score(0.8) == "Medium"


def test_format_score_boundary_medium():
    # > 0.5 for Medium, so 0.5 is Low
    assert format_score(0.5) == "Low"