Skip to content

Commit 79827cb

Browse files
format file according to .JuliaFormatter.toml
1 parent cb3fe59 commit 79827cb

File tree

4 files changed

+90
-55
lines changed

4 files changed

+90
-55
lines changed

.JuliaFormatter.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
remove_extra_newlines=true
2+
join_lines_based_on_source=true
3+
whitespace_in_kwargs=false
4+
short_to_long_function_def=true
5+
always_for_in=true
6+
verbose=true
7+
margin=88

docs/make.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using TerminalClock
22
using Documenter
33

4-
DocMeta.setdocmeta!(TerminalClock, :DocTestSetup, :(using TerminalClock); recursive=true)
4+
DocMeta.setdocmeta!(
5+
TerminalClock,
6+
:DocTestSetup,
7+
:(using TerminalClock);
8+
recursive=true,
9+
)
510

611
makedocs(;
712
modules=[TerminalClock],

src/TerminalClock.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ n2d(n::Int, ::Val{:Large}) = n2d(DIALS_LARGE, n)
5656
n2d(n::Int, ::Val{:Small}) = n2d(DIALS_SMALL, n)
5757
n2d(n::Int) = n2d(n, :Large)
5858

59-
function clearline(; move_up::Bool = false)
59+
function clearline(; move_up::Bool=false)
6060
buf = IOBuffer()
6161
print(buf, "\x1b[2K") # clear line
6262
print(buf, "\x1b[999D") # rollback the cursor
@@ -65,8 +65,8 @@ function clearline(; move_up::Bool = false)
6565
end
6666

6767
function clearlines(H::Integer)
68-
for _ = 1:H
69-
clearline(move_up = true)
68+
for _ in 1:H
69+
clearline(move_up=true)
7070
end
7171
end
7272

@@ -105,7 +105,11 @@ end
105105

106106
const Optional = Union{Nothing,Int}
107107

108-
function setup_timer(; hour = nothing::Optional, minute = nothing::Optional, second = nothing::Optional)
108+
function setup_timer(;
109+
hour=nothing::Optional,
110+
minute=nothing::Optional,
111+
second=nothing::Optional,
112+
)
109113
if all(isnothing.([hour, second, minute]))
110114
hour = 0
111115
minute = 3
@@ -118,7 +122,11 @@ function setup_timer(; hour = nothing::Optional, minute = nothing::Optional, sec
118122
return Time(hour, minute, second)
119123
end
120124

121-
function countdown(; hour = nothing::Optional, minute = nothing::Optional, second = nothing::Optional)
125+
function countdown(;
126+
hour=nothing::Optional,
127+
minute=nothing::Optional,
128+
second=nothing::Optional,
129+
)
122130
countdown(setup_timer(; hour, minute, second))
123131
end
124132

@@ -141,13 +149,14 @@ function countdown(t::Time)
141149
end
142150
end
143151

144-
function stopwatch(duration = 0.1::AbstractFloat)
152+
function stopwatch(duration=0.1::AbstractFloat)
145153
start = Dates.now()
146154
sleep(0.001) # warmup
147155
while true
148156
try
149157
Δ = Dates.now() - start # millisecond
150-
periods = Dates.canonicalize(Dates.CompoundPeriod(Dates.Millisecond(Δ))).periods
158+
periods =
159+
Dates.canonicalize(Dates.CompoundPeriod(Dates.Millisecond(Δ))).periods
151160
str = stopwatch(Time(periods...))
152161
println(str)
153162
sleep(duration)

test/runtests.jl

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ function with_temp_depot(f::Function)
2121
end
2222

2323
# Taken from Prefernces.jl/test/runtests.jl
24-
function activate_and_run(project_dir::String, code::String; env::Dict = Dict())
24+
function activate_and_run(project_dir::String, code::String; env::Dict=Dict())
2525
mktempdir() do dir
2626
open(joinpath(dir, "test_code.jl"), "w") do io
2727
write(io, code)
2828
end
2929

3030
out = Pipe()
31-
cmd = setenv(`$(Base.julia_cmd()) --project=$(project_dir) $(dir)/test_code.jl`,
32-
env..., "JULIA_DEPOT_PATH" => Base.DEPOT_PATH[1])
31+
cmd =
32+
setenv(`$(Base.julia_cmd()) --project=$(project_dir) $(dir)/test_code.jl`,
33+
env..., "JULIA_DEPOT_PATH" => Base.DEPOT_PATH[1])
3334
p = run(pipeline(cmd, stdout=out, stderr=out); wait=false)
3435
close(out.in)
3536
wait(p)
@@ -43,7 +44,7 @@ function activate_and_run(project_dir::String, code::String; env::Dict = Dict())
4344
end
4445

4546
@testset "Dial" begin
46-
for n = 0:9
47+
for n in 0:9
4748
@test length(split(n2d(n).str, "\n")) == 9
4849
@test length(split(n2d(n), "\n")) == 9
4950
end
@@ -73,61 +74,74 @@ end
7374
end
7475

7576
@testset "setup_timer" begin
76-
@test setup_timer(hour = 1) == Time(1, 0, 0)
77-
@test setup_timer(minute = 2) == Time(0, 2, 0)
78-
@test setup_timer(second = 3) == Time(0, 0, 3)
79-
@test setup_timer(hour = 1, minute = 2, second = 3) == Time(1, 2, 3)
77+
@test setup_timer(hour=1) == Time(1, 0, 0)
78+
@test setup_timer(minute=2) == Time(0, 2, 0)
79+
@test setup_timer(second=3) == Time(0, 0, 3)
80+
@test setup_timer(hour=1, minute=2, second=3) == Time(1, 2, 3)
8081
end
8182

8283
@testset "preference" begin
83-
local_prefs_toml = joinpath(dirname(dirname(pathof(TerminalClock))), "LocalPreferences.toml")
84+
local_prefs_toml =
85+
joinpath(dirname(dirname(pathof(TerminalClock))), "LocalPreferences.toml")
8486
rm(local_prefs_toml; force=true)
8587
with_temp_depot() do
86-
project_dir = joinpath(dirname(@__DIR__,))
88+
project_dir = joinpath(dirname(@__DIR__))
8789

8890
# test for set_dials
89-
activate_and_run(project_dir, """
90-
using Pkg; Pkg.instantiate()
91-
using TerminalClock
92-
unicodebox = joinpath(dirname(pathof(TerminalClock)), "dials", "UnicodeBox.toml")
93-
TerminalClock.set_dials(unicodebox)
94-
""")
91+
activate_and_run(
92+
project_dir,
93+
"""
94+
using Pkg; Pkg.instantiate()
95+
using TerminalClock
96+
unicodebox = joinpath(dirname(pathof(TerminalClock)), "dials", "UnicodeBox.toml")
97+
TerminalClock.set_dials(unicodebox)
98+
""",
99+
)
95100
prefs = local_prefs_toml |> TOML.parsefile
96101
@test haskey(prefs, "TerminalClock")
97102
@test basename(prefs["TerminalClock"]["tomlfile"]) == "UnicodeBox.toml"
98103

99-
activate_and_run(project_dir, """
100-
using Test
101-
using TerminalClock, Dates
102-
dt = DateTime(2021, 11, 15, 12, 34, 56, 7)
103-
str = clock(dt)
104-
txt = joinpath("references", "UnicodeBox", "clock.txt")
105-
@test str == join(readlines(txt), "\n")
104+
activate_and_run(
105+
project_dir,
106+
"""
107+
using Test
108+
using TerminalClock, Dates
109+
dt = DateTime(2021, 11, 15, 12, 34, 56, 7)
110+
str = clock(dt)
111+
txt = joinpath("references", "UnicodeBox", "clock.txt")
112+
@test str == join(readlines(txt), "\n")
106113
107-
t = Time(12, 34, 56, 789)
108-
str = stopwatch(t)
109-
txt = joinpath("references", "UnicodeBox", "stopwatch.txt")
110-
@test str == join(readlines(txt), "\n")
111-
""")
114+
t = Time(12, 34, 56, 789)
115+
str = stopwatch(t)
116+
txt = joinpath("references", "UnicodeBox", "stopwatch.txt")
117+
@test str == join(readlines(txt), "\n")
118+
""",
119+
)
112120

113121
# test for clear_dials
114-
activate_and_run(project_dir, """
115-
using TerminalClock
116-
TerminalClock.clear_dials()
117-
""")
118-
119-
activate_and_run(project_dir, """
120-
using Test
121-
using TerminalClock, Dates
122-
dt = DateTime(2021, 11, 15, 12, 34, 56, 7)
123-
str = clock(dt)
124-
txt = joinpath("references", "ASCII", "clock.txt")
125-
@test str == join(readlines(txt), "\n")
126-
127-
t = Time(12, 34, 56, 789)
128-
str = stopwatch(t)
129-
txt = joinpath("references", "ASCII", "stopwatch.txt")
130-
@test str == join(readlines(txt), "\n")
131-
""")
122+
activate_and_run(
123+
project_dir,
124+
"""
125+
using TerminalClock
126+
TerminalClock.clear_dials()
127+
""",
128+
)
129+
130+
activate_and_run(
131+
project_dir,
132+
"""
133+
using Test
134+
using TerminalClock, Dates
135+
dt = DateTime(2021, 11, 15, 12, 34, 56, 7)
136+
str = clock(dt)
137+
txt = joinpath("references", "ASCII", "clock.txt")
138+
@test str == join(readlines(txt), "\n")
139+
140+
t = Time(12, 34, 56, 789)
141+
str = stopwatch(t)
142+
txt = joinpath("references", "ASCII", "stopwatch.txt")
143+
@test str == join(readlines(txt), "\n")
144+
""",
145+
)
132146
end # with_temp_depot
133-
end
147+
end

0 commit comments

Comments
 (0)