Skip to content

Makes the property searching case insensitive #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/orgmode/parser/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Search:_matches(val, item)
end
return val == item.tags
end
prop_name = vim.trim(prop_name)
prop_name = string.lower(vim.trim(prop_name))
prop_val = vim.trim(prop_val)
if not item.props or not item.props[prop_name] then
return false
Expand Down
38 changes: 19 additions & 19 deletions tests/plenary/parser/search_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,109 +68,109 @@ describe('Search parser', function()
it('should parse search term and match string properties and value', function()
local result = Search:new('CATEGORY="test"&MYPROP=myval+WORK')
assert.Is.True(result:check({
props = { CATEGORY = 'test', MYPROP = 'myval', AGE = 10 },
props = { category = 'test', myprop = 'myval', age = 10 },
tags = { 'WORK', 'OFFICE' },
}))

assert.Is.False(result:check({
props = { CATEGORY = 'invalid', MYPROP = 'myval', AGE = 10 },
props = { category = 'invalid', myprop = 'myval', age = 10 },
tags = { 'WORK', 'OFFICE' },
}))

assert.Is.False(result:check({
props = { CATEGORY = 'test', MYPROP = 'myval', AGE = 10 },
props = { category = 'test', myprop = 'myval', age = 10 },
tags = { 'OFFICE' },
}))
end)

it('should parse search term and match number properties and value', function()
local result = Search:new('PAGES>=1000&ITEMS<500&COUNT=10&CALCULATION<>5&BOOKS>3+WORK')
assert.Is.True(result:check({
props = { PAGES = 1010, ITEMS = 100, COUNT = 10, CALCULATION = 8, BOOKS = 5 },
props = { pages = 1010, items = 100, count = 10, calculation = 8, books = 5 },
tags = { 'WORK', 'OFFICE' },
}))

assert.Is.True(result:check({
props = { PAGES = 1000, ITEMS = 499, COUNT = 10, CALCULATION = 10, BOOKS = 4 },
props = { pages = 1000, items = 499, count = 10, calculation = 10, books = 4 },
tags = { 'WORK' },
}))

assert.Is.False(result:check({
props = { PAGES = 999, ITEMS = 499, COUNT = 10, CALCULATION = 10, BOOKS = 4 },
props = { pages = 999, items = 499, count = 10, calculation = 10, books = 4 },
tags = { 'WORK' },
}))

assert.Is.False(result:check({
props = { PAGES = 1001, ITEMS = 500, COUNT = 10, CALCULATION = 10, BOOKS = 4 },
props = { pages = 1001, items = 500, count = 10, calculation = 10, books = 4 },
tags = { 'WORK' },
}))

assert.Is.False(result:check({
props = { PAGES = 1001, ITEMS = 500, COUNT = 11, CALCULATION = 10, BOOKS = 4 },
props = { pages = 1001, items = 500, count = 11, calculation = 10, books = 4 },
tags = { 'WORK' },
}))

assert.Is.False(result:check({
props = { PAGES = 1001, ITEMS = 500, COUNT = 11, CALCULATION = 5, BOOKS = 4 },
props = { pages = 1001, items = 500, count = 11, calculation = 5, books = 4 },
tags = { 'WORK' },
}))

assert.Is.False(result:check({
props = { PAGES = 1001, ITEMS = 500, COUNT = 11, CALCULATION = 5, BOOKS = 3 },
props = { pages = 1001, items = 500, count = 11, calculation = 5, books = 3 },
tags = { 'WORK' },
}))

assert.Is.False(result:check({
props = { PAGES = 1010, ITEMS = 100, COUNT = 10, CALCULATION = 8, BOOKS = 5 },
props = { pages = 1010, items = 100, count = 10, calculation = 8, books = 5 },
tags = { 'OFFICE' },
}))
end)

it('should search props, tags and todo keywords', function()
local result = Search:new('CATEGORY="test"&MYPROP=myval+WORK/TODO|NEXT')
assert.Is.True(result:check({
props = { CATEGORY = 'test', MYPROP = 'myval', AGE = 10 },
props = { category = 'test', myprop = 'myval', age = 10 },
tags = { 'WORK', 'OFFICE' },
todo = { 'TODO' },
}))
assert.Is.True(result:check({
props = { CATEGORY = 'test', MYPROP = 'myval', AGE = 10 },
props = { category = 'test', myprop = 'myval', age = 10 },
tags = { 'WORK', 'OFFICE' },
todo = 'NEXT',
}))
assert.Is.False(result:check({
props = { CATEGORY = 'test', MYPROP = 'myval', AGE = 10 },
props = { category = 'test', myprop = 'myval', age = 10 },
tags = { 'WORK', 'OFFICE' },
todo = { 'DONE' },
}))

result = Search:new('CATEGORY="test"+WORK/-WAITING')
assert.Is.True(result:check({
props = { CATEGORY = 'test' },
props = { category = 'test' },
tags = { 'WORK' },
todo = { 'TODO' },
}))

assert.Is.True(result:check({
props = { CATEGORY = 'test' },
props = { category = 'test' },
tags = { 'WORK' },
todo = { 'DONE' },
}))

assert.Is.False(result:check({
props = { CATEGORY = 'test' },
props = { category = 'test' },
tags = { 'WORK' },
todo = { 'WAITING' },
}))

assert.Is.False(result:check({
props = { CATEGORY = 'test_bad' },
props = { category = 'test_bad' },
tags = { 'WORK' },
todo = { 'DONE' },
}))

assert.Is.False(result:check({
props = { CATEGORY = 'test' },
props = { category = 'test' },
tags = { 'OFFICE' },
todo = { 'DONE' },
}))
Expand Down