Skip to content

Commit db53a9e

Browse files
committed
Add more tests, fix completions
1 parent 231bd8c commit db53a9e

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

src/Unicode_Entities.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ PackedEntities(tab::PackedTable) = PackedEntities(tab.offsetvec, tab.namtab)
2323
Base.getindex(str::PackedEntities, ind::Integer) =
2424
_unpackword(str.namtab[str.offsetvec[ind]+1:str.offsetvec[ind+1]])
2525

26-
include("unicode_table.jl")
26+
VER = UInt32(1)
27+
28+
immutable Unicode_Table{S,T,V} <: AbstractEntityTable
29+
ver::UInt32
30+
tim::String
31+
inf::String
32+
base32::UInt32
33+
nam::PackedTable{S,V} # This has packed byte vectors
34+
ind::Vector{UInt16}
35+
wrd1::StrTable{T} # This has sorted words for 1-byte
36+
wrd2::StrTable{T} # This has sorted words for 2-byte
37+
val16::Vector{UInt16}
38+
ind16::Vector{UInt16}
39+
val32::Vector{UInt16}
40+
ind32::Vector{UInt16}
41+
end
2742

2843
function __init__()
2944
const global _tab =
@@ -87,31 +102,26 @@ function _get_strings{T}(val::T, tab::Vector{T}, ind::Vector{UInt16})
87102
_names[ind[rng]]
88103
end
89104

90-
"""Given a Unicode name, return the string it represents, or an empty string if not found"""
91105
function lookupname(str::AbstractString)
92106
rng = searchsorted(_names, uppercase(str))
93107
isempty(rng) ? _empty_str : _get_str(_tab.ind[rng.start])
94108
end
95109

96-
"""Given a character, return all exact matches to the character as a vector"""
97110
matchchar(ch::Char) =
98111
(ch <= '\uffff'
99112
? _get_strings(ch%UInt16, _tab.val16, _tab.ind16)
100113
: (ch <= '\U1ffff' ? _get_strings(ch%UInt16, _tab.val32, _tab.ind32) : _empty_str_vec))
101114

102-
"""Given a string, return all exact matches to the string as a vector"""
103-
function matches end
104115
matches(str::AbstractString) = matches(convert(Vector{Char}, str))
105116
matches(vec::Vector{Char}) = length(vec) == 1 ? matchchar(vec[1]) : _empty_str_vec
106117

107-
"""Given a string, return all of the longest matches to the beginning of the string as a vector"""
108-
function longestmatches end
109118
longestmatches(str::AbstractString) = longestmatches(convert(Vector{Char},str))
110119
longestmatches(vec::Vector{Char}) = isempty(vec) ? _empty_str_vec : matchchar(uppercase(vec[1]))
111120

112-
"""Given a string, return all of the Unicode entity names that start with that string, if any"""
113-
function completions end
114121
completions(str::AbstractString) = completions(String(str))
115-
completions(str::String) = StrTables.matchfirst(_names, uppercase(str))
122+
function completions(str::String)
123+
str = uppercase(str)
124+
[nam for nam in _names if startswith(nam, str)]
125+
end
116126

117127
end # module

src/unicode_table.jl

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/runtests.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,15 @@ end
100100
end
101101
end
102102

103-
#=
104103
@testset "completions" begin
105104
@test isempty(UE.completions("ScottPaulJones"))
106-
for (chrs, exp) in (("A", ["AA", "AE", "Alpha"]),
107-
("mtt", ["mtta", "mttthree", "mttzero"]),
108-
("nleq", ["nleq", "nleqslant"]))
105+
for (chrs, exp) in (("ZERO", ["ZERO WIDTH JOINER", "ZERO WIDTH NO-BREAK SPACE",
106+
"ZERO WIDTH NON-JOINER", "ZERO WIDTH SPACE"]),
107+
("BACK OF", ["BACK OF ENVELOPE"]))
109108
res = UE.completions(chrs)
110109
@test length(res) >= length(exp)
111110
@test intersect(res, exp) == exp
112111
end
113112
end
114-
=#
115113
end
116114

0 commit comments

Comments
 (0)