diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 4106d354da24a..3169537ceb9c0 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -1325,11 +1325,11 @@ AnyDict( i = position(buf) if i != 0 c = buf.data[i] - if c == '\n' || c == '\t' || + if c == UInt8('\n') || c == UInt8('\t') || # hack to allow path completion in cmds # after a space, e.g., `cd `, while still # allowing multiple indent levels - (c == ' ' && i > 3 && buf.data[i-1] == ' ') + (c == UInt8(' ') && i > 3 && buf.data[i-1] == UInt8(' ')) edit_insert(s, " "^4) return end diff --git a/base/REPL.jl b/base/REPL.jl index 90929b02d9a99..dcfd69f2e90e3 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -360,7 +360,7 @@ function hist_from_file(hp, file) while !isempty(line) push!(lines, chomp(line[2:end])) eof(file) && break - ch = Base.peek(file) + ch = Char(Base.peek(file)) ch == ' ' && error(munged_history_message, countlines) ch != '\t' && break line = hist_getline(file) diff --git a/base/char.jl b/base/char.jl index 319e4b35257b8..75105b174b674 100644 --- a/base/char.jl +++ b/base/char.jl @@ -30,12 +30,7 @@ isempty(c::Char) = false in(x::Char, y::Char) = x == y ==(x::Char, y::Char) = UInt32(x) == UInt32(y) -==(x::Char, y::Integer) = UInt32(x) == y -==(x::Integer, y::Char) = x == UInt32(y) - -isless(x::Char, y::Char) = isless(UInt32(x), UInt32(y)) -isless(x::Char, y::Integer) = isless(UInt32(x), y) -isless(x::Integer, y::Char) = isless(x, UInt32(y)) +isless(x::Char, y::Char) = UInt32(x) < UInt32(y) -(x::Char, y::Char) = Int(x) - Int(y) -(x::Char, y::Integer) = Char(Int32(x) - Int32(y)) diff --git a/base/datafmt.jl b/base/datafmt.jl index f9b3cb1e9ce72..07dfcafb54574 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -23,7 +23,7 @@ function countlines(io::IO, eol::Char='\n') while !eof(io) nb = readbytes!(io, a) @simd for i=1:nb - @inbounds nl += a[i] == eol + @inbounds nl += a[i] == UInt8(eol) end end nl diff --git a/base/deprecated.jl b/base/deprecated.jl index 331e483161010..c348ebab631b2 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1123,6 +1123,14 @@ end @deprecate_binding UTF8String String @deprecate_binding ByteString String +@deprecate ==(x::Char, y::Integer) UInt32(x) == y +@deprecate ==(x::Integer, y::Char) x == UInt32(y) +@deprecate isless(x::Char, y::Integer) UInt32(x) < y +@deprecate isless(x::Integer, y::Char) x < UInt32(y) +# delete these methods along with deprecations: +isequal(x::Char, y::Integer) = false +isequal(x::Integer, y::Char) = false + # During the 0.5 development cycle, do not add any deprecations below this line # To be deprecated in 0.6 diff --git a/base/float.jl b/base/float.jl index 50da2e0cdaee1..e199c6565f171 100644 --- a/base/float.jl +++ b/base/float.jl @@ -337,7 +337,7 @@ hash(x::UInt64, h::UInt) = hx(x, Float64(x), h) hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h) hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN $ h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h) -hash(x::Union{Bool,Char,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h) +hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h) hash(x::Float32, h::UInt) = hash(Float64(x), h) ## precision, as defined by the effective number of bits in the mantissa ## diff --git a/base/markdown/Common/block.jl b/base/markdown/Common/block.jl index 432e0a239e8ba..891a4fecbd32e 100644 --- a/base/markdown/Common/block.jl +++ b/base/markdown/Common/block.jl @@ -198,7 +198,7 @@ function list(stream::IO, block::MD) c = read(stream, Char) if c == '\n' eof(stream) && break - next = peek(stream) + next = Char(peek(stream)) # ok since we only compare with ASCII if next == '\n' break else diff --git a/base/markdown/Julia/interp.jl b/base/markdown/Julia/interp.jl index eecfcb09b9487..b34f8f122b4a7 100644 --- a/base/markdown/Julia/interp.jl +++ b/base/markdown/Julia/interp.jl @@ -9,7 +9,7 @@ end function interpinner(stream::IO, greedy = false) startswith(stream, '$') || return - (eof(stream) || peek(stream) in whitespace) && return + (eof(stream) || Char(peek(stream)) in whitespace) && return try return Base.parse(stream::IOBuffer, greedy = greedy) catch e diff --git a/base/markdown/parse/parse.jl b/base/markdown/parse/parse.jl index 79b5d22efea46..5df7ff71884b5 100644 --- a/base/markdown/parse/parse.jl +++ b/base/markdown/parse/parse.jl @@ -51,7 +51,9 @@ function parseinline(stream::IO, md::MD, config::Config) content = [] buffer = IOBuffer() while !eof(stream) - char = peek(stream) + # FIXME: this is broken if we're looking for non-ASCII + # characters because peek only returns a single byte. + char = Char(peek(stream)) if haskey(config.inner, char) && (inner = parseinline(stream, md, config.inner[char])) !== nothing c = takebuf_string(buffer) diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl index 3eca2c9f9f794..71efddb507d1e 100644 --- a/base/markdown/parse/util.jl +++ b/base/markdown/parse/util.jl @@ -16,7 +16,7 @@ const whitespace = " \t\r" Skip any leading whitespace. Returns io. """ function skipwhitespace(io::IO; newlines = true) - while !eof(io) && (peek(io) in whitespace || (newlines && peek(io) == '\n')) + while !eof(io) && (Char(peek(io)) in whitespace || (newlines && peek(io) == UInt8('\n'))) read(io, Char) end return io @@ -82,7 +82,7 @@ function startswith(stream::IO, s::AbstractString; eat = true, padding = false, end function startswith(stream::IO, c::Char; eat = true) - if !eof(stream) && peek(stream) == c + if !eof(stream) && peek(stream) == UInt8(c) eat && read(stream, Char) return true else @@ -181,7 +181,7 @@ function parse_inline_wrapper(stream::IO, delimiter::AbstractString; rep = false startswith(stream, delimiter^n) || return nothing while startswith(stream, delimiter); n += 1; end !rep && n > nmin && return nothing - !eof(stream) && peek(stream) in whitespace && return nothing + !eof(stream) && Char(peek(stream)) in whitespace && return nothing buffer = IOBuffer() while !eof(stream) diff --git a/base/printf.jl b/base/printf.jl index 96fbed7a62ef4..c2882d65452c1 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -458,7 +458,7 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo # print sign '+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) : ' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) : - push!(blk.args, :(neg && write(out, '-'))) + push!(blk.args, :(neg && write(out, '-'))) # print zero padding if padding !== nothing && !('-' in flags) && '0' in flags push!(blk.args, pad(width, padding, '0')) @@ -468,7 +468,7 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo if precision > 0 if inside_g && !('#' in flags) push!(blk.args, :(endidx = $ndigits; - while endidx > 1 && DIGITS[endidx] == '0' + while endidx > 1 && DIGITS[endidx] == UInt8('0') endidx -= 1 end; if endidx > 1 diff --git a/test/char.jl b/test/char.jl index d2bf335b8c047..9861fc9e13d01 100644 --- a/test/char.jl +++ b/test/char.jl @@ -2,7 +2,7 @@ #tests for /base/char.jl -@test typemin(Char) == 0 +@test typemin(Char) == Char(0) @test ndims(Char) == 0 @test getindex('a', 1) == 'a' @test_throws BoundsError getindex('a',2) @@ -133,44 +133,44 @@ let #isless(x::Char, y::Integer) = isless(UInt32(x), y) for x in upperchars - @test isless(x, 91) == true + @test isless(x, Char(91)) == true end for x in lowerchars - @test isless(x, 123) == true + @test isless(x, Char(123)) == true end for x in numberchars - @test isless(x, 66) == true + @test isless(x, Char(66)) == true end for x in plane1_playingcards - @test isless(x, 127151) == true + @test isless(x, Char(127151)) == true end for x in plane2_cjkpart1 - @test isless(x, 131088) == true + @test isless(x, Char(131088)) == true end #isless(x::Integer, y::Char) = isless(x, UInt32(y)) for x in upperchars - @test isless(64, x) == true + @test isless(Char(64), x) == true end for x in lowerchars - @test isless(96, x) == true + @test isless(Char(96), x) == true end for x in numberchars - @test isless(47, x) == true + @test isless(Char(47), x) == true end for x in plane1_playingcards - @test isless(127135, x) == true + @test isless(Char(127135), x) == true end for x in plane2_cjkpart1 - @test isless(131071, x) == true + @test isless(Char(131071), x) == true end end #end of let block @@ -191,3 +191,5 @@ let @test array == ['a', 'a', 'a'] @test eltype(array) == Char end + +@test !isequal('x', 120) diff --git a/test/random.jl b/test/random.jl index bbff7ccea5f87..a9c25cb0a7532 100644 --- a/test/random.jl +++ b/test/random.jl @@ -42,7 +42,7 @@ let mt = MersenneTwister() srand(mt) @test rand(mt, 0:3:1000) in 0:3:1000 @test issubset(rand!(mt, Array(Int, 100), 0:3:1000), 0:3:1000) - coll = Any[2, UInt128(128), big(619), "string", 'c'] + coll = Any[2, UInt128(128), big(619), "string"] @test rand(mt, coll) in coll @test issubset(rand(mt, coll, 2, 3), coll) @@ -315,7 +315,7 @@ for rng in ([], [MersenneTwister()], [RandomDevice()]) rand!(rng..., BitArray(5)) ::BitArray{1} rand!(rng..., BitArray(2, 3)) ::BitArray{2} - for T in [Base.BitInteger_types..., Bool, Char, Float16, Float32, Float64] + for T in [Base.BitInteger_types..., Bool, Float16, Float32, Float64] a0 = rand(rng..., T) ::T a1 = rand(rng..., T, 5) ::Vector{T} a2 = rand(rng..., T, 2, 3) ::Array{T, 2} diff --git a/test/read.jl b/test/read.jl index bf39dc23265c3..87bde3aa30181 100644 --- a/test/read.jl +++ b/test/read.jl @@ -382,9 +382,9 @@ f = joinpath(dir, "test.txt") open(io->write(io, "123"), f, "w") f1 = open(f) f2 = Base.Filesystem.open(f, Base.Filesystem.JL_O_RDONLY) -@test read(f1, UInt8) == read(f2, UInt8) == '1' -@test read(f1, UInt8) == read(f2, UInt8) == '2' -@test read(f1, UInt8) == read(f2, UInt8) == '3' +@test read(f1, UInt8) == read(f2, UInt8) == UInt8('1') +@test read(f1, UInt8) == read(f2, UInt8) == UInt8('2') +@test read(f1, UInt8) == read(f2, UInt8) == UInt8('3') @test_throws EOFError read(f1, UInt8) @test_throws EOFError read(f2, UInt8) close(f1) diff --git a/test/sets.jl b/test/sets.jl index bebced5b518b3..8b830b9b2ee36 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -244,3 +244,5 @@ let s = Set(1:5) end @test pop!(Set(1:2), 2, nothing) == 2 + +@test length(Set(['x',120])) == 2 diff --git a/test/spawn.jl b/test/spawn.jl index 0818bdcbfaa39..d446ae2b17ea1 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -276,7 +276,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN wait(ready) # wait for writer task to be ready before using `out` @test nb_available(out) == 0 @test endswith(readuntil(out, '1'), '1') - @test read(out, UInt8) == '\t' + @test Char(read(out, UInt8)) == '\t' c = UInt8[0] @test c == read!(out, c) Base.wait_readnb(out, 1) @@ -288,7 +288,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN @test !iswritable(out) @test !isopen(out) @test nb_available(out) == 0 - @test c == ['w'] + @test c == UInt8['w'] @test lstrip(ln2) == "1\thello\n" @test ln1 == "orld\n" @test isempty(read(out)) diff --git a/test/strings/basic.jl b/test/strings/basic.jl index 2a6a3660f376a..99cab256668ef 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -477,7 +477,7 @@ str = "abcdef\uff\uffff\u10ffffABCDEF" @test typeof(lowercase(utf16(str))) == UTF16String @test typeof(lowercase(utf32(str))) == UTF32String -foomap(ch) = (ch > 65) +foomap(ch) = (ch > Char(65)) foobar(ch) = Char(0xd800) foobaz(ch) = reinterpret(Char, typemax(UInt32)) @test_throws UnicodeError map(foomap, utf16(str)) diff --git a/test/unicode/utf32.jl b/test/unicode/utf32.jl index 54e3dff171604..8165a6aaecc6d 100644 --- a/test/unicode/utf32.jl +++ b/test/unicode/utf32.jl @@ -4,7 +4,7 @@ u8 = "\U10ffff\U1d565\U1d7f6\U00066\U2008a" u32 = utf32(u8) @test sizeof(u32) == 20 -@test length(u32.data) == 6 && u32.data[end] == Char(0) +@test length(u32.data) == 6 && u32.data[end] == 0 @test length(u32) == 5 @test utf8(u32) == u8 @test collect(u8) == collect(u32) @@ -181,13 +181,13 @@ for (fun, S, T) in ((utf16, UInt16, UTF16String), (utf32, UInt32, UTF32String)) str = "abcd\0\uff\u7ff\u7fff\U7ffff" tst = SubString(convert(T,str),4) cmp = Char['d','\0','\uff','\u7ff','\u7fff','\U7ffff'] - cmpch = Char['d','\0','\uff','\u7ff','\u7fff','\U7ffff','\0'] + cmp32 = UInt32['d','\0','\uff','\u7ff','\u7fff','\U7ffff','\0'] cmp16 = UInt16[0x0064,0x0000,0x00ff,0x07ff,0x7fff,0xd9bf,0xdfff,0x0000] x = fun(tst) - cmpx = (S == UInt16 ? cmp16 : cmpch) + cmpx = (S == UInt16 ? cmp16 : cmp32) @test typeof(tst) == SubString{T} @test convert(T, tst) == str[4:end] - S != UInt32 && @test convert(Vector{Char}, x) == cmp + @test convert(Vector{Char}, x) == cmp # Vector{T} / Array{T} @test convert(Vector{S}, x) == cmpx @test convert(Array{S}, x) == cmpx @@ -223,9 +223,9 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x74 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0074 + @test unsafe_load(p16,1) == 0x74 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 't' + @test unsafe_load(p32,1) == 0x74 pa = pointer(str, 2) p8 = pointer(u8, 2) p16 = pointer(u16, 2) @@ -235,10 +235,10 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x68 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0068 + @test unsafe_load(p16,1) == 0x68 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 'h' - s8 = SubString{String}(u8, 3, 5) + @test unsafe_load(p32,1) == 0x68 + s8 = SubString{String}(u8, 3, 5) s16 = SubString{UTF16String}(u16, 3, 5) s32 = SubString{UTF32String}(u32, 3, 5) p8 = pointer(s8) @@ -247,18 +247,18 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x69 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0069 + @test unsafe_load(p16,1) == 0x69 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 'i' + @test unsafe_load(p32,1) == 0x69 p8 = pointer(s8, 2) p16 = pointer(s16, 2) p32 = pointer(s32, 2) @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x73 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0073 + @test unsafe_load(p16,1) == 0x73 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 's' + @test unsafe_load(p32,1) == 0x73 end @test isvalid(Char['f','o','o','b','a','r'])