Skip to content

Commit

Permalink
allow swapping Int32 literals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rfourquet committed Nov 7, 2020
1 parent d414f8c commit f8d8c22
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -4,9 +4,11 @@ os:
- linux
- osx

arch:
- x64
- x86

julia:
- 1.1
- 1.4
- 1.5
- nightly

Expand Down
4 changes: 2 additions & 2 deletions SwapLiterals/src/SwapLiterals.jl
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions SwapLiterals/test/runtests.jl
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f8d8c22

Please sign in to comment.