From 40873ba64f9863f95cea4e69e7bb855b6100c6ec Mon Sep 17 00:00:00 2001 From: nick evans Date: Fri, 8 Nov 2024 15:29:04 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20SequenceSet.try=5Fconvert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's a silly mistake, but it had no test coverage. I'm sure I did have this working at one point, but no test coverage! --- lib/net/imap/sequence_set.rb | 2 +- test/net/imap/test_sequence_set.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/net/imap/sequence_set.rb b/lib/net/imap/sequence_set.rb index f5da7b24..74a1d9ea 100644 --- a/lib/net/imap/sequence_set.rb +++ b/lib/net/imap/sequence_set.rb @@ -320,7 +320,7 @@ def [](first, *rest) # raised. def try_convert(obj) return obj if obj.is_a?(SequenceSet) - return nil unless respond_to?(:to_sequence_set) + return nil unless obj.respond_to?(:to_sequence_set) obj = obj.to_sequence_set return obj if obj.is_a?(SequenceSet) raise DataFormatError, "invalid object returned from to_sequence_set" diff --git a/test/net/imap/test_sequence_set.rb b/test/net/imap/test_sequence_set.rb index 3949c7f3..85204b24 100644 --- a/test/net/imap/test_sequence_set.rb +++ b/test/net/imap/test_sequence_set.rb @@ -151,6 +151,22 @@ def compare_to_reference_set(nums, set, seqset) assert_raise DataFormatError do SequenceSet[Set.new] end end + test ".try_convert" do + assert_nil SequenceSet.try_convert(nil) + assert_nil SequenceSet.try_convert(123) + assert_nil SequenceSet.try_convert(12..34) + assert_nil SequenceSet.try_convert("12:34") + assert_nil SequenceSet.try_convert(Object.new) + + obj = Object.new + def obj.to_sequence_set; SequenceSet[192, 168, 1, 255] end + assert_equal SequenceSet[192, 168, 1, 255], SequenceSet.try_convert(obj) + + obj = Object.new + def obj.to_sequence_set; 192_168.001_255 end + assert_raise DataFormatError do SequenceSet.try_convert(obj) end + end + test "#[non-negative index]" do assert_nil SequenceSet.empty[0] assert_equal 1, SequenceSet[1..][0]