test/convertor_test.rb in boogex-0.1.1 vs test/convertor_test.rb in boogex-0.1.2

- old
+ new

@@ -2,44 +2,67 @@ describe Boogex do it 'turns OR into |' do string = 'This OR That' expecting = '(?:This|That)' - result = Boogex.convert(string) + result = Boogex.convert(string)[:inclusive_regex] assert_equal expecting, result end it 'turns boolean AND into AND array string' do string = 'This AND That' expecting = "AND(['(?:This)','(?:That)'])" - result = Boogex.convert(string) + result = Boogex.convert(string)[:inclusive_regex] assert_equal expecting, result end it 'understands bracketing' do string = '(This OR That) AND My self' expecting = "AND(['(?:This|That)','(?:My self)'])" - result = Boogex.convert(string) + result = Boogex.convert(string)[:inclusive_regex] assert_equal expecting, result end it 'correctly convert this Lucene boolean query string' do string = '(((asd OR dd) AND that) AND this) OR What?' expecting = "AND([AND(['(?:asd|dd)','(?:that)']),'(?:this)'])|What?" - result = Boogex.convert(string) + result = Boogex.convert(string)[:inclusive_regex] assert_equal expecting, result end it 'understands embedded AND' do string = '((im AND researching) AND travelling)' expecting = "AND([AND(['(?:im)','(?:researching)']),'(?:travelling)'])" - result = Boogex.convert(string) + result = Boogex.convert(string)[:inclusive_regex] assert_equal expecting, result end it 'understands double embedded AND' do string = 'Peeps OR ((dude OR roos) AND (what OR Footy))' expecting = "Peeps|AND(['(?:dude|roos)','(?:what|Footy)'])" - result = Boogex.convert(string) + result = Boogex.convert(string)[:inclusive_regex] + assert_equal expecting, result + end + + it 'escapes hyphens' do + string = '("John Gordon-Smith" OR "hair") AND ("none" OR "all")' + expecting = "AND(['(?:John Gordon\\-Smith|hair)','(?:none|all)'])" + result = Boogex.convert(string)[:inclusive_regex] + assert_equal expecting, result + end + + it 'handles unclosed brackets' do + string = '("@AUSOlympicTeam" OR "Olympics") AND ("boxing" OR "@Shelley__watts"))' + + assert_raises do + result = Boogex.convert(string)[:inclusive_regex] + end + end + + it 'handles multiple brackets' do + string = '((@officialcsa OR "south africa" OR "south african") AND ("cricket" OR "proteas") AND ("national" OR "international") AND ("team"))' + expecting = "AND(['(?:@officialcsa|south africa|south african)','(?:cricket|proteas)','(?:national|international)','(?:team)'])" + + result = Boogex.convert(string)[:inclusive_regex] assert_equal expecting, result end end