1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
= FuzzyHash
Should accept strings and retrieve based on them.
l = FuzzyHash.new
l['asd'] = 'qwe'
l['asd'].should == 'qwe'
Should accept strings, but the second time you set the same string, it should overwrite.
l = FuzzyHash.new
l['asd'] = 'asd'
l['asd'] = 'qwe'
l['asd'].should == 'qwe'
Should accept regexs too.
l = FuzzyHash.new
l[/asd.*/] = 'qwe'
l['asdqweasd'].should == 'qwe'
Should accept regexs too, but the second time you set the same regex, it should overwrite.
l = FuzzyHash.new
l[/asd/] = 'asd'
l[/asd/] = 'qwe'
l['asdqweasd'].should == 'qwe'
Should accept regexs too with the match.
l = FuzzyHash.new
l[/asd.*/] = 'qwe'
l.match_with_result('asdqweasd').should == ['qwe', 'asdqweasd']
Should accept regexs that match the whole strong too with the match.
l = FuzzyHash.new
l[/asd/] = 'qwe'
l.match_with_result('asd').should == ['qwe', 'asd']
Should prefer string to regex matches.
l = FuzzyHash.new
l['asd'] = 'qwe2'
l[/asd.*/] = 'qwe'
l['asd'].should == 'qwe2'
Should allow nil keys.
l = FuzzyHash.new
l[nil] = 'qwe2'
l['asd'] = 'qwe'
l['asd'].should == 'qwe'
l[nil].should == 'qwe2'
Should allow boolean keys.
l = FuzzyHash.new
l[false] = 'false'
l[true] = 'true'
l[/.*/] = 'everything else'
l[true].should == 'true'
l[false].should == 'false'
l['false'].should == 'everything else'
Should pick between the correct regex.
hash = FuzzyHash.new
hash[/^\d+$/] = 'number'
hash[/.*/] = 'something'
hash['123asd'].should == 'something'
Should be able to delete by value for hash.
l = FuzzyHash.new
l[nil] = 'qwe2'
l['asd'] = 'qwe'
l['asd'].should == 'qwe'
l[nil].should == 'qwe2'
l.delete_value('qwe2')
l[nil].should == nil
Should be able to delete by value for regex.
l = FuzzyHash.new
l[/qwe.*/] = 'qwe2'
l['asd'] = 'qwe'
l['asd'].should == 'qwe'
l['qweasd'].should == 'qwe2'
l.delete_value('qwe2')
l['qweasd'].should == nil
Should iterate through the keys.
l = FuzzyHash.new
l[/qwe.*/] = 'qwe2'
l['asd'] = 'qwe'
l['zxc'] = 'qwe'
l.keys.size.should == 3
Should iterate through the values.
l = FuzzyHash.new
l[/qwe.*/] = 'qwe2'
l['asd'] = 'qwe'
l['zxc'] = 'qwelkj'
(['qwe2','qwe','qwelkj'] & l.values).size.should == 3
Should clear.
l = FuzzyHash.new
l[/qwe.*/] = 'qwe2'
l['asd'] = 'qwe'
l['zxc'] = 'qwelkj'
l.clear
l.empty?.should == true
Should handle equality.
l_1 = FuzzyHash.new
l_1[/qwe.*/] = 'qwe2'
l_1['asd'] = 'qwelkj'
l_1['zxc'] = 'qwe'
l_2 = FuzzyHash.new
l_2['zxc'] = 'qwe'
l_2['asd'] = 'qwelkj'
l_2[/qwe.*/] = 'qwe2'
l_1.should == l_2
Should return the value when adding the value.
h = FuzzyHash.new
(h[/asd/] = '123').should == '123'
(h['qwe'] = '123').should == '123'
That's It.
|