aboutsummaryrefslogtreecommitdiff
path: root/tests/builder/diagnose.test.py
blob: 8b9e4dc2ca7b0a2a9f28b097aa9ce0cdb97d9f97 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Tests for the diagnostic helpers in :mod:`edify.builder.diagnose`."""

import pytest

from edify import Pattern, RegexBuilder
from edify.errors.comparison import CannotCompareUnfinishedBuilderError


def test_two_finished_builders_compare_equal_without_diagnostic():
    left = RegexBuilder().digit()
    right = RegexBuilder().digit()
    assert left == right


def test_open_group_frame_names_group_in_the_problem_description():
    unfinished = RegexBuilder().group().digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert "open `group()`" in text


def test_open_capture_frame_names_capture_in_the_problem_description():
    unfinished = RegexBuilder().capture().digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert "open `capture()`" in text


def test_open_named_capture_frame_names_the_name_in_the_problem_description():
    unfinished = RegexBuilder().named_capture("year").digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert 'named_capture("year")' in text


def test_open_assert_ahead_frame_names_lookahead():
    unfinished = RegexBuilder().assert_ahead().digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert "assert_ahead()" in text


def test_open_assert_not_ahead_frame_names_negative_lookahead():
    unfinished = RegexBuilder().assert_not_ahead().digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert "assert_not_ahead()" in text


def test_open_assert_behind_frame_names_lookbehind():
    unfinished = RegexBuilder().assert_behind().digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert "assert_behind()" in text


def test_open_assert_not_behind_frame_names_negative_lookbehind():
    unfinished = RegexBuilder().assert_not_behind().digit()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished == RegexBuilder()
    text = str(excinfo.value)
    assert "assert_not_behind()" in text


def test_dangling_quantifier_on_pattern_reports_quantifier_name():
    unfinished_pattern = Pattern().one_or_more()
    with pytest.raises(CannotCompareUnfinishedBuilderError) as excinfo:
        _ = unfinished_pattern == Pattern()
    text = str(excinfo.value)
    assert "pending `.one_or_more()`" in text