Skip to content
Open
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 jsonpath.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ local jsonpath_grammer = (function()
local digit = R('09')
local letter = R('AZ','az')
local alpha0 = R('AZ','az') + '_'
local alphaN = R('AZ','az','09') + '_'
local alphaN = R('AZ','az','09') + '_' + '-'
local hexdigit = R('09', 'AF', 'af')

local number_hex = P'0' * S'xX' * hexdigit^1
Expand Down
4 changes: 4 additions & 0 deletions test/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ return {
isbn = '0-395-19395-8',
price = 22.99
}
},
['soccer-shoes'] = {
color = 'blue',
price = 200.00
}
}
}
20 changes: 16 additions & 4 deletions test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ testParse = {
lu.assertNil(err)
lu.assertEquals(path, {'$', '..', 'price'})
end,

testParserPathForSoccerShoes = function()
local path, err = jp.parse('$.store.soccer-shoes')
lu.assertNil(err)
lu.assertEquals(path, { '$', 'store', 'soccer-shoes' })
end,
}


Expand Down Expand Up @@ -373,7 +379,8 @@ testQuery = {
lu.assertNil(err)
lu.assertItemsEquals(results, sortByPath({
{ path = {'$', 'store', 'book'}, value = data.store.book },
{ path = {'$', 'store', 'bicycle'}, value = data.store.bicycle }
{ path = {'$', 'store', 'bicycle'}, value = data.store.bicycle },
{ path = {'$', 'store', 'soccer-shoes'}, value = data.store['soccer-shoes'] }
}))
end,

Expand All @@ -385,7 +392,9 @@ testQuery = {
{ path = {'$', 'store', 'book', 1, 'price'}, value = 12.99 },
{ path = {'$', 'store', 'book', 2, 'price'}, value = 8.99 },
{ path = {'$', 'store', 'book', 3, 'price'}, value = 22.99 },
{ path = {'$', 'store', 'bicycle', 'price'}, value = 19.95 }
{ path = {'$', 'store', 'bicycle', 'price'}, value = 19.95 },
{ path = {'$', 'store', 'soccer-shoes', 'price'}, value = 200.00 }

}))
end,

Expand Down Expand Up @@ -447,6 +456,7 @@ testQuery = {
{ path = { '$', 'store' }, value = data.store },
{ path = { '$', 'store', 'book' }, value = data.store.book },
{ path = { '$', 'store', 'bicycle' }, value = data.store.bicycle },
{ path = { '$', 'store', 'soccer-shoes' }, value = data.store['soccer-shoes'] },
{ path = { '$', 'store', 'book', 0 }, value = data.store.book[1] },
{ path = { '$', 'store', 'book', 1 }, value = data.store.book[2] },
{ path = { '$', 'store', 'book', 2 }, value = data.store.book[3] },
Expand All @@ -470,7 +480,9 @@ testQuery = {
{ path = { '$', 'store', 'book', 3, 'isbn' }, value = '0-395-19395-8' },
{ path = { '$', 'store', 'book', 3, 'price' }, value = 22.99 },
{ path = { '$', 'store', 'bicycle', 'color' }, value = 'red' },
{ path = { '$', 'store', 'bicycle', 'price' }, value = 19.95 }
{ path = { '$', 'store', 'bicycle', 'price' }, value = 19.95 },
{ path = { '$', 'store', 'soccer-shoes', 'price' }, value = 200.00 },
{ path = { '$', 'store', 'soccer-shoes', 'color' }, value = 'blue' }
}))
end,

Expand All @@ -483,7 +495,7 @@ testQuery = {
testObjectSubscriptWildcard = function()
local results, err = jp.query(data, '$.store[*]')
lu.assertNil(err)
lu.assertItemsEquals(results, { data.store.book, data.store.bicycle })
lu.assertItemsEquals(results, { data.store.book, data.store.bicycle, data.store['soccer-shoes']})
end,

testNoMatchReturnsEmptyArray = function()
Expand Down