Skip to content
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

fix(argcount) fix n if too low #17

Merged
merged 1 commit into from
Aug 27, 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
7 changes: 7 additions & 0 deletions spec/say_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ describe("Tests to make sure the say library is functional", function()
assert(s('this does not exist') == nil)
end)

it("tests the wrong arg count", function()
-- backward compatibility after the nil-safe fix, in which the 'n' field got precendence over #
s:set('substitute_test', '1 = %s, 2 = %s')
-- two arguments, but "n = 1"
assert(s('substitute_test', {"one", "two", n = 1}) == '1 = one, 2 = two')
end)

end)
1 change: 1 addition & 0 deletions src/say/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local __meta = {
error(("expected parameter table to be a table, got '%s'"):format(type(vars)), 2)
end
vars = vars or {}
vars.n = math.max((vars.n or 0), #vars)

local str = registry[current_namespace][key] or registry[fallback_namespace][key]

Expand Down