Skip to content

Commit 2f18444

Browse files
committed
Restore 100% test coverage.
1 parent 82ea2f1 commit 2f18444

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

lib/async/list.rb

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,34 @@ def empty?
137137
@size == 0
138138
end
139139

140-
def validate!(node = nil)
141-
previous = self
142-
current = @tail
143-
found = node.equal?(self)
140+
# def validate!(node = nil)
141+
# previous = self
142+
# current = @tail
143+
# found = node.equal?(self)
144144

145-
while true
146-
break if current.equal?(self)
145+
# while true
146+
# break if current.equal?(self)
147147

148-
if current.head != previous
149-
raise "Invalid previous linked list node!"
150-
end
148+
# if current.head != previous
149+
# raise "Invalid previous linked list node!"
150+
# end
151151

152-
if current.is_a?(List) and !current.equal?(self)
153-
raise "Invalid list in list node!"
154-
end
152+
# if current.is_a?(List) and !current.equal?(self)
153+
# raise "Invalid list in list node!"
154+
# end
155155

156-
if node
157-
found ||= current.equal?(node)
158-
end
156+
# if node
157+
# found ||= current.equal?(node)
158+
# end
159159

160-
previous = current
161-
current = current.tail
162-
end
160+
# previous = current
161+
# current = current.tail
162+
# end
163163

164-
if node and !found
165-
raise "Node not found in list!"
166-
end
167-
end
164+
# if node and !found
165+
# raise "Node not found in list!"
166+
# end
167+
# end
168168

169169
# Iterate over each node in the linked list. It is generally safe to remove the current node, any previous node or any future node during iteration.
170170
#
@@ -293,8 +293,6 @@ def each
293293
end
294294

295295
def self.each(list, &block)
296-
list.validate!
297-
298296
return if list.empty?
299297

300298
iterator = Iterator.new(list)

test/async/list.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def initialize(value)
2525
list.append(Item.new(3))
2626

2727
expect(list.each.map(&:value)).to be == [1, 2, 3]
28+
expect(list.to_a.map(&:value)).to be == [1, 2, 3]
2829
expect(list.to_s).to be =~ /size=3/
2930
end
3031

@@ -115,6 +116,19 @@ def initialize(value)
115116

116117
expect(enumerated).to be == nodes
117118
end
119+
120+
it "can get #first and #last while enumerating" do
121+
list.append(first = Item.new(1))
122+
list.append(last = Item.new(2))
123+
124+
list.each do |item|
125+
if item.equal?(last)
126+
# This ensures the last node in the list is an iterator:
127+
list.remove(last)
128+
expect(list.last).to be == first
129+
end
130+
end
131+
end
118132
end
119133

120134
with '#first' do

test/async/scheduler.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
require 'net/http'
1010

1111
describe Async::Scheduler do
12+
it "is supported" do
13+
expect(Async::Scheduler).to be(:supported?)
14+
end
15+
1216
describe 'Fiber.schedule' do
1317
it "can start child task" do
1418
fiber = nil

0 commit comments

Comments
 (0)