예제 #1
0
def test_validate_pattern_double_ident():
    """A pattern with identifier used twice is incorrect"""
    with pytest.raises(adventurelib.InvalidCommand) as exc:
        Pattern("take I with I")
    err = str(exc.value)
    assert err == "Invalid command 'take I with I'"\
                  " Identifiers may only be used once"
예제 #2
0
def test_word_combinations_3():
    combos = Pattern.word_combinations(have=4, placeholders=3)
    assert list(combos) == [
        (2, 1, 1),
        (1, 2, 1),
        (1, 1, 2)
    ]
예제 #3
0
def test_word_combinations_2():
    combos = Pattern.word_combinations(have=4, placeholders=2)
    assert list(combos) == [
        (3, 1),
        (2, 2),
        (1, 3)
    ]
예제 #4
0
def test_word_combinations_4():
    combos = Pattern.word_combinations(have=5, placeholders=3)
    assert list(combos) == [
        (3, 1, 1),
        (2, 2, 1),
        (2, 1, 2),
        (1, 3, 1),
        (1, 2, 2),
        (1, 1, 3),
    ]
예제 #5
0
def test_multiple_multiword_captures():
    pat = Pattern('give ITEM to PERSON')
    matches = pat.match(['give', 'golden', 'apple', 'to', 'evil', 'wizard'])
    assert matches == {'item': 'golden apple', 'person': 'evil wizard'}
예제 #6
0
def test_capturing_multiword():
    matches = Pattern('take ITEM').match(['take', 'golden', 'apple'])
    assert matches == {'item': 'golden apple'}
예제 #7
0
def test_capturing_match():
    matches = Pattern('take ITEM').match(['take', 'apple'])
    assert matches == {'item': 'apple'}
예제 #8
0
def test_multiple_words_mismatch_length():
    matches = Pattern('take apple').match(['take', 'golden', 'apple'])
    assert matches is None
예제 #9
0
def test_multiple_words_mismatch():
    matches = Pattern('take apple').match(['take', 'tortoise'])
    assert matches is None
예제 #10
0
def test_multiple_words():
    pat = Pattern('take apple')
    matches = pat.match(['take', 'apple'])
    assert matches == {}
예제 #11
0
def test_match():
    matches = Pattern('apple').match(['apple'])
    assert matches == {}
예제 #12
0
def test_no_match_extra_words():
    matches = Pattern('look').match(['look', 'at', 'butler'])
    assert matches is None
예제 #13
0
def test_no_match_different_words():
    matches = Pattern('look').match(['apple'])
    assert matches is None