mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
parent
e4d4c0cec8
commit
7bb94d0692
3 changed files with 42 additions and 1 deletions
|
@ -81,12 +81,18 @@ module java::util::Collection
|
||||||
def compact
|
def compact
|
||||||
duped = Java::JavaUtil::ArrayList.new(self)
|
duped = Java::JavaUtil::ArrayList.new(self)
|
||||||
duped.compact!
|
duped.compact!
|
||||||
|
duped
|
||||||
end
|
end
|
||||||
|
|
||||||
def compact!
|
def compact!
|
||||||
|
size_before = self.size
|
||||||
self.removeAll(java::util::Collections.singleton(nil))
|
self.removeAll(java::util::Collections.singleton(nil))
|
||||||
|
if size_before == self.size
|
||||||
|
nil
|
||||||
|
else
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# support the Ruby intersection method on Java Collection
|
# support the Ruby intersection method on Java Collection
|
||||||
def &(other)
|
def &(other)
|
||||||
|
|
|
@ -29,6 +29,11 @@ namespace "test" do
|
||||||
exit(Spec::Core::Runner.run(["--fail-fast", Rake::FileList["spec/**/*_spec.rb"]]))
|
exit(Spec::Core::Runner.run(["--fail-fast", Rake::FileList["spec/**/*_spec.rb"]]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "run core specs on a single file"
|
||||||
|
task "core-single-file", [:specfile] => ["setup"] do |t,args|
|
||||||
|
exit(RSpec::Core::Runner.run([Rake::FileList[args.specfile]]))
|
||||||
|
end
|
||||||
|
|
||||||
desc "run all installed plugins specs"
|
desc "run all installed plugins specs"
|
||||||
task "plugins" => ["setup"] do
|
task "plugins" => ["setup"] do
|
||||||
# grab all spec files using the live plugins gem specs. this allows correclty also running the specs
|
# grab all spec files using the live plugins gem specs. this allows correclty also running the specs
|
||||||
|
|
|
@ -211,6 +211,36 @@ describe "Java integration" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when compacting" do
|
||||||
|
context "#compact with nils" do
|
||||||
|
let(:initial_array) { [1,2,3,nil,nil,6] }
|
||||||
|
it "should remove nil values from a copy" do
|
||||||
|
expect(subject.compact).to eq([1,2,3,6])
|
||||||
|
expect(subject).to eq([1,2,3,nil,nil,6])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#compact! with nils" do
|
||||||
|
let(:initial_array) { [1,2,3,nil,nil,6] }
|
||||||
|
it "should remove nil values" do
|
||||||
|
expect(subject.compact!).to eq([1,2,3,6])
|
||||||
|
expect(subject).to eq([1,2,3,6])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return the original" do
|
||||||
|
expect(subject.compact!.object_id).to eq(subject.object_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#compact! without nils" do
|
||||||
|
let(:initial_array) { [1,2,3,6] }
|
||||||
|
it "should return nil" do
|
||||||
|
expect(subject.compact!).to be nil
|
||||||
|
expect(subject).to eq([1,2,3,6])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Enumerable implementation" do
|
context "Enumerable implementation" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue