# Path: test/common_test_util.py
# def expected_result(contents):
#     return dedent(contents.lstrip('\n'))
# 
# Path: test/hquery/hquery_test_util.py
# def query_html_doc(html_body, hquery, preserve_space=False, wrap_body=True):
#     soup = soup_with_body(html_body) if wrap_body else make_soup(html_body)
#     raw_result = HqueryProcessor(hquery, preserve_space=preserve_space).query(soup)
#     return eliminate_blank_lines(convert_results_to_output_text(raw_result, preserve_space=preserve_space).strip())


import re
from test.common_test_util import expected_result
from test.hquery.hquery_test_util import query_html_doc



def test_class_function_returns_true_when_element_has_name_in_class_attribute():
    html_body = """
    <p class="not selected">not selected</p>
    <p class="foo bar">expected</p>"""

    assert query_html_doc(html_body, 'class(//p[1], "foo")') == 'false'
    assert query_html_doc(html_body, 'class(//p[2], "foo")') == 'true'
    assert query_html_doc(html_body, '//p[class("bar")]/text()') == 'expected'


def test_even_and_odd_functions_select_the_appropriate_elements_based_on_position():
    html_body = """
    <p>You</p>
    <p>I</p>
    <p>are</p>
    <p>am</p>
    <p>odd.</p>
    <p>even.</p>"""


# Path: test/common_test_util.py
# def expected_result(contents):
#     return dedent(contents.lstrip('\n'))
# 
# Path: test/hquery/hquery_test_util.py
# def query_html_doc(html_body, hquery, preserve_space=False, wrap_body=True):
#     soup = soup_with_body(html_body) if wrap_body else make_soup(html_body)
#     raw_result = HqueryProcessor(hquery, preserve_space=preserve_space).query(soup)
#     return eliminate_blank_lines(convert_results_to_output_text(raw_result, preserve_space=preserve_space).strip())


# Path: test/hquery/test_extended_functions.py
import re
from test.common_test_util import expected_result
from test.hquery.hquery_test_util import query_html_doc




def test_class_function_returns_true_when_element_has_name_in_class_attribute():
    html_body = """
    <p class="not selected">not selected</p>
    <p class="foo bar">expected</p>"""

    assert query_html_doc(html_body, 'class(//p[1], "foo")') == 'false'
    assert query_html_doc(html_body, 'class(//p[2], "foo")') == 'true'
    assert query_html_doc(html_body, '//p[class("bar")]/text()') == 'expected'


def test_even_and_odd_functions_select_the_appropriate_elements_based_on_position():
    html_body = """
    <p>You</p>
    <p>I</p>
    <p>are</p>
    <p>am</p>
    <p>odd.</p>
    <p>even.</p>"""


    assert query_html_doc(html_body, '//p[even()]/text()') == expected_result("""