Skip to content

Commit

Permalink
Fix handling of ! internally and patch bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokazama committed Jan 17, 2021
1 parent ebe4fbb commit ab4c4ea
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ChainedFixes"
uuid = "9706b775-b1f4-4c74-b677-0491368ea71c"
authors = ["Zachary P. Christensen <[email protected]>"]
version = "0.2.1"
version = "0.2.2"

[compat]
julia = "1"
Expand Down
80 changes: 55 additions & 25 deletions src/ChainedFixes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ getargs(x::Fix2) = (getfield(x, :x),)
getargs(x::Fix1) = (getfield(x, :x),)
getargs(x::Approx) = (getfield(x, :y),)
getargs(x::NFix) = getfield(x, :args)
getargs(x::Not) = getargs(getfield(x, :f))
getargs(x::Not) = (getfield(x, :f),)
getargs(x::ChainedFix) = (getfield(x, :f1), getfield(x, :f2))

"""
Expand Down Expand Up @@ -405,8 +405,6 @@ getfxn(x::Fix1) = getfield(x, :f)
getfxn(x::Fix2) = getfield(x, :f)
getfxn(x::Approx) = isapprox
getfxn(x::Not) = !
getfxn(x::NotIn) = !in
getfxn(x::NotApprox) = !isapprox

"""
positions(f) -> Tuple{Vararg{Int}}
Expand Down Expand Up @@ -501,16 +499,8 @@ function Base.show(io::IO, f::PipeChain)
print_fixed(io, f)
end


print_fixed(io::IO, f::Function) = print(io, "$(nameof(f))")
print_fixed(io::IO, x) = print(io, repr(x))
function print_fixed(io::IO, f::Fix2)
print(io, "Fix2(")
print_fixed(io, f.f)
print(io, ", ")
print_fixed(io, f.x)
print(io, ")")
end

function print_fixed(io::IO, f::PipeChain)
print_fixed(io, f.f1)
Expand All @@ -529,7 +519,6 @@ end

function print_fixed(io::IO, f::NFix{P}) where {P}
print_fixed(io, getfxn(f))

print(io, "(")
if length(P) !== 0
args = getargs(f)
Expand Down Expand Up @@ -569,19 +558,60 @@ end
Base.show(io::IO, ::MIME"text/plain", f::NFix) = print_fixed(io, f)
Base.show(io::IO, f::NFix) = print_fixed(io, f)

print_fixed(io::IO, x::Less) = print(io, "<($(x.x))")
print_fixed(io::IO, x::Greater) = print(io, ">($(x.x))")
print_fixed(io::IO, x::Equal) = print(io, "==($(x.x))")
print_fixed(io::IO, x::NotEqual) = print(io, "!=($(x.x))")
print_fixed(io::IO, x::LessThanOrEqual) = print(io, "<=($(x.x))")
print_fixed(io::IO, x::GreaterThanOrEqual) = print(io, ">=($(x.x))")
print_fixed(io::IO, x::Not) = print(io, "!($(x.x))")
print_fixed(io::IO, x::In) = print(io, "in($(x.x))")
print_fixed(io::IO, x::NotIn) = print(io, "!in($(getargs(x)[1]))")
print_fixed(io::IO, x::EndsWith) = print(io, "endswith($(repr(x.x)))")
print_fixed(io::IO, x::StartsWith) = print(io, "startswith($(repr(x.x)))")
print_fixed(io::IO, x::Approx) = print(io, "≈($(getargs(x)[1]))")
print_fixed(io::IO, x::NotApprox) = print(io, "!≈($(getargs(x)[1]))")
function print_fixed(io::IO, x::Not)
print(io, "!")
print_fixed(io, getargs(x)[1])
end
function print_fixed(io::IO, x::Greater)
print(io, ">(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::Less)
print(io, "<(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::Equal)
print(io, "==(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::NotEqual)
print(io, "!=(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::LessThanOrEqual)
print(io, "<=(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::GreaterThanOrEqual)
print(io, ">=(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::In)
print(io, "in(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::EndsWith)
print(io, "endswith(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::StartsWith)
print(io, "startswith(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end
function print_fixed(io::IO, x::Approx)
print(io, "≈(")
print_fixed(io, first(getargs(x)))
print(io, ")")
end

end # module

9 changes: 4 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ end
@test !isa(!(==(1)), In)

@test @inferred(is_fixed_function(typeof(notinfxn)))
@test @inferred(getfxn(notinfxn)) == !in
@test @inferred(getargs(notinfxn)) == (1,)
@test @inferred(getfxn(notinfxn)) == !
@test @inferred(getargs(notinfxn)) == (in(1),)
@test @inferred(getkwargs(notinfxn)) == empty_pairs
end

Expand All @@ -73,9 +73,8 @@ end
@test !isa(!(==(1)), NotApprox)

@test @inferred(is_fixed_function(typeof(notisapprox_fxn)))
@test @inferred(getfxn(notisapprox_fxn)) == !isapprox
@test @inferred(getargs(notisapprox_fxn)) == (1,)
@test @inferred(getkwargs(notisapprox_fxn)) == Pairs((atol=2,),(:atol,))
@test @inferred(getfxn(notisapprox_fxn)) == !
@test @inferred(getargs(notisapprox_fxn)) == (isapprox(1; atol=2),)
end

@testset "Less" begin
Expand Down

2 comments on commit ab4c4ea

@Tokazama
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/28157

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.2 -m "<description of version>" ab4c4ea46d518fdf0bcc92f965563518f221c2fd
git push origin v0.2.2

Please sign in to comment.