Skip to content

Commit

Permalink
Add nameof (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored and fredrikekre committed Jan 30, 2018
1 parent 791ea60 commit 5d14f28
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ Currently, the `@compat` macro supports the following syntaxes:
* `module_parent`, `Base.function_module`, and `Base.datatype_module` are now methods of
a new function called `parentmodule` ([#25629]).

* `module_name`, `Base.function_name`, and `Base.datatype_name` are now methods of a
new function called `nameof` ([#25622]).

* `find` is now `findall` ([#25545]).

* `indmin` and `indmax` are now `argmin` and `argmax`, respectively ([#25654]).
Expand Down Expand Up @@ -499,6 +502,7 @@ includes this fix. Find the minimum version from there.
[#25544]: https://github.com/JuliaLang/julia/issues/25544
[#25545]: https://github.com/JuliaLang/julia/issues/25545
[#25571]: https://github.com/JuliaLang/julia/issues/25571
[#25622]: https://github.com/JuliaLang/julia/issues/25622
[#25628]: https://github.com/JuliaLang/julia/issues/25628
[#25629]: https://github.com/JuliaLang/julia/issues/25629
[#25654]: https://github.com/JuliaLang/julia/issues/25654
Expand Down
7 changes: 7 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,13 @@ end
export codeunits, ncodeunits
end

@static if !isdefined(Base, :nameof)
nameof(m::Module) = Base.module_name(m)
nameof(f::Function) = Base.function_name(f)
nameof(t::Union{DataType,UnionAll}) = Base.datatype_name(t)
export nameof
end

include("deprecated.jl")

end # module Compat
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,12 @@ end
@test codeunits("foo") == [0x66,0x6f,0x6f] == codeunits(SubString("fooαβγ",1,3))
@test ncodeunits("αβγ") == 6 == ncodeunits(SubString("fooαβγ",4,8))

# 0.7.0-DEV.3539
@test nameof(Compat.Sys) == :Sys
@test nameof(sin) == :sin
@test nameof(Float64) == :Float64
@test nameof(Array) == :Array

# 0.7.0-DEV.3382
module TestLibdl
using Compat
Expand Down

0 comments on commit 5d14f28

Please sign in to comment.