diff --git a/spec/std/fiber/execution_context/global_queue_spec.cr b/spec/std/fiber/execution_context/global_queue_spec.cr index b6b866b79e88..cc409c45efc6 100644 --- a/spec/std/fiber/execution_context/global_queue_spec.cr +++ b/spec/std/fiber/execution_context/global_queue_spec.cr @@ -107,7 +107,7 @@ describe Fiber::ExecutionContext::GlobalQueue do loop do if fiber = queue.pop? - fc = fibers.find { |x| x.@fiber == fiber }.not_nil! + fc = fibers.find! { |x| x.@fiber == fiber } queue.push(fiber) if fc.increment < increments slept = 0 elsif slept < 100 @@ -163,7 +163,7 @@ describe Fiber::ExecutionContext::GlobalQueue do } execute = ->(fiber : Fiber) { - fc = fibers.find { |x| x.@fiber == fiber }.not_nil! + fc = fibers.find! { |x| x.@fiber == fiber } if fc.increment < increments batch.push(fc.@fiber) diff --git a/spec/std/fiber/execution_context/runnables_spec.cr b/spec/std/fiber/execution_context/runnables_spec.cr index 0df82f3f5bda..3930bf2f07a6 100644 --- a/spec/std/fiber/execution_context/runnables_spec.cr +++ b/spec/std/fiber/execution_context/runnables_spec.cr @@ -202,7 +202,7 @@ describe Fiber::ExecutionContext::Runnables do slept = 0 execute = ->(fiber : Fiber) { - fc = fibers.find { |x| x.@fiber == fiber }.not_nil! + fc = fibers.find! { |x| x.@fiber == fiber } runnables.push(fiber) if fc.increment < increments } diff --git a/spec/std/regex_spec.cr b/spec/std/regex_spec.cr index 230976d6ad3e..b2220959fdb4 100644 --- a/spec/std/regex_spec.cr +++ b/spec/std/regex_spec.cr @@ -547,8 +547,8 @@ describe "Regex" do describe ".union" do it "constructs a Regex that matches things any of its arguments match" do re = Regex.union(/skiing/i, "sledding") - re.match("Skiing").not_nil![0].should eq "Skiing" - re.match("sledding").not_nil![0].should eq "sledding" + re.match!("Skiing")[0].should eq "Skiing" + re.match!("sledding")[0].should eq "sledding" end it "returns a regular expression that will match passed arguments" do diff --git a/spec/std/string_spec.cr b/spec/std/string_spec.cr index 2bd5574dbc2a..a80ed3a50bfe 100644 --- a/spec/std/string_spec.cr +++ b/spec/std/string_spec.cr @@ -2417,18 +2417,26 @@ describe "String" do end end - it "has match" do - "FooBar".match(/oo/).not_nil![0].should eq("oo") - end + describe "#match" do + it "has match" do + match = "FooBar".match(/oo/).should_not be_nil + match[0].should eq("oo") + end - it "matches with position" do - "こんにちは".match(/./, 1).not_nil![0].should eq("ん") - end + it "matches with position" do + match = "こんにちは".match(/./, 1).should_not be_nil + match[0].should eq("ん") + end - it "matches empty string" do - match = "".match(/.*/).not_nil! - match.group_size.should eq(0) - match[0].should eq("") + it "matches empty string" do + match = "".match(/.*/).should_not be_nil + match.group_size.should eq(0) + match[0].should eq("") + end + + it "returns nil" do + "foo".match(/bar/).should be_nil + end end it "matches, but returns Bool" do diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index cebd5d222a5c..0d275fe796a0 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -699,7 +699,7 @@ module Crystal if @progress_tracker.stats? if result["reused"].as_bool name = result["name"].as_s - unit = units.find { |unit| unit.name == name }.not_nil! + unit = units.find! { |unit| unit.name == name } unit.reused_previous_compilation = true end end diff --git a/src/compiler/crystal/crystal_path.cr b/src/compiler/crystal/crystal_path.cr index e957a513a714..dbee841e9268 100644 --- a/src/compiler/crystal/crystal_path.cr +++ b/src/compiler/crystal/crystal_path.cr @@ -106,7 +106,7 @@ module Crystal # Check if it's a wildcard. if filename.ends_with?("/*") || (recursive = filename.ends_with?("/**")) - filename_dir_index = filename.rindex('/').not_nil! + filename_dir_index = filename.rindex!('/') filename_dir = filename[0..filename_dir_index] relative_dir = "#{relative_to}/#{filename_dir}" if File.exists?(relative_dir) diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index dcd7be66df08..2070327e4f90 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -5111,7 +5111,7 @@ module Crystal next if doc_comment.start_line > doc_comment.end_line first_line = lines[doc_comment.start_line] - sharp_index = first_line.index('#').not_nil! + sharp_index = first_line.index!('#') comment = String.build do |str| (doc_comment.start_line..doc_comment.end_line).each do |i| diff --git a/src/compiler/crystal/tools/playground/server.cr b/src/compiler/crystal/tools/playground/server.cr index 1729bd7a98b3..8d36d486c40e 100644 --- a/src/compiler/crystal/tools/playground/server.cr +++ b/src/compiler/crystal/tools/playground/server.cr @@ -453,7 +453,7 @@ module Crystal::Playground public_dir = File.join(playground_dir, "public") agent_ws = PathWebSocketHandler.new "/agent" do |ws, context| - match_data = context.request.path.not_nil!.match(/\/(\d+)\/(\d+)$/).not_nil! + match_data = context.request.path.not_nil!.match!(/\/(\d+)\/(\d+)$/) session_key = match_data[1].to_i tag = match_data[2].to_i Log.info { "#{context.request.path} WebSocket connected (session=#{session_key}, tag=#{tag})" }