def test_parse_object():
    word_list = lexicon.scan('the door')
    assert_equal(parser.parse_object(word_list), ('noun', 'door'))
    word_list = lexicon.scan('the east')
    assert_equal(parser.parse_object(word_list), ('direction', 'east'))
    word_list = lexicon.scan('the it')
    assert_raises(parser.ParserError, parser.parse_object, word_list)
def test_parse_sentence():
    word_list = lexicon.scan('the bear eat door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
    word_list = lexicon.scan('in eat door')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('player', 'eat', 1, 'door'))
    word_list = lexicon.scan('north eat door')
    assert_raises(parser.ParserError, parser.parse_sentence, word_list)
def test_match():
    word_list = lexicon.scan('princess')
    assert_equal(parser.match(word_list, 'noun'), ('noun', 'princess'))
    assert_equal(parser.match(word_list, 'stop'), None)
    assert_equal(parser.match(None, 'noun'), None)
def test_peek():
    word_list = lexicon.scan('princess')
    assert_equal(parser.peek(word_list), 'noun')
    assert_equal(parser.peek(None), None)
示例#5
0
def test_sentence():
    assert_raises(sentence.ParserError, sentence.parse_sentence,
                  lexicon.scan("go north south east on the bear"))
示例#6
0
def test_sentence_parsesubject():
    assert_raises(sentence.ParserError, sentence.parse_subject,
                  lexicon.scan("north south east on the bear"), 'honglong')
示例#7
0
def test_verbs():
	assert_equal(lexicon.scan("go"), [('verbs', 'go')])
	results = lexicon.scan("go kill eat")
	assert_equal(results, [('verbs', 'go'), ('verbs', 'kill'), ('verbs', 'eat')])
示例#8
0
def test_sentence_match():
    assert_raises(sentence.ParserError, sentence.match,
                  lexicon.scan("go north south east"), 'verbs')
示例#9
0
def test_errors():
	assert_equal(lexicon.scan("ADEG"), [('error', 'ADEG')])
	results = lexicon.scan("bear IAS princess")
	assert_equal(results, [('nouns', 'bear'), ('error', 'IAS'), ('nouns', 'princess')])
示例#10
0
def test_sentence_peek():
    assert_raises(sentence.ParserError, sentence.peek,
                  lexicon.scan("north south east"))
示例#11
0
def test_numbers():
	assert_equal(lexicon.scan('1234'), [('numbers', 1234)])
	results = lexicon.scan("3 91234")
	assert_equal(results, [('numbers', 3), ('numbers', 91234)])
示例#12
0
def test_nouns():
	assert_equal(lexicon.scan("bear"), [('nouns', 'bear')])
	results = lexicon.scan("bear princess")
	assert_equal(results, [('nouns', 'bear'), ('nouns', 'princess')])
示例#13
0
def test_stops():
	assert_equal(lexicon.scan("the"), [('stops', 'the')])
	results = lexicon.scan("the in of")
	assert_equal(results, [('stops', 'the'),('stops', 'in'), ('stops', 'of')])
def test_skip():
    word_list = lexicon.scan('bear eat door')
    assert_equal(word_list, [('noun', 'bear'), ('verb', 'eat'),
                             ('noun', 'door')])
    parser.skip(word_list, 'noun')
    assert_equal(word_list, [('verb', 'eat'), ('noun', 'door')])
示例#15
0
def test_sentence_skip():
    assert_raises(sentence.ParserError, sentence.skip, lexicon.scan("on bear"),
                  'stops')
def test_parse_verb():
    word_list = lexicon.scan('it eat door')
    assert_equal(parser.parse_verb(word_list), ('verb', 'eat'))
    word_list = lexicon.scan('bear eat door')
    assert_raises(parser.ParserError, parser.parse_verb, word_list)
示例#17
0
def test_sentence_parseverb():
    assert_raises(sentence.ParserError, sentence.parse_verb,
                  lexicon.scan("go north south east"))
def test_parse_subject():
    word_list = lexicon.scan('eat door')
    subj = ('noun', 'bear')
    s = parser.parse_subject(word_list, subj)
    assert_equal(s.to_tuple(), ('bear', 'eat', 1, 'door'))
示例#19
0
def test_sentence_parseobject():
    assert_raises(sentence.ParserError, sentence.parse_object,
                  lexicon.scan("go north south east"))
def test_numbers():
    word_list = lexicon.scan('xxx the xxx bear xxx eat xxx 5 xxx door xxx')
    s = parser.parse_sentence(word_list)
    assert_equal(s.to_tuple(), ('bear', 'eat', 5, 'door'))
示例#21
0
def test_directions():
	assert_equal(lexicon.scan("north"), [('directions', 'north')])
	results = lexicon.scan("north south east")
	assert_equal(results, [('directions', 'north'), ('directions', 'south'), ('directions', 'east')])