add lexer tests to check for correct keyword extraction

This commit is contained in:
Bilal Catic
2020-02-09 22:30:17 +01:00
parent a783d85f0a
commit b532b830ca

View File

@@ -255,5 +255,265 @@ class QueryLexerTester
expect(@result[2][0]).to eq :TERM_WITH_QUOTES
expect(@result[2][1]).to eq '"tag with or and not inside"'
end
it 'tests query without column name containing AND word inside without quotes' do
@result = @evaluator.tokenize('land')
expect(@result.length).to eq 1
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'land'
end
it 'tests query without column name containing AND word inside with quotes' do
@result = @evaluator.tokenize('"land"')
expect(@result.length).to eq 1
expect(@result[0][0]).to eq :TERM_WITH_QUOTES
expect(@result[0][1]).to eq '"land"'
end
it 'tests query without column name and with word starting with AND without quotes' do
@result = @evaluator.tokenize('andromeda')
expect(@result.length).to eq 1
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'andromeda'
end
it 'tests query without column name and with word starting with AND with quotes' do
@result = @evaluator.tokenize('"andromeda"')
expect(@result.length).to eq 1
expect(@result[0][0]).to eq :TERM_WITH_QUOTES
expect(@result[0][1]).to eq '"andromeda"'
end
it 'tests query with column name containing AND word inside' do
@result = @evaluator.tokenize('land:some-search-term')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'land'
expect(@result[1][0]).to eq :COLON
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[2][1]).to eq 'some-search-term'
end
it 'tests query with column name starting with AND' do
@result = @evaluator.tokenize('andromeda:some-search-term')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'andromeda'
expect(@result[1][0]).to eq :COLON
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[2][1]).to eq 'some-search-term'
end
it 'tests query with search term without quotes containing AND word inside' do
@result = @evaluator.tokenize('name:land')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'name'
expect(@result[1][0]).to eq :COLON
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[2][1]).to eq 'land'
end
it 'tests query with search term with quotes containing AND word inside' do
@result = @evaluator.tokenize('name:"land"')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'name'
expect(@result[1][0]).to eq :COLON
expect(@result[2][0]).to eq :TERM_WITH_QUOTES
expect(@result[2][1]).to eq '"land"'
end
it 'tests query with search term without quotes and search term starting with AND without quotes' do
@result = @evaluator.tokenize('name:andromeda')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'name'
expect(@result[1][0]).to eq :COLON
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[2][1]).to eq 'andromeda'
end
it 'tests query with search term without quotes and search term starting with AND with quotes' do
@result = @evaluator.tokenize('name:"andrew"')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'name'
expect(@result[1][0]).to eq :COLON
expect(@result[2][0]).to eq :TERM_WITH_QUOTES
expect(@result[2][1]).to eq '"andrew"'
end
it 'tests query with search term in brackets with AND inside word' do
@result = @evaluator.tokenize('(land)')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :L_BRACKET
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[1][1]).to eq 'land'
expect(@result[2][0]).to eq :R_BRACKET
end
it 'tests query with search term in brackets starting with AND' do
@result = @evaluator.tokenize('(andromeda)')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :L_BRACKET
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[1][1]).to eq 'andromeda'
expect(@result[2][0]).to eq :R_BRACKET
end
it 'tests query with search term in brackets with AND inside word with quotes' do
@result = @evaluator.tokenize('("land")')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :L_BRACKET
expect(@result[1][0]).to eq :TERM_WITH_QUOTES
expect(@result[1][1]).to eq '"land"'
expect(@result[2][0]).to eq :R_BRACKET
end
it 'tests query with search term in brackets starting with AND with quotes' do
@result = @evaluator.tokenize('("andromeda")')
expect(@result.length).to eq 3
expect(@result[0][0]).to eq :L_BRACKET
expect(@result[1][0]).to eq :TERM_WITH_QUOTES
expect(@result[1][1]).to eq '"andromeda"'
expect(@result[2][0]).to eq :R_BRACKET
end
it 'tests query with multiple search terms starting with AND' do
@result = @evaluator.tokenize('land andrew and andromeda or orlando')
expect(@result.length).to eq 6
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'land'
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[1][1]).to eq 'andrew'
expect(@result[2][0]).to eq :OPERATOR_AND
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[3][1]).to eq 'andromeda'
expect(@result[4][0]).to eq :OPERATOR_OR
expect(@result[5][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[5][1]).to eq 'orlando'
end
it 'tests query with multiple search terms with dash and underscore chars' do
@result = @evaluator.tokenize('land 123-andrew or -andrew- and not _ornela_ or ornela')
expect(@result.length).to eq 9
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'land'
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[1][1]).to eq '123-andrew'
expect(@result[2][0]).to eq :OPERATOR_OR
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[3][1]).to eq '-andrew-'
expect(@result[4][0]).to eq :OPERATOR_AND
expect(@result[5][0]).to eq :OPERATOR_NOT
expect(@result[6][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[6][1]).to eq '_ornela_'
expect(@result[7][0]).to eq :OPERATOR_OR
expect(@result[8][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[8][1]).to eq 'ornela'
end
it 'tests query with multiple search terms with dash and underscore chars under quotes' do
@result = @evaluator.tokenize('"land" "123-andrew" or "-andrew-"')
expect(@result.length).to eq 4
expect(@result[0][0]).to eq :TERM_WITH_QUOTES
expect(@result[0][1]).to eq '"land"'
expect(@result[1][0]).to eq :TERM_WITH_QUOTES
expect(@result[1][1]).to eq '"123-andrew"'
expect(@result[2][0]).to eq :OPERATOR_OR
expect(@result[3][0]).to eq :TERM_WITH_QUOTES
expect(@result[3][1]).to eq '"-andrew-"'
end
it 'tests query with multiple search terms with mixed and-or-not on start' do
@result = @evaluator.tokenize('sindy andora ornoty notary')
expect(@result.length).to eq 4
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'sindy'
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[1][1]).to eq 'andora'
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[2][1]).to eq 'ornoty'
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[3][1]).to eq 'notary'
end
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
@result = @evaluator.tokenize('sindy and andora-notary or not ornoty notary')
expect(@result.length).to eq 7
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[0][1]).to eq 'sindy'
expect(@result[1][0]).to eq :OPERATOR_AND
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[2][1]).to eq 'andora-notary'
expect(@result[3][0]).to eq :OPERATOR_OR
expect(@result[4][0]).to eq :OPERATOR_NOT
expect(@result[5][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[5][1]).to eq 'ornoty'
expect(@result[6][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[6][1]).to eq 'notary'
end
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
@result = @evaluator.tokenize('(sindy and andora-notary)or not(ornoty notary)')
expect(@result.length).to eq 11
expect(@result[0][0]).to eq :L_BRACKET
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[1][1]).to eq 'sindy'
expect(@result[2][0]).to eq :OPERATOR_AND
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[3][1]).to eq 'andora-notary'
expect(@result[4][0]).to eq :R_BRACKET
expect(@result[5][0]).to eq :OPERATOR_OR
expect(@result[6][0]).to eq :OPERATOR_NOT
expect(@result[7][0]).to eq :L_BRACKET
expect(@result[8][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[8][1]).to eq 'ornoty'
expect(@result[9][0]).to eq :TERM_WITHOUT_QUOTES
expect(@result[9][1]).to eq 'notary'
expect(@result[10][0]).to eq :R_BRACKET
end
end
end