Skip to content

Commit

Permalink
Fix bug with no matches and multiple test strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmagic committed Mar 2, 2012
1 parent d6bdd3e commit 6e1b88b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
34 changes: 17 additions & 17 deletions application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions scripts/application.coffee
Expand Up @@ -50,8 +50,9 @@ class Results

try
for value in @test_strings.values
@matchResults(value)
@matchGroups(value, count)
matches = value.match(@expression.value)
@matchResults(value, matches)
@matchGroups(value, matches, count)
count += 1
$('#intro').hide()
$('#error').hide()
Expand All @@ -61,11 +62,11 @@ class Results
$('#output').hide()
$('#error').show()

matchResults: (value) ->
console.log(value, value.match(@expression.value))
matchResults: (value, matches) ->
return unless matches
string = ''

for match in value.match(@expression.value)
for match in matches
index = value.indexOf(match)
length = match.length
string += value.slice(0, index)
Expand All @@ -74,14 +75,16 @@ class Results

$('ul#results').append("<li>#{string}</li>")

matchGroups: (value, count) ->
matchGroups: (value, matches, count) ->
return unless matches

$('ul#groups').append("<li id='match_#{count}'><h3>Match #{count}</h3><ol></ol></li>")

if @expression.option.val() == 'g'
for match in value.match(@expression.value)
for match in matches
$("ul#groups li#match_#{count} ol").append("<li>#{match}</li>")
else
for match in value.match(@expression.value)[1..-1]
for match in matches[1..-1]
$("ul#groups li#match_#{count} ol").append("<li>#{match}</li>")

class App
Expand Down

0 comments on commit 6e1b88b

Please sign in to comment.