Skip to content

Commit

Permalink
fix parsing of numbers in tinyyaml.lua (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshya8066 authored Jan 9, 2024
1 parent 31b9a5c commit 197632c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/example_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ busted.describe("example", function()
end

assert.same(
'6.8523015e+5', -- not supported
6.8523015e+5,
t.float.canonical
)
assert.same(
Expand Down
54 changes: 54 additions & 0 deletions spec/number_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local busted = require('busted')
local assert = require('luassert')
local yaml = require('tinyyaml')

busted.describe("numbers in nested seq:", function ()
local parsed_yaml = yaml.parse('case: [["status", "==", 302]]')
local parsed_yaml2 = yaml.parse('case: [["status", "==", "302"]]')
busted.it("numbers", function ()
assert.same(
{
case = {{"status", "==", 302}}
},
yaml.parse([[
case:
- - "status"
- "=="
- 302
]]
)
)
end)

busted.it("numbers in inline nested seq:", function ()
assert.same(
{
case = {{"status", "==", 302}}
},
yaml.parse([[
case:
-
- "status"
- "=="
- 302
]]
)
)
end)

busted.it("number inside [] brackets", function ()
assert.same(
{
case = {{"status", "==", 302}}
}, parsed_yaml
)
end)

busted.it("number inside [] brackets in double quotes", function ()
assert.same(
{
case = {{"status", "==", "302"}}
}, parsed_yaml2
)
end)
end)
4 changes: 3 additions & 1 deletion tinyyaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ function Parser:parsestring(line, stopper)
end
line = ssub(line, 2)
end
return rtrim(buf), line
buf = rtrim(buf)
local val = tonumber(buf) or buf
return val, line
end

local function isemptyline(line)
Expand Down

0 comments on commit 197632c

Please sign in to comment.