add tests for mixed operators expression; test precedence

This commit is contained in:
Bilal Catic
2020-01-31 13:27:31 +01:00
parent 0286f3ed81
commit 9c2aff53d7

View File

@@ -35,19 +35,19 @@ class SqlGeneratorTester
it 'tests search without operators' do
@query = TextToSqlQuery.new('123 456', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.device_id LIKE ? OR players.device_id LIKE ?', '%123%', '%456%']
expect(@query.where_clause).to eq ['(players.device_id LIKE ? OR players.device_id LIKE ?)', '%123%', '%456%']
end
it 'tests search with OR operator' do
@query = TextToSqlQuery.new('123 or 456', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.device_id LIKE ? OR players.device_id LIKE ?', '%123%', '%456%']
expect(@query.where_clause).to eq ['(players.device_id LIKE ? OR players.device_id LIKE ?)', '%123%', '%456%']
end
it 'tests search with AND operator' do
@query = TextToSqlQuery.new('123 and 456', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.device_id LIKE ? AND players.device_id LIKE ?', '%123%', '%456%']
expect(@query.where_clause).to eq ['(players.device_id LIKE ? AND players.device_id LIKE ?)', '%123%', '%456%']
end
it 'tests search with NOT operator on default column' do
@@ -65,13 +65,25 @@ class SqlGeneratorTester
it 'tests search with mixed logical operators' do
@query = TextToSqlQuery.new('title:ab and not tag:hf-1', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.title LIKE ? AND NOT players.tag LIKE ?', '%ab%', '%hf-1%']
expect(@query.where_clause).to eq ['(players.title LIKE ? AND NOT players.tag LIKE ?)', '%ab%', '%hf-1%']
end
it 'tests search with mixed logical operators without NOT' do
@query = TextToSqlQuery.new('title:a and title:b or title:c', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.title LIKE ? AND players.title LIKE ? OR players.title LIKE ?', '%a%', '%b%', '%c%']
expect(@query.where_clause).to eq ['((players.title LIKE ? AND players.title LIKE ?) OR players.title LIKE ?)', '%a%', '%b%', '%c%']
end
it 'tests search with brackets in expression' do
@query = TextToSqlQuery.new('title:a and (title:b or title:c)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['(players.title LIKE ? AND (players.title LIKE ? OR players.title LIKE ?))', '%a%', '%b%', '%c%']
end
it 'tests search with brackets in expression and with NOT operator' do
@query = TextToSqlQuery.new('title:a and not (title:b or title:c)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['(players.title LIKE ? AND NOT (players.title LIKE ? OR players.title LIKE ?))', '%a%', '%b%', '%c%']
end
end
end