Skip to content

Commit

Permalink
Fix namespacing for unicode trimmer
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc authored and jordansissel committed Jul 10, 2015
1 parent f4edadc commit f7b76fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/logstash/util/unicode_trimmer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module UnicodeTrimmer
module LogStash::Util::UnicodeTrimmer
# The largest possible unicode chars are 4 bytes
# http://stackoverflow.com/questions/9533258/what-is-the-maximum-number-of-bytes-for-a-utf-8-encoded-character
# http://tools.ietf.org/html/rfc3629
Expand Down
16 changes: 9 additions & 7 deletions spec/util/unicode_trimmer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,37 @@
end

describe "truncating unicode strings correctly" do
subject { LogStash::Util::UnicodeTrimmer }

context "with extra bytes before the snip" do
let(:ustr) { "Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!" }

it "should truncate to exact byte boundaries when possible" do
expect(UnicodeTrimmer.trim_bytes(ustr, 21).bytesize).to eql(21)
expect(subject.trim_bytes(ustr, 21).bytesize).to eql(21)
end

it "should truncate below the bytesize when splitting a byte" do
expect(UnicodeTrimmer.trim_bytes(ustr, 20).bytesize).to eql(18)
expect(subject.trim_bytes(ustr, 20).bytesize).to eql(18)
end

it "should not truncate the string when the bytesize is already OK" do
expect(UnicodeTrimmer.trim_bytes(ustr, ustr.bytesize)).to eql(ustr)
expect(subject.trim_bytes(ustr, ustr.bytesize)).to eql(ustr)
end
end

context "with extra bytes after the snip" do
let(:ustr) { ": 1<2 & 4+1>3, now 20% off! testing «ταБЬℓσ»" }

it "should truncate to exact byte boundaries when possible" do
expect(UnicodeTrimmer.trim_bytes(ustr, 21).bytesize).to eql(21)
expect(subject.trim_bytes(ustr, 21).bytesize).to eql(21)
end

it "should truncate below the bytesize when splitting a byte" do
expect(UnicodeTrimmer.trim_bytes(ustr, 52).bytesize).to eql(51)
expect(subject.trim_bytes(ustr, 52).bytesize).to eql(51)
end

it "should not truncate the string when the bytesize is already OK" do
expect(UnicodeTrimmer.trim_bytes(ustr, ustr.bytesize)).to eql(ustr)
expect(subject.trim_bytes(ustr, ustr.bytesize)).to eql(ustr)
end
end

Expand All @@ -47,7 +49,7 @@
let(:expected_range) { (size - 4)..size }

stress_it "should be near the boundary of requested size" do
expect(expected_range).to include(UnicodeTrimmer.trim_bytes(text, size).bytesize)
expect(expected_range).to include(subject.trim_bytes(text, size).bytesize)
end
end
end

0 comments on commit f7b76fa

Please sign in to comment.