From 2b0b76e1e9e6ac28f605566caaf496e20383f022 Mon Sep 17 00:00:00 2001 From: Tom Gillam Date: Thu, 30 Nov 2023 21:22:56 +0000 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Curtis Vogt --- src/types/timezone.jl | 2 ++ test/helpers.jl | 10 ++++------ test/types/timezone.jl | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/types/timezone.jl b/src/types/timezone.jl index c68cad54..c547a40c 100644 --- a/src/types/timezone.jl +++ b/src/types/timezone.jl @@ -32,6 +32,8 @@ function _reload_cache!(ftz_cache::AbstractDict, vtz_cache::AbstractDict, compil ftz_cache[name] = (tz, class) elseif isa(tz, VariableTimeZone) vtz_cache[name] = (tz, class) + else + error("Unhandled TimeZone class encountered: $(typeof(tz))") end end end diff --git a/test/helpers.jl b/test/helpers.jl index 1b868af0..d045638d 100644 --- a/test/helpers.jl +++ b/test/helpers.jl @@ -1,6 +1,6 @@ # Utility functions for testing -if VERSION < v"1.9.0-" # https://github.com/JuliaLang/julia/pull/47367 +if VERSION < v"1.9.0-DEV.1744" # https://github.com/JuliaLang/julia/pull/47367 macro allocations(ex) quote while false; end # want to force compilation, but v1.6 doesn't have `@force_compile` @@ -75,11 +75,9 @@ function with_tz_cache(f, cache::Dict{String,Tuple{TimeZone,TimeZones.Class}}) empty!(TimeZones._FTZ_CACHE) empty!(TimeZones._VTZ_CACHE) foreach(cache) do (k, v) - setindex!( - isa(first(v), FixedTimeZone) ? TimeZones._FTZ_CACHE : TimeZones._VTZ_CACHE, - v, - k, - ) + tz = first(v) + cache = tz isa FixedTimeZone ? TimeZones._FTZ_CACHE : TimeZones._VTZ_CACHE + setindex!(cache, v, k) end try diff --git a/test/types/timezone.jl b/test/types/timezone.jl index 37dfc415..3c37bd13 100644 --- a/test/types/timezone.jl +++ b/test/types/timezone.jl @@ -3,11 +3,11 @@ using TimeZones: Class @testset "TimeZone allocations" begin tz = TimeZone("UTC") # run once for compilation and to populate cache @assert tz isa FixedTimeZone - @test 0 == @allocations(TimeZone("UTC")) + @test @allocations(TimeZone("UTC")) == 0 tz = TimeZone("America/Winnipeg") # populate cache @assert tz isa VariableTimeZone - @test 2 == @allocations(TimeZone("America/Winnipeg")) + @test @allocations(TimeZone("America/Winnipeg")) == 2 end @testset "istimezone" begin