Skip to content

Commit 8c5f32d

Browse files
committed
wip: test
1 parent 8b12823 commit 8c5f32d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

test/refactor.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
@testset "rename refactor" begin
2+
import Atom: renamerefactor
3+
4+
@testset "catch invalid/unsupported refactorings" begin
5+
# catch renaming on keywords
6+
let result = renamerefactor("function", "function", "func")
7+
@test haskey(result, :warning)
8+
end
9+
10+
# catch field renaming
11+
let result = renamerefactor("field", "obj.field", "newfield")
12+
@test haskey(result, :warning)
13+
end
14+
15+
# but when dot-accessed object is a (existing) module, continues refactoring
16+
let result = renamerefactor("bind", "Main.bind", "newbind")
17+
@test !haskey(result, :warning)
18+
@test haskey(result, :info)
19+
end
20+
end
21+
22+
@testset "local rename refactor" begin
23+
# TODO
24+
end
25+
26+
@testset "global rename refactor" begin
27+
@testset "catch edge cases" begin
28+
# handle refactoring on an unsaved / non-existing file
29+
let context = """
30+
toplevel() = nothing
31+
"""
32+
# mock MAIN_MODULE_LOCATION update in `module` handler
33+
@eval Atom begin
34+
MAIN_MODULE_LOCATION[] = "", 1
35+
end
36+
result = renamerefactor("toplevel", "toplevel", "toplevel2", 0, 1, 1, context)
37+
@test haskey(result, :warning)
38+
@test result[:warning] == Atom.unsaveddescription()
39+
end
40+
41+
# handle refactoring on nonwritable files
42+
let path = joinpath(@__DIR__, "fixtures", "Junk.jl")
43+
originalmode = Base.filemode(path)
44+
45+
try
46+
Base.chmod(path, 0x444) # only reading
47+
context = "module Junk2 end"
48+
result = renamerefactor("Junk2", "Junk2", "Junk3", 0, 1, 1, context, "Main.Junk")
49+
50+
@test haskey(result, :warning)
51+
@test result[:warning] == Atom.nonwritablesdescription(Main.Junk, [path])
52+
catch err
53+
@info """
54+
Cancelled the test for handling of refactorings on non-writable
55+
files due to the error below:
56+
""" err
57+
finally
58+
Base.chmod(path, originalmode)
59+
end
60+
end
61+
end
62+
end
63+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ include("outline.jl")
5858
include("completions.jl")
5959
include("goto.jl")
6060
include("datatip.jl")
61+
include("refactor.jl")
6162
include("workspace.jl")
6263
include("docs.jl")

0 commit comments

Comments
 (0)