Skip to content

Commit

Permalink
Wrap in let block, add unicode
Browse files Browse the repository at this point in the history
Add a let block around the entire test base to try to avoid leaking
variables into other tests, add plane1 and plane2 examples
  • Loading branch information
randyzwitch committed Feb 3, 2015
1 parent 025c3a3 commit 2feee44
Showing 1 changed file with 51 additions and 107 deletions.
158 changes: 51 additions & 107 deletions test/char.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#tests for /base/char.jl
let

numberchars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
lowerchars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upperchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
plane1_playingcards = ['🂠', '🂡', '🂢', '🂣', '🂤', '🂥', '🂦', '🂧', '🂨', '🂩', '🂪', '🂫', '🂬', '🂭', '🂮']
plane2_cjkpart1 = ['𠀀', '𠀁', '𠀂', '𠀃', '𠀄', '𠀅', '𠀆', '𠀇', '𠀈', '𠀉', '𠀊', '𠀋', '𠀌', '𠀍', '𠀎', '𠀏']

testarrays = [numberchars,
lowerchars,
upperchars,
plane1_playingcards,
plane2_cjkpart1]

#char(x::FloatingPoint) = char(round(UInt32,x))
@test char(1.00000001) == '\x01' #Round down
Expand Down Expand Up @@ -32,6 +41,20 @@ upperchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', '
counter += 1
end

#tests Unicode plane 1: 127136 - 127150
counter = 127136
for x in plane1_playingcards
@test integer(x) == counter
counter += 1
end

#tests Unicode plane 2: 131072 - 131087
counter = 131072
for x in plane2_cjkpart1
@test integer(x) == counter
counter += 1
end

#convert(::Type{Char}, x::Float16) = char(convert(UInt32, x))
#convert(::Type{Char}, x::Float32) = char(convert(UInt32, x))
#convert(::Type{Char}, x::Float64) = char(convert(UInt32, x))
Expand All @@ -46,155 +69,59 @@ upperchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', '
@test convert(Char, float16(9)) == convert(Char, float32(9)) == convert(Char, float64(9)) == '\x09'

#size(c::Char) = ()
for x in upperchars
@test size(x) == ()
end

for x in lowerchars
@test size(x) == ()
end

for x in numberchars
for x in testarrays
@test size(x) == ()
end

#ndims(c::Char) = 0
for x in upperchars
@test ndims(x) == 0
end

for x in lowerchars
@test ndims(x) == 0
end

for x in numberchars
for x in testarrays
@test ndims(x) == 0
end

#length(c::Char) = 1
for x in upperchars
@test length(x) == 1
end

for x in lowerchars
@test length(x) == 1
end

for x in numberchars
for x in testarrays
@test length(x) == 1
end

#endof(c::Char) = 1
for x in upperchars
@test endof(x) == 1
end

for x in lowerchars
@test endof(x) == 1
end

for x in numberchars
for x in testarrays
@test endof(x) == 1
end

#getindex(c::Char) = c
for x in upperchars
@test getindex(x) == x
end

for x in lowerchars
@test getindex(x) == x
end

for x in numberchars
for x in testarrays
@test getindex(x) == x
end

#first(c::Char) = c
for x in upperchars
@test first(x) == x
end

for x in lowerchars
@test first(x) == x
end

for x in numberchars
for x in testarrays
@test first(x) == x
end

#last(c::Char) = c
for x in upperchars
@test last(x) == x
end

for x in lowerchars
@test last(x) == x
end

for x in numberchars
for x in testarrays
@test last(x) == x
end

#eltype(c::Char) = Char
for x in upperchars
@test eltype(x) == Char
end

for x in lowerchars
@test eltype(x) == Char
end

for x in numberchars
for x in testarrays
@test eltype(x) == Char
end

#start(c::Char) = false
for x in upperchars
@test start(x) == false
end

for x in lowerchars
@test start(x) == false
end

for x in numberchars
for x in testarrays
@test start(x) == false
end

#next(c::Char, state) = (c, true)
for x in upperchars
for state in [true, false]
@test next(x, state) == (x, true)
end
end

for x in lowerchars
for state in [true, false]
@test next(x, state) == (x, true)
end
end

for x in numberchars
for x in testarrays
for state in [true, false]
@test next(x, state) == (x, true)
end
end

#done(c::Char, state) = state
for x in upperchars
for state in [true, false]
@test done(x, state) == state
end
end

for x in lowerchars
for state in [true, false]
@test done(x, state) == state
end
end

for x in numberchars
for x in testarrays
for state in [true, false]
@test done(x, state) == state
end
Expand All @@ -213,6 +140,14 @@ upperchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', '
@test isless(x, 66) == true
end

for x in plane1_playingcards
@test isless(x, 127151) == true
end

for x in plane2_cjkpart1
@test isless(x, 131088) == true
end

#isless(x::Integer, y::Char) = isless(x, uint32(y))
for x in upperchars
@test isless(64, x) == true
Expand All @@ -226,3 +161,12 @@ upperchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', '
@test isless(47, x) == true
end

for x in plane1_playingcards
@test isless(127135, x) == true
end

for x in plane2_cjkpart1
@test isless(131071, x) == true
end

end #end of let block

0 comments on commit 2feee44

Please sign in to comment.