# Path: tlfp/tools/parse_texte.py
# class TextParsingFailedException(Exception):
# def word_to_number(word):
# def non_recursive_find_all(node, should_be_parsed, should_be_ignored):
# def clean_extra_expose_des_motifs(html):
# def clean_extra_expose_des_motifs_v2(html):
# def romans(n):
# def lower_but_first(text):
# def clean_full_upcase(text):
# def clean_html(t):
# def check_section_is_not_a_duplicate(section_id, articles):
# def add_to_articles(dic, all_articles):
# def normalize_1(name, one):
# def normalize_section_title(line, line_soup, has_multiple_expose):
# def clean_article_name(text):
# def parse(url, resp=None, DEBUG=False, include_annexes=False):
#     def pr_js(article):
#     def should_be_parsed(x):
#     def should_be_ignored(x):
#     NEW_LINE_MARKER = 'NEW_LINE_MARKER'
#     READ_DISABLED = -1 # the text is not detected yet
#     READ_TEXT = 0 # read the text
#     READ_TITLE = 1 # titles lecture
#     READ_ALINEAS = 2 # alineas lecture


from tlfp.tools.parse_texte import (
    clean_article_name, clean_html, normalize_1, re_clean_conf, re_mat_sec
)


def assert_eq(x, y):
    if x != y:
        print(repr(x), "!=", repr(y))
        raise Exception()


# keep the dots
assert_eq(clean_html('<i>....................</i>'), '<i>....................</i>')
# but remove them for status
assert_eq(clean_html('...........Conforme.........'), 'Conforme')
assert_eq(clean_html('...……......……..Conforme....……...…….'), 'Conforme')
# even with spaces
assert_eq(clean_html('...........  Conforme   .........'), 'Conforme')
# or for alineas
assert_eq(clean_html('II. - <i>Conforme</i>...............'), 'II. - <i>Conforme</i>')
# even midway alineas
assert_eq(clean_html('II. - <i>Conforme</i>............... ;'), 'II. - <i>Conforme</i> ;')

# clean empty <a> tags
assert_eq(clean_html('<b><a name="P302_55065"></a>ANNEXE N° 1 :<a name="P302_55081"><br/> </a>TEXTE ADOPTÉ PAR LA COMMISSION</b>'), '<b>ANNEXE N° 1 : TEXTE ADOPTÉ PAR LA COMMISSION</b>')

# clean status
assert_eq(re_clean_conf.sub(r'\1(Non modifié)', 'IV. - Non modifié'), 'IV. - (Non modifié)')
assert_eq(re_clean_conf.sub(r'\1(Non modifié)', 'III et IV. - Non modifié'), 'III et IV. - (Non modifié)')

assert_eq(normalize_1('1', '1er'), '1er')
assert_eq(normalize_1('17', '1er'), '17')

# Path: tlfp/tools/parse_texte.py
# class TextParsingFailedException(Exception):
# def word_to_number(word):
# def non_recursive_find_all(node, should_be_parsed, should_be_ignored):
# def clean_extra_expose_des_motifs(html):
# def clean_extra_expose_des_motifs_v2(html):
# def romans(n):
# def lower_but_first(text):
# def clean_full_upcase(text):
# def clean_html(t):
# def check_section_is_not_a_duplicate(section_id, articles):
# def add_to_articles(dic, all_articles):
# def normalize_1(name, one):
# def normalize_section_title(line, line_soup, has_multiple_expose):
# def clean_article_name(text):
# def parse(url, resp=None, DEBUG=False, include_annexes=False):
#     def pr_js(article):
#     def should_be_parsed(x):
#     def should_be_ignored(x):
#     NEW_LINE_MARKER = 'NEW_LINE_MARKER'
#     READ_DISABLED = -1 # the text is not detected yet
#     READ_TEXT = 0 # read the text
#     READ_TITLE = 1 # titles lecture
#     READ_ALINEAS = 2 # alineas lecture


# Path: tests/test_parse_texte.py
from tlfp.tools.parse_texte import (
    clean_article_name, clean_html, normalize_1, re_clean_conf, re_mat_sec
)



def assert_eq(x, y):
    if x != y:
        print(repr(x), "!=", repr(y))
        raise Exception()


# keep the dots
assert_eq(clean_html('<i>....................</i>'), '<i>....................</i>')
# but remove them for status
assert_eq(clean_html('...........Conforme.........'), 'Conforme')
assert_eq(clean_html('...……......……..Conforme....……...…….'), 'Conforme')
# even with spaces
assert_eq(clean_html('...........  Conforme   .........'), 'Conforme')
# or for alineas
assert_eq(clean_html('II. - <i>Conforme</i>...............'), 'II. - <i>Conforme</i>')
# even midway alineas
assert_eq(clean_html('II. - <i>Conforme</i>............... ;'), 'II. - <i>Conforme</i> ;')

# clean empty <a> tags
assert_eq(clean_html('<b><a name="P302_55065"></a>ANNEXE N° 1 :<a name="P302_55081"><br/> </a>TEXTE ADOPTÉ PAR LA COMMISSION</b>'), '<b>ANNEXE N° 1 : TEXTE ADOPTÉ PAR LA COMMISSION</b>')

# clean status
assert_eq(re_clean_conf.sub(r'\1(Non modifié)', 'IV. - Non modifié'), 'IV. - (Non modifié)')
assert_eq(re_clean_conf.sub(r'\1(Non modifié)', 'III et IV. - Non modifié'), 'III et IV. - (Non modifié)')

assert_eq(normalize_1('1', '1er'), '1er')
assert_eq(normalize_1('17', '1er'), '17')

assert_eq(normalize_1('1 bis', '1er'), '1er bis')