Skip to content

Commit

Permalink
Add test_julia_repl.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed May 2, 2018
1 parent b509c7b commit 072da65
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/IPython.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

# Register keybind '.' in Julia REPL:

function init_repl_if_not()
function init_repl_if_not(; _init_repl=init_repl)
active_repl = try
Base.active_repl
catch err
Expand All @@ -29,7 +29,7 @@ function init_repl_if_not()
end

if isinteractive() && typeof(active_repl) != Base.REPL.BasicREPL
init_repl(active_repl)
_init_repl(active_repl)
end
end
# See: https://github.com/JuliaInterop/RCall.jl/blob/master/src/setup.jl
Expand Down
7 changes: 7 additions & 0 deletions test/preamble.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@static if VERSION < v"0.7.0-DEV.2005"
using Base.Test
else
using Test
end

using IPython
11 changes: 4 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# module TestIPython

using IPython
import PyCall
@static if VERSION < v"0.7.0-DEV.2005"
using Base.Test
else
using Test
end
include("preamble.jl")

import PyCall
@show PyCall.pyprogramname
@show PyCall.pyversion
@show PyCall.libpython
Expand All @@ -21,4 +16,6 @@ ipy_main = ipy_opts["user_ns"]["Main"]
@test x == 17061
end

include("test_julia_repl.jl")

# end # module
39 changes: 39 additions & 0 deletions test/test_julia_repl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module TestJuliaREPL

include("preamble.jl")
using IPython: init_repl, init_repl_if_not
using Base.Terminals: TextTerminal


@testset "init_repl_if_not" begin
repl = init_repl_if_not(; _init_repl=identity)
if isinteractive()
@test repl === Base.active_repl
else
@test repl === nothing
end
end


struct DummyTerminal <: TextTerminal
end

function dummy_repl()
repl = Base.REPL.LineEditREPL(DummyTerminal())
repl.interface = Base.REPL.setup_interface(repl)
return repl
end

function dummy_initialized_repl()
repl = dummy_repl()
init_repl(repl)
return repl
end

@testset "init_repl" begin
repl = dummy_initialized_repl()
keymap_dict = repl.interface.modes[1].keymap_dict
@test haskey(keymap_dict, '.')
end

end # module

0 comments on commit 072da65

Please sign in to comment.