Class: TestRegexReplace
- Defined in:
- lib/regex_replace.rb
Instance Method Summary collapse
- #test_capture1 ⇒ Object
- #test_capture2 ⇒ Object
- #test_combination ⇒ Object
- #test_conditional ⇒ Object
- #test_conditional_with_alternative ⇒ Object
- #test_escape_characters ⇒ Object
- #test_full_match ⇒ Object
- #test_lonely_upcase ⇒ Object
- #test_simple ⇒ Object
- #test_simple_blank ⇒ Object
- #test_simple_global ⇒ Object
- #test_simple_single ⇒ Object
- #test_upcase_letter ⇒ Object
- #test_upcase_string ⇒ Object
Instance Method Details
#test_capture1 ⇒ Object
179 180 181 182 183 |
# File 'lib/regex_replace.rb', line 179 def test_capture1 rr = RegexReplace.new("bl(ackb)ird", "laura$1") assert_equal "foo lauraackb bar", rr.rep("foo blackbird bar") end |
#test_capture2 ⇒ Object
185 186 187 188 189 |
# File 'lib/regex_replace.rb', line 185 def test_capture2 rr = RegexReplace.new("bl(ackb)i(r)d", "$2laura$1") assert_equal "foo rlauraackb bar", rr.rep("foo blackbird bar") end |
#test_combination ⇒ Object
203 204 205 206 207 |
# File 'lib/regex_replace.rb', line 203 def test_combination rr = RegexReplace.new("bl(ackb)i(rd)", "\\l\\U$2\\Elaura$1") assert_equal "foo rDlauraackb bar", rr.rep("foo blackbird bar") end |
#test_conditional ⇒ Object
209 210 211 212 213 |
# File 'lib/regex_replace.rb', line 209 def test_conditional rr = RegexReplace.new("(\\w+)|(\\W+)", "(?1:\\L$1\\E)(?2:\\(_)") assert_equal "textmate(_power(_editing", rr.grep("TextMate: Power Editing") end |
#test_conditional_with_alternative ⇒ Object
215 216 217 218 219 |
# File 'lib/regex_replace.rb', line 215 def test_conditional_with_alternative rr = RegexReplace.new("[[:alpha:]]+|( )", "(?1:_:\\L$0)") assert_equal "textmate:_power_editing", rr.grep("TextMate: Power Editing") end |
#test_escape_characters ⇒ Object
160 161 162 163 164 165 |
# File 'lib/regex_replace.rb', line 160 def test_escape_characters rr = RegexReplace.new("blackbird", "lau\\nr\\ta") assert_equal "foo lau\nr\ta bar blackbird bar", rr.rep("foo blackbird bar blackbird bar") end |
#test_full_match ⇒ Object
167 168 169 170 171 |
# File 'lib/regex_replace.rb', line 167 def test_full_match rr = RegexReplace.new("bl(ackb)ird", "laura$0") assert_equal "foo laurablackbird bar", rr.rep("foo blackbird bar") end |
#test_lonely_upcase ⇒ Object
173 174 175 176 177 |
# File 'lib/regex_replace.rb', line 173 def test_lonely_upcase rr = RegexReplace.new("bl(ackb)ird", "\\u") assert_equal "foo bar", rr.rep("foo blackbird bar") end |
#test_simple ⇒ Object
136 137 138 139 140 |
# File 'lib/regex_replace.rb', line 136 def test_simple rr = RegexReplace.new("blackbird", "laura") assert_equal "foo laura bar", rr.rep("foo blackbird bar") end |
#test_simple_blank ⇒ Object
142 143 144 145 146 |
# File 'lib/regex_replace.rb', line 142 def test_simple_blank rr = RegexReplace.new("blackbird", "laura") assert_equal "", rr.rep("") end |
#test_simple_global ⇒ Object
148 149 150 151 152 |
# File 'lib/regex_replace.rb', line 148 def test_simple_global rr = RegexReplace.new("blackbird", "laura") assert_equal "foo laura bar laura bar", rr.grep("foo blackbird bar blackbird bar") end |
#test_simple_single ⇒ Object
154 155 156 157 158 |
# File 'lib/regex_replace.rb', line 154 def test_simple_single rr = RegexReplace.new("blackbird", "laura") assert_equal "foo laura bar blackbird bar", rr.rep("foo blackbird bar blackbird bar") end |
#test_upcase_letter ⇒ Object
197 198 199 200 201 |
# File 'lib/regex_replace.rb', line 197 def test_upcase_letter rr = RegexReplace.new("bl(ackb)i(rd)", "\\u$2laura$1") assert_equal "foo Rdlauraackb bar", rr.rep("foo blackbird bar") end |
#test_upcase_string ⇒ Object
191 192 193 194 195 |
# File 'lib/regex_replace.rb', line 191 def test_upcase_string rr = RegexReplace.new("bl(ackb)i(rd)", "\\U$2\\Elaura$1") assert_equal "foo RDlauraackb bar", rr.rep("foo blackbird bar") end |