Skip to content

Commit

Permalink
Playing around with Tryout formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed Jul 18, 2010
1 parent 1a3f6ee commit fa50d25
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 146 deletions.
4 changes: 2 additions & 2 deletions try/01_mixins_try.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'gibbler'

# TEST 1: has String#clear
"".respond_to? :clear
## has String#clear
"".respond_to? :clear
#=> true

10 changes: 4 additions & 6 deletions try/02_compat_try.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
require 'gibbler'

## Gibbler Objects have gibbler_cache method
"kimmy".respond_to? :gibbler_cache
"kimmy".respond_to? :gibbler_cache
#=> true


## Gibbler Objects have __gibbler_cache method
"kimmy".respond_to? :__gibbler_cache
"kimmy".respond_to? :__gibbler_cache
#=> true


## __gibbler_cache returns the same value as gibbler_cache
@a = "kimmy" and @a.gibbler
@a.gibbler_cache
@a = "kimmy" and @a.gibbler
@a.gibbler_cache
#=> @a.__gibbler_cache
22 changes: 11 additions & 11 deletions try/05_gibbler_digest_try.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
require 'gibbler'

## has short method
"kimmy".gibbler.short
"kimmy".gibbler.short
#=> Gibbler::Digest.new("c8027100")

# can Gibbler::Digest#short
Gibbler::Digest.new("1234567890").short
Gibbler::Digest.new("1234567890").short
#=> Gibbler::Digest.new("12345678")

# == is strict (only exact matches)
Gibbler::Digest.new("1234567890") == "12345678"
#=> false
Gibbler::Digest.new("1234567890") != "12345678"
#=> true

# === is relaxed (allows partial matches)
Gibbler::Digest.new("1234567890") === "12345678"
Gibbler::Digest.new("1234567890") === "12345678"
#=> true

# supports base36 output
Gibbler::Digest.new("1234567890").base36
Gibbler::Digest.new("1234567890").base36
#=> 'zx2tc40'

# base36 works on digests too
"kimmy".gibbler.base36
"kimmy".gibbler.base36
#=> 'nd2w8270caslmly0ix3s8ruh0y8yjdt'

# base36 digests can be short too
"kimmy".gibbler.base36.short
"kimmy".gibbler.base36.short
#=> 'nd2w8270'

# to_s returns a string and can accept a base
"kimmy".gibbler.to_s(16)
"kimmy".gibbler.to_s(16)
#=> "kimmy".gibbler.base(16).to_s

# base takes a base
"kimmy".gibbler.base(17)
"kimmy".gibbler.base(17)
#=> '12gaabd69eg5b32gf69a7a021c22g977d4gf46d6'

# to_s can take a base
"kimmy".gibbler.to_s(36)
"kimmy".gibbler.to_s(36)
#=> "kimmy".gibbler.base36
95 changes: 45 additions & 50 deletions try/10_basic_try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,96 @@
#Gibbler.enable_debug

# include Gibbler raises exception
begin
a = Class.new
a.send :include, Gibbler
rescue RuntimeError
:success
end
begin
a = Class.new
a.send :include, Gibbler
rescue RuntimeError
:success
end
#=> :success

# Symbol digests are consistent
:kimmy.gibbler
:kimmy.gibbler
#=> '52be7494a602d85ff5d8a8ab4ffe7f1b171587df'

# String digests are consistent
'kimmy'.gibbler
'kimmy'.gibbler
#=> 'c8027100ecc54945ab15ddac529230e38b1ba6a1'

# String and Symbol return different digests
:kimmy.gibbler != "kimmy".gibbler
:kimmy.gibbler != "kimmy".gibbler
#=> true

# Class digests are consistent
Class.gibbler
Class.gibbler
#=> '25ac269ae3ef18cdb4143ad02ca315afb5026de9'

# Fixnum instance digests are consistent
1.gibbler
1.gibbler
#=> 'a9cad665549bd22a4346fcf602d9d3c3b0482bbe'

# Bignum instance
100000000000.gibbler
100000000000.gibbler
#=> '608256db120251843843bba57e9b2c7adb7342aa'

# Empty Hash instance digests are consistent
Hash.new.gibbler
Hash.new.gibbler
#=> '4fdcadc66a38feb9c57faf3c5a18d5e76a6d29bf'

# Populated Hash instance
{ :a => [1,2,3, [4,5,6]], :b => { :c => Class } }.gibbler
{ :a => [1,2,3, [4,5,6]], :b => { :c => Class } }.gibbler
#=> "1d4b62e1e9f2c097b0cefb6877bf47c2015cdd21"

# Empty Array instance
Array.new.gibbler
Array.new.gibbler
#=> '48fda57c05684c9e5c3259557851943572183a21'

# Populated Array instance
[1, 2, :runtime, [3, "four", [Object, true]]].gibbler
[1, 2, :runtime, [3, "four", [Object, true]]].gibbler
#=> "3e1d79d113a409a96a13ca3879fc4c42027aa74b"

# Knows when a Hash has not changed
a = { :magic => true }
a.gibbler
a[:magic] = true
a.gibbled?
a = { :magic => true }
a.gibbler
a[:magic] = true
a.gibbled?
# => false

# Knows when a Hash has changed
a = { :magic => true }
a.gibbler
a[:magic] = false
a.gibbled?
a = { :magic => true }
a.gibbler
a[:magic] = false
a.gibbled?
#=> true

# Two Symbol digests don't cross streams
a, b = :something, :anything
a.gibbler
b.gibbler
[a.gibbler_cache.short, b.gibbler_cache.short]
a, b = :something, :anything
a.gibbler
b.gibbler
[a.gibbler_cache.short, b.gibbler_cache.short]
#=> ["667ce086", "92d5f7cd"]

# Two String digests don't cross streams" do
a, b = 'something', 'anything'
a.gibbler
b.gibbler
[a.gibbler_cache.short, b.gibbler_cache.short]
# Two String digests don't cross streams"
a, b = 'something', 'anything'
a.gibbler
b.gibbler
[a.gibbler_cache.short, b.gibbler_cache.short]
#=> ["ce0c7694", "c13b2f02"]

## DISABLED: If gibbler/history is required, there will be an
## additional attic_var (:gibbler_history), but only if the
## gibbler_history method has been called already (the history
## remains nil by default). The fix is not straightfroward and
## tests are not important anyway so disabling them is fine.
## Symbol has list of attic vars", [:gibbler_cache] do
## Symbol has list of attic vars", [:gibbler_cache]
# Symbol.attic_vars
#end
#
## String has list of attic vars", [:gibbler_cache] do
## String has list of attic vars", [:gibbler_cache]
# String.attic_vars
#end
#
## Hash has list of attic vars", [:gibbler_cache] do
## Hash has list of attic vars", [:gibbler_cache]
# Hash.attic_vars
#end

Expand All @@ -104,18 +104,18 @@
pre != post && post == a.gibbler_cache
#=> true

# works on arbitrary objects" do
class ::FullHouse
include Gibbler::Complex
attr_accessor :roles
end
a = FullHouse.new
a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
a.gibbler
# works on arbitrary objects"
class ::FullHouse
include Gibbler::Complex
attr_accessor :roles
end
a = FullHouse.new
a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
a.gibbler
#=> "fa5f741275b6b27932537e1946042b0286286e1d"

# TODO: Update for Attic 0.4
# doesn't reveal @__gibbler_digest__ instance variable", false do
# doesn't reveal @__gibbler_digest__ instance variable", false
a = {}
a.gibbler # We need to gibbler first so it sets a value to the instance var
val = RUBY_VERSION >= '1.9' ? :'@__gibbler_digest__' : '@__gibbler_digest__'
Expand All @@ -128,8 +128,3 @@ class ::FullHouse
a.gibbler_cache
#=> 'c8027100ecc54945ab15ddac529230e38b1ba6a1'






9 changes: 4 additions & 5 deletions try/11_basic_sha256_try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
end

## A Symbol can gibbler
:anything.gibbler
:anything.gibbler
#=> '754f87ca720ec256633a286d9270d68478850b2abd7b0ae65021cb769ae70c08'

## Class can gibbler
Class.gibbler
Class.gibbler
#=> 'd345c0afb4e8da0133a3946d3bd9b2622b0acdd8d6cc1237470cc637a9e4777f'

## TrueClass can gibbler
TrueClass.gibbler
TrueClass.gibbler
#=> 'b7b874a9bff7825caa57750a900652354ac601b77497b694d313f658c69d25b4'

# Empty Hash instance
{}.gibbler
{}.gibbler
#=> '88d2bcbd68ce593fd2e0e06f276f7301357516291b95c0c53038e61a9bf091e5'


Gibbler.digest_type = Digest::SHA1

6 changes: 3 additions & 3 deletions try/15_file_try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@tempfile = "tryouts-9000-awesome.txt"

# File can gibbler
## File can gibbler
file = File.new(File.join('.', 'CHANGES.txt'))
file.gibbler
#=> 'c052e87bd0acb7e08c98dad7f8b09b4382a08ef6'
Expand All @@ -22,8 +22,8 @@


# TempFile digests change
Tempfile.new('gibbler').gibbler == Tempfile.new('gibbler').gibbler
#=> false
Tempfile.new('gibbler').gibbler != Tempfile.new('gibbler').gibbler
#=> true


# File doesn't care about file contents
Expand Down
10 changes: 5 additions & 5 deletions try/16_uri_try.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
require 'uri'
require 'gibbler'

# "URI::HTTP can gibbler" do
# "URI::HTTP can gibbler"
uri = URI.parse "http://localhost:3114/spaceship"
uri.gibbler
#=> "9efe60a5db66aecf9b5fb8655b0bab0fcc7bd0c5"


# "URI::HTTPS can gibbler" do
# "URI::HTTPS can gibbler"
uri = URI.parse "https://localhost:3114/spaceship"
uri.gibbler
#=> "b75d3c34e60d6feafa796ddbb51e45710f6b106d"


# "URI::HTTP is trailing slash sensitive" do
# "URI::HTTP is trailing slash sensitive"
uri = URI.parse "http://localhost:3114/spaceship/"
uri.gibbler
#=> "191b0072b95ca0c79ed75e6deb5b28562dd9e5b9"


# "URI::Generic can gibbler" do
# "URI::Generic can gibbler"
uri = URI.parse "localhost:3114/spaceship"
uri.gibbler
#=> "d378372934326947113489d1f36f4853bef90a65"


# "URI::FTP can gibbler" do
# "URI::FTP can gibbler"
uri = URI.parse "ftp://localhost:3114/spaceship"
uri.gibbler
#=> "9d0543b31afebac9e8d38c56a0cf12070779f790"
Expand Down
14 changes: 7 additions & 7 deletions try/51_hash_history_try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ class ::Hash
a.gibbler_commit
#=> 'd7049916ddb25e6cc438b1028fb957e5139f9910'

# "return a Hash history" do
# "return a Hash history"
a = { :magic => :original }
a.gibbler_commit
a[:magic] = :updated
a.gibbler_commit
a.gibbler_history
#=> ['d7049916ddb25e6cc438b1028fb957e5139f9910', 'b668098e16d08898532bf3aa33ce2253a3a4150e']

# "can revert Hash" do
# "can revert Hash"
a = { :magic => :original }
a.gibbler_commit
a[:magic] = :updated
a.gibbler_revert!
#=> 'd7049916ddb25e6cc438b1028fb957e5139f9910'

# "knows a valid gibble", true do
# "knows a valid gibble"
a = { :magic => :original }
a.gibbler_commit
a.gibbler_valid? 'd7049916ddb25e6cc438b1028fb957e5139f9910'
#=> true

# "knows an invalid gibble", false do
# "knows an invalid gibble"
a = { :magic => :original }
a.gibbler_commit
a.gibbler_valid? '2222222222222222222222222222222222222222'
#=> false

# "can revert to any valid gibble" do
# "can revert to any valid gibble"
a = { :magic => :original }
a.gibbler_commit
a[:magic] = :updated
Expand All @@ -56,14 +56,14 @@ class ::Hash
#=> Hash[:magic => :original]


# "revert does nothing if digest is the same as current one" do
# "revert does nothing if digest is the same as current one"
a = { :magic => :original }
a.gibbler_commit
a.gibbler_revert!
a
#=> Hash[:magic => :original]

# "can revert using short gibbler_commit
# "can revert using short gibbler_commit"
a = { :magic => :original }
a.gibbler_commit
a[:magic] = :updated
Expand Down
Loading

0 comments on commit fa50d25

Please sign in to comment.