add parser tests to check if keywords are handled correctly
This commit is contained in:
@@ -366,5 +366,241 @@ class QueryParserTester
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_final_array_result
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside without quotes' do
|
||||
@result = @evaluator.parse('land')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside with quotes' do
|
||||
@result = @evaluator.parse('"land"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND without quotes' do
|
||||
@result = @evaluator.parse('andromeda')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND with quotes' do
|
||||
@result = @evaluator.parse('"andromeda"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"andromeda"'
|
||||
end
|
||||
|
||||
it 'tests query with column name containing AND word inside' do
|
||||
@result = @evaluator.parse('land:some-search-term')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['land']).to eq 'some-search-term'
|
||||
end
|
||||
|
||||
it 'tests query with column name starting with AND' do
|
||||
@result = @evaluator.parse('andromeda:some-search-term')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['andromeda']).to eq 'some-search-term'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes containing AND word inside' do
|
||||
@result = @evaluator.parse('name:land')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query with search term with quotes containing AND word inside' do
|
||||
@result = @evaluator.parse('name:"land"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND without quotes' do
|
||||
@result = @evaluator.parse('name:andromeda')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND with quotes' do
|
||||
@result = @evaluator.parse('name:"andrew"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq '"andrew"'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word' do
|
||||
@result = @evaluator.parse('(land)')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND' do
|
||||
@result = @evaluator.parse('(andromeda)')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word with quotes' do
|
||||
@result = @evaluator.parse('("land")')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND with quotes' do
|
||||
@result = @evaluator.parse('("andromeda")')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"andromeda"'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms starting with AND' do
|
||||
@result = @evaluator.parse('land andrew and andromeda or orlando')
|
||||
|
||||
@and_array = [
|
||||
{:DEFAULT_COLUMN=>'andrew'},
|
||||
{:DEFAULT_COLUMN=>'andromeda'}
|
||||
]
|
||||
|
||||
@last_or_array = [
|
||||
{:OPERATOR_AND => @and_array},
|
||||
{:DEFAULT_COLUMN => 'orlando'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => 'land'},
|
||||
{:OPERATOR_OR => @last_or_array}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars' do
|
||||
@result = @evaluator.parse('land 123-andrew or -andrew- and not _ornela_ or ornela')
|
||||
|
||||
@and_array = [
|
||||
{:DEFAULT_COLUMN=>'-andrew-'},
|
||||
{:OPERATOR_NOT=>{:DEFAULT_COLUMN => '_ornela_'}}
|
||||
]
|
||||
|
||||
@intra_or_array = [
|
||||
{:DEFAULT_COLUMN => '123-andrew'},
|
||||
{:OPERATOR_AND => @and_array}
|
||||
]
|
||||
|
||||
@last_or_array = [
|
||||
{:OPERATOR_OR => @intra_or_array},
|
||||
{:DEFAULT_COLUMN => 'ornela'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => 'land'},
|
||||
{:OPERATOR_OR => @last_or_array}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars under quotes' do
|
||||
@result = @evaluator.parse('"land" "123-andrew" or "-andrew-"')
|
||||
|
||||
|
||||
@last_or_array = [
|
||||
{:DEFAULT_COLUMN => '"123-andrew"'},
|
||||
{:DEFAULT_COLUMN => '"-andrew-"'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => '"land"'},
|
||||
{:OPERATOR_OR => @last_or_array}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start' do
|
||||
@result = @evaluator.parse('sindy andora ornoty notary')
|
||||
|
||||
@or_array_1 = [
|
||||
{:DEFAULT_COLUMN=>'ornoty'},
|
||||
{:DEFAULT_COLUMN=>'notary'}
|
||||
]
|
||||
|
||||
@or_array_2 = [
|
||||
{:DEFAULT_COLUMN => 'andora'},
|
||||
{:OPERATOR_OR => @or_array_1}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => 'sindy'},
|
||||
{:OPERATOR_OR => @or_array_2}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@result = @evaluator.parse('sindy and andora-notary or not ornoty notary')
|
||||
|
||||
@and_array = [
|
||||
{:DEFAULT_COLUMN=>'sindy'},
|
||||
{:DEFAULT_COLUMN=>'andora-notary'}
|
||||
]
|
||||
|
||||
@not_or_array = [
|
||||
{:DEFAULT_COLUMN => 'ornoty'},
|
||||
{:DEFAULT_COLUMN => 'notary'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:OPERATOR_AND => @and_array},
|
||||
{:OPERATOR_NOT => {
|
||||
:OPERATOR_OR => @not_or_array
|
||||
}}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@result = @evaluator.parse('(sindy or andora-notary)and not(ornoty notary)')
|
||||
|
||||
@or_array_1 = [
|
||||
{:DEFAULT_COLUMN=>'sindy'},
|
||||
{:DEFAULT_COLUMN=>'andora-notary'}
|
||||
]
|
||||
|
||||
@not_or_array = [
|
||||
{:DEFAULT_COLUMN => 'ornoty'},
|
||||
{:DEFAULT_COLUMN => 'notary'}
|
||||
]
|
||||
|
||||
@main_and_array = [
|
||||
{:OPERATOR_OR => @or_array_1},
|
||||
{:OPERATOR_NOT => {
|
||||
:OPERATOR_OR => @not_or_array
|
||||
}}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_AND]).to eq @main_and_array
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user