Skip to content

Commit

Permalink
Fix keyword argument handling (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Jan 15, 2021
1 parent 5eb40d5 commit 7a13ac2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/FGenerators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ macro fgenerator(ex)
end

allargs = map([def[:args]; def[:kwargs]]) do x
if isexpr(x, :kw)
x = x.args[1]
end
if @capture(x, args_...)
args
elseif @capture(x, a_::T_)
Expand Down
28 changes: 27 additions & 1 deletion test/test_samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,29 @@ end
end
end

raw_testdata = """
asval(x::Val) = x
asval(x) = Val(x)
const FlagType = Union{Val{true},Val{false},Bool}

@fgenerator function linesin(str::AbstractString; keep::FlagType = Val(false))
keep = asval(keep)
start = firstindex(str)
for (i, c) in pairs(str)
if c == '\n'
if keep === Val(true)
@yield SubString(str, start, i)
else
@yield SubString(str, start, prevind(str, i))
end
start = nextind(str, i)
end
end
if start <= ncodeunits(str)
@yield SubString(str, start)
end
end

raw_testdata = raw"""
noone() == []
oneone() == [1]
onetwothree() == [1, 2, 3]
Expand All @@ -113,6 +135,10 @@ ffilter(isodd, oneone()) == [1]
ffilter(isodd, onetwothree()) == [1, 3]
ffilter(isodd, 1:5) == [1, 3, 5]
ffilter(isodd, organpipe(3)) == [1, 3, 1]
linesin("a\nbb\nccc") == ["a", "bb", "ccc"]
linesin("a\nbb\nccc"; keep=true) == ["a\n", "bb\n", "ccc"]
linesin("a\nbb\nccc\n") == ["a", "bb", "ccc"]
linesin("a\nbb\nccc\n"; keep=true) == ["a\n", "bb\n", "ccc\n"]
"""

args_and_kwargs(args...; kwargs...) = args, (; kwargs...)
Expand Down

0 comments on commit 7a13ac2

Please sign in to comment.