Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/mcp/annotations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Annotations
attr_reader :audience, :priority, :last_modified

def initialize(audience: nil, priority: nil, last_modified: nil)
raise ArgumentError, "The value of priority must be between 0 and 1." if priority && !priority.between?(0, 1)

@audience = audience
@priority = priority
@last_modified = last_modified
Expand Down
26 changes: 26 additions & 0 deletions test/mcp/annotations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,31 @@ def test_initialization_with_last_modified_only

assert_equal({ lastModified: timestamp }, annotations.to_h)
end

def test_valid_priority_at_lower_bound
assert_nothing_raised do
Annotations.new(priority: 0)
end
end

def test_valid_priority_at_upper_bound
assert_nothing_raised do
Annotations.new(priority: 1)
end
end

def test_invalid_priority_above_upper_bound
exception = assert_raises(ArgumentError) do
Annotations.new(priority: 1.5)
end
assert_equal("The value of priority must be between 0 and 1.", exception.message)
end

def test_invalid_priority_below_lower_bound
exception = assert_raises(ArgumentError) do
Annotations.new(priority: -0.1)
end
assert_equal("The value of priority must be between 0 and 1.", exception.message)
end
end
end