From dcbc0fe7ad6b9a55986f003d25c0c0023228db0b Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 15 Sep 2026 10:13:19 +1200 Subject: [PATCH] Cover header quality comparisons. Assisted-By: devx/71d171da-b98c-42c2-922b-36328d89d0d6 --- test/protocol/http/header/accept.rb | 6 ++++++ test/protocol/http/header/accept_charset.rb | 6 ++++++ test/protocol/http/header/accept_encoding.rb | 6 ++++++ test/protocol/http/header/accept_language.rb | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/test/protocol/http/header/accept.rb b/test/protocol/http/header/accept.rb index d9f878e..d650b9f 100644 --- a/test/protocol/http/header/accept.rb +++ b/test/protocol/http/header/accept.rb @@ -11,6 +11,12 @@ expect(media_range.quality_factor).to be == 1.0 end + it "compares by quality factor" do + high = subject.new("text", "html", {"q" => "0.9"}) + low = subject.new("text", "plain", {"q" => "0.5"}) + expect(high <=> low).to be == -1 + end + with "#to_s" do it "can convert to string" do media_range = subject.new("text", "plain", {"q" => "0.5"}) diff --git a/test/protocol/http/header/accept_charset.rb b/test/protocol/http/header/accept_charset.rb index 839eb10..b89d8e1 100644 --- a/test/protocol/http/header/accept_charset.rb +++ b/test/protocol/http/header/accept_charset.rb @@ -10,6 +10,12 @@ charset = subject.new("utf-8", nil) expect(charset.quality_factor).to be == 1.0 end + + it "compares by quality factor" do + high = subject.new("utf-8", "0.9") + low = subject.new("iso-8859-1", "0.5") + expect(high <=> low).to be == -1 + end end describe Protocol::HTTP::Header::AcceptCharset do diff --git a/test/protocol/http/header/accept_encoding.rb b/test/protocol/http/header/accept_encoding.rb index 6269d56..836e569 100644 --- a/test/protocol/http/header/accept_encoding.rb +++ b/test/protocol/http/header/accept_encoding.rb @@ -10,6 +10,12 @@ encoding = subject.new("utf-8", nil) expect(encoding.quality_factor).to be == 1.0 end + + it "compares by quality factor" do + high = subject.new("gzip", "0.9") + low = subject.new("deflate", "0.5") + expect(high <=> low).to be == -1 + end end describe Protocol::HTTP::Header::AcceptEncoding do diff --git a/test/protocol/http/header/accept_language.rb b/test/protocol/http/header/accept_language.rb index cd657f6..6bb3e11 100644 --- a/test/protocol/http/header/accept_language.rb +++ b/test/protocol/http/header/accept_language.rb @@ -10,6 +10,12 @@ language = subject.new("utf-8", nil) expect(language.quality_factor).to be == 1.0 end + + it "compares by quality factor" do + high = subject.new("en", "0.9") + low = subject.new("fr", "0.5") + expect(high <=> low).to be == -1 + end end describe Protocol::HTTP::Header::AcceptLanguage do