Skip to content

Commit

Permalink
Merge pull request #8 from timholy/teh/fix_tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
timholy authored Dec 2, 2018
2 parents 5b7133a + 76ba672 commit 6d223d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
julia:
- 0.7
- 1.0
- nightly
notifications:
email: false

# comment the following lines to disallow failures on nightly julia
matrix:
allow_failures:
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
# packages:
# - gfortran
#before_script: # homebrew for mac
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi

## uncomment the following lines to override the default test script
#script:
# - julia -e 'import Pkg; Pkg.build(); Pkg.test(; coverage=true)'

after_success:
# push coverage results to Codecov
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
6 changes: 6 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ version = "0.2.1"

[deps]
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
33 changes: 17 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ using Test
using REPL.LineEdit: transition, state
using REPL.Terminals: TTYTerminal

mutable struct CountingHeader <: AbstractHeader
n::Int
nlines::Int
end
CountingHeader(n::Integer) = CountingHeader(n, nlines(n))

if isdefined(Base, :active_repl)

mutable struct CountingHeader <: AbstractHeader
n::Int
nlines::Int
end

nlines(n) = n == 0 ? 0 : n+1
CountingHeader(n::Integer) = CountingHeader(n, nlines(n))


function HeaderREPLs.print_header(io::IO, header::CountingHeader)
if header.nlines == 0
if header.n > 0
Expand All @@ -25,26 +26,26 @@ if isdefined(Base, :active_repl)
end
return nothing
end

function HeaderREPLs.setup_prompt(repl::HeaderREPL{CountingHeader}, hascolor::Bool)
julia_prompt = find_prompt(repl.interface, "julia")

prompt = REPL.LineEdit.Prompt(
"count> ";
prompt_prefix = hascolor ? repl.prompt_color : "",
prompt_suffix = hascolor ?
(repl.envcolors ? Base.input_color : repl.input_color) : "",
complete = julia_prompt.complete,
on_enter = REPL.return_callback)

prompt.on_done = HeaderREPLs.respond(repl, julia_prompt) do str
Base.parse_input_line(str; filename="COUNT")
end
# hist will be handled automatically if repl.history_file is true
# keymap_dict is separate
return prompt, :count
end

function HeaderREPLs.append_keymaps!(keymaps, repl::HeaderREPL{CountingHeader})
julia_prompt = find_prompt(repl.interface, "julia")
kms = [
Expand All @@ -57,25 +58,25 @@ if isdefined(Base, :active_repl)
]
append!(keymaps, kms)
end

function modify(s, repl, diff)
clear_io(state(s), repl)
repl.header.n = max(0, repl.header.n + diff)
refresh_header(s, repl)
end

@noinline increment(s, repl) = modify(s, repl, +1)
@noinline decrement(s, repl) = modify(s, repl, -1)

special_keys = Dict{Any,Any}(
'+' => (s, repl, str) -> increment(s, repl),
'-' => (s, repl, str) -> decrement(s, repl),
)

main_repl = Base.active_repl
repl = HeaderREPL(main_repl, CountingHeader(0))
REPL.setup_interface(repl; extra_repl_keymap=special_keys)

# Modify repl keymap so '|' enters the count> prompt
# (Normally you'd use the atreplinit mechanism)
function enter_count(s)
Expand Down

0 comments on commit 6d223d2

Please sign in to comment.