Permalink
Browse files

Added put_url and put_jpeg_url

  • Loading branch information...
1 parent 7dd694a commit 34944430fd19f75d9443d6fd56a28e207aa238b0 @drbrain committed Mar 28, 2011
Showing with 60 additions and 0 deletions.
  1. +28 −0 lib/pasteboard.rb
  2. +32 −0 test/test_pasteboard.rb
View
@@ -205,6 +205,34 @@ def put *items
self
end
+ ##
+ # Adds +url+ to the pasteboard with an optional +url_name+.
+
+ def put_url url, url_name = url
+ item = [
+ [Pasteboard::Type::URL, url],
+ [Pasteboard::Type::URL_NAME, url_name],
+ [Pasteboard::Type::UTF_8, url],
+ ]
+
+ put item
+ end
+
+ ##
+ # Adds JPEG data +image+ to the pasteboard with a +url+ and optional
+ # +url_name+.
+
+ def put_jpeg_url image, url, url_name = url
+ item = [
+ [Pasteboard::Type::JPEG, image],
+ [Pasteboard::Type::URL, url],
+ [Pasteboard::Type::URL_NAME, url_name],
+ [Pasteboard::Type::UTF_8, url],
+ ]
+
+ put item
+ end
+
end
require 'pasteboard/type'
@@ -224,6 +224,27 @@ def test_put_item_flavor
assert_equal Encoding::BINARY, data.encoding if @encoding
end
+ def test_put_jpeg_url
+ @pb.put_jpeg_url 'JPEG data', 'http://example', 'my cool jpeg'
+
+ assert_put [
+ [Pasteboard::Type::JPEG, 'JPEG data'],
+ [Pasteboard::Type::URL, 'http://example'],
+ [Pasteboard::Type::URL_NAME, 'my cool jpeg'],
+ [Pasteboard::Type::UTF_8, 'http://example'],
+ ]
+ end
+
+ def test_put_url
+ @pb.put_url 'http://example', 'my cool jpeg'
+
+ assert_put [
+ [Pasteboard::Type::URL, 'http://example'],
+ [Pasteboard::Type::URL_NAME, 'my cool jpeg'],
+ [Pasteboard::Type::UTF_8, 'http://example'],
+ ]
+ end
+
def test_sync
assert_equal 0, @pb.sync
end
@@ -251,5 +272,16 @@ def util_put_many
@pb.put @item1, @item2
end
+ def assert_put *expecteds
+ assert_equal expecteds.length, @pb.get_item_count
+
+ expecteds.each do |expected|
+ expected.each_with_index do |(flavor, data), index|
+ assert_equal flavor, @pb.copy_item_flavors(0)[index]
+ assert_equal data, @pb.first(flavor)
+ end
+ end
+ end
+
end

0 comments on commit 3494443

Please sign in to comment.