コード例 #1
0
def test_conflict_solver_1():
    input_string = "123456789"

    re1 = StringPattern("2345678", conflict_solver=lambda match, conflicting: '__default__')
    re2 = StringPattern("34567")

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 1
    assert matches[0].value == "2345678"
コード例 #2
0
def test_conflict_solver_7():
    input_string = "102"

    re1 = StringPattern("102")
    re2 = StringPattern("02")

    matches = Matches(re2.matches(input_string))
    matches.extend(re1.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 1
    assert matches[0].value == "102"
コード例 #3
0
def test_conflict_solver_7():
    input_string = "102"

    re1 = StringPattern("102")
    re2 = StringPattern("02")

    matches = Matches(re2.matches(input_string))
    matches.extend(re1.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 1
    assert matches[0].value == "102"
コード例 #4
0
def test_prefer_longer_parent():
    input_string = "xxx.1x02.xxx"

    re1 = RePattern("([0-9]+)x([0-9]+)", name='prefer', children=True, formatter=int)
    re2 = RePattern("x([0-9]+)", name='skip', children=True)

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2
    assert matches[0].value == 1
    assert matches[1].value == 2
コード例 #5
0
def test_conflict_solver_1():
    input_string = "123456789"

    re1 = StringPattern(
        "2345678", conflict_solver=lambda match, conflicting: '__default__')
    re2 = StringPattern("34567")

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 1
    assert matches[0].value == "2345678"
コード例 #6
0
def test_prefer_longer_parent():
    input_string = "xxx.1x02.xxx"

    re1 = RePattern("([0-9]+)x([0-9]+)",
                    name='prefer',
                    children=True,
                    formatter=int)
    re2 = RePattern("x([0-9]+)", name='skip', children=True)

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2
    assert matches[0].value == 1
    assert matches[1].value == 2
コード例 #7
0
def test_unresolved():
    input_string = "123456789"

    re1 = StringPattern("23456")
    re2 = StringPattern("34567")

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2

    re1 = StringPattern("34567")
    re2 = StringPattern("2345678", conflict_solver=lambda match, conflicting: None)

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2

    re1 = StringPattern("34567", conflict_solver=lambda match, conflicting: None)
    re2 = StringPattern("2345678")

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2
コード例 #8
0
def test_unresolved():
    input_string = "123456789"

    re1 = StringPattern("23456")
    re2 = StringPattern("34567")

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2

    re1 = StringPattern("34567")
    re2 = StringPattern("2345678",
                        conflict_solver=lambda match, conflicting: None)

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2

    re1 = StringPattern("34567",
                        conflict_solver=lambda match, conflicting: None)
    re2 = StringPattern("2345678")

    matches = Matches(re1.matches(input_string))
    matches.extend(re2.matches(input_string))

    execute_rule(ConflictSolver(), matches, None)
    assert len(matches) == 2