aboutsummaryrefslogtreecommitdiff
path: root/tests/atoms/cidr.test.py
blob: a7dc9c9d9189dc50ec27deb91514abd214744e74 (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
from edify import Pattern
from edify.atoms import cidr


def _anchored():
    return Pattern().start_of_input().use(cidr).end_of_input()


def test_accepts_sample_from_shape():
    assert _anchored()("10.0.0.0/8")


def test_rejects_off_shape_input():
    assert not _anchored()("10.0.0.0")


def test_atom_composes_inside_a_larger_pattern():
    embedded = Pattern().start_of_input().string("v=").use(cidr).end_of_input()
    assert embedded("v=" + "10.0.0.0/8")
    assert not embedded("10.0.0.0/8")


def test_atom_regex_string_is_non_empty():
    fragment = cidr.to_regex_string()
    assert fragment
    assert isinstance(fragment, str)