File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,16 @@ def to_s
2424 def inspect
2525 "#<#{ self } >"
2626 end
27+
28+ def hash
29+ @value . hash
30+ end
31+
32+ def ==( other )
33+ other . is_a? ( Sensitive ) &&
34+ other . hash == hash
35+ end
36+ alias eql? ==
2737 end
2838
2939 def self . register_ptype ( loader , ir )
Original file line number Diff line number Diff line change @@ -113,6 +113,24 @@ module Types
113113 expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'Sensitive[Integer] != Sensitive[String]' ] )
114114 end
115115
116+ it 'equals another instance with the same value' do
117+ code = <<-CODE
118+ $i = Sensitive('secret')
119+ $o = Sensitive('secret')
120+ notice($i == $o)
121+ CODE
122+ expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'true' ] )
123+ end
124+
125+ it 'has equal hash keys for same values' do
126+ code = <<-CODE
127+ $i = Sensitive('secret')
128+ $o = Sensitive('secret')
129+ notice({$i => 1} == {$o => 1})
130+ CODE
131+ expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'true' ] )
132+ end
133+
116134 it 'can be created from another sensitive instance ' do
117135 code = <<-CODE
118136 $o = Sensitive("hunter2")
You can’t perform that action at this time.
0 commit comments