Skip to content

Commit

Permalink
wip: test
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Feb 17, 2020
1 parent 8b12823 commit 8c5f32d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/refactor.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@testset "rename refactor" begin
import Atom: renamerefactor

@testset "catch invalid/unsupported refactorings" begin
# catch renaming on keywords
let result = renamerefactor("function", "function", "func")
@test haskey(result, :warning)
end

# catch field renaming
let result = renamerefactor("field", "obj.field", "newfield")
@test haskey(result, :warning)
end

# but when dot-accessed object is a (existing) module, continues refactoring
let result = renamerefactor("bind", "Main.bind", "newbind")
@test !haskey(result, :warning)
@test haskey(result, :info)
end
end

@testset "local rename refactor" begin
# TODO
end

@testset "global rename refactor" begin
@testset "catch edge cases" begin
# handle refactoring on an unsaved / non-existing file
let context = """
toplevel() = nothing
"""
# mock MAIN_MODULE_LOCATION update in `module` handler
@eval Atom begin
MAIN_MODULE_LOCATION[] = "", 1
end
result = renamerefactor("toplevel", "toplevel", "toplevel2", 0, 1, 1, context)
@test haskey(result, :warning)
@test result[:warning] == Atom.unsaveddescription()
end

# handle refactoring on nonwritable files
let path = joinpath(@__DIR__, "fixtures", "Junk.jl")
originalmode = Base.filemode(path)

try
Base.chmod(path, 0x444) # only reading
context = "module Junk2 end"
result = renamerefactor("Junk2", "Junk2", "Junk3", 0, 1, 1, context, "Main.Junk")

@test haskey(result, :warning)
@test result[:warning] == Atom.nonwritablesdescription(Main.Junk, [path])
catch err
@info """
Cancelled the test for handling of refactorings on non-writable
files due to the error below:
""" err
finally
Base.chmod(path, originalmode)
end
end
end
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ include("outline.jl")
include("completions.jl")
include("goto.jl")
include("datatip.jl")
include("refactor.jl")
include("workspace.jl")
include("docs.jl")

0 comments on commit 8c5f32d

Please sign in to comment.