From f8d8c22357f73f42de8c65362286af660ca067f7 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Fri, 6 Nov 2020 17:13:05 +0100 Subject: [PATCH] allow swapping Int32 literals Tests on Julia < 1.5 have to be disabled until a new release is made, because the last release of SwapLiterals fails with Int32 swapping. --- .travis.yml | 6 ++++-- SwapLiterals/src/SwapLiterals.jl | 4 ++-- SwapLiterals/test/runtests.jl | 12 +++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07e91ab..b0ed15e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,11 @@ os: - linux - osx +arch: + - x64 + - x86 + julia: - - 1.1 - - 1.4 - 1.5 - nightly diff --git a/SwapLiterals/src/SwapLiterals.jl b/SwapLiterals/src/SwapLiterals.jl index b051b71..e2a5c00 100644 --- a/SwapLiterals/src/SwapLiterals.jl +++ b/SwapLiterals/src/SwapLiterals.jl @@ -38,13 +38,13 @@ function literals_swapper(swaps) throw(ArgumentError("unsupported type for swapper")) foreach(swaps) do kv - kv[1] ∈ Any[Float32,Float64,Int,String,Char, + kv[1] ∈ Any[Float32,Float64,Int32,Int64,String,Char, Base.BitUnsigned64_types...,Int128,UInt128,BigInt, :braces, :tuple, :vect, :(:=)] || throw(ArgumentError("type $(kv[1]) cannot be replaced")) end - function swapper(@nospecialize(ex::Union{Float32,Float64,Int,String,Char, + function swapper(@nospecialize(ex::Union{Float32,Float64,Int32,Int64,String,Char, Base.BitUnsigned64}), quoted=false) swap = get(swaps, typeof(ex), nothing) diff --git a/SwapLiterals/test/runtests.jl b/SwapLiterals/test/runtests.jl index f62fc44..7df4c16 100644 --- a/SwapLiterals/test/runtests.jl +++ b/SwapLiterals/test/runtests.jl @@ -207,9 +207,15 @@ makecoloneq(ex) = Expr(:(=), # Int & UInt @swapliterals Int => :UInt8 UInt => :Int8 begin @test 1 isa UInt8 - @test 0x0000000000000001 isa Int8 + if UInt === UInt64 + @test 0x0000000000000001 isa Int8 + @test 0x00000001 isa UInt32 + else + @test 0x00000001 isa Int8 + @test 0x0000000000000001 isa UInt64 + end end - @swapliterals Int64=>:UInt8 UInt64=>:Int8 begin + @swapliterals Int32=>:UInt8 Int64=>:UInt8 UInt64=>:Int8 begin @test 1 isa UInt8 @test 0x0000000000000001 isa Int8 end @@ -238,7 +244,7 @@ makecoloneq(ex) = Expr(:(=), @test 'a' isa String end - @swapliterals Char => :UInt String => :Symbol begin + @swapliterals Char => :UInt64 String => :Symbol begin @test "123" isa Symbol @test 'a' === 0x0000000000000061 end