diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py
index 6c3ac8664..3184994a0 100644
--- a/openlp/core/lib/__init__.py
+++ b/openlp/core/lib/__init__.py
@@ -470,6 +470,7 @@ def find_formatting_tags(text, active_formatting_tags):
start_tag = True
if char == '/':
start_tag = False
+ char = next(word_it)
while char != '}':
tag += char
char = next(word_it)
@@ -479,10 +480,12 @@ def find_formatting_tags(text, active_formatting_tags):
if formatting_tag['end tag']:
if start_tag:
# prepend the new tag to the list of active formatting tags
- active_formatting_tags[:0] = tag
+ active_formatting_tags[:0] = [tag]
else:
# remove the tag from the list
active_formatting_tags.remove(tag)
+ # Break out of the loop matching the found tag against the tag list.
+ break
return active_formatting_tags
diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py
index 8eabd252a..ad00f5521 100644
--- a/tests/functional/openlp_core_lib/test_lib.py
+++ b/tests/functional/openlp_core_lib/test_lib.py
@@ -29,8 +29,10 @@ from datetime import datetime, timedelta
from PyQt5 import QtCore, QtGui
+from openlp.core.lib import FormattingTags
from openlp.core.lib import build_icon, check_item_selected, clean_tags, create_thumb, create_separated_list, \
- expand_tags, get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb, expand_chords
+ expand_tags, get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb, expand_chords, \
+ compare_chord_lyric, find_formatting_tags
from tests.functional import MagicMock, patch
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
@@ -762,3 +764,46 @@ class TestLib(TestCase):
'alleluya.F' \
' G'
self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!')
+
+ def test_compare_chord_lyric_short_chord(self):
+ """
+ Test that the chord/lyric comparing works.
+ """
+ # GIVEN: A chord and some lyric
+ chord = 'C'
+ lyrics = 'alleluya'
+
+ # WHEN: Comparing the chord and lyrics
+ ret = compare_chord_lyric(chord, lyrics)
+
+ # THEN: The returned value should 0 because the lyric is longer than the chord
+ self.assertEquals(0, ret, 'The returned value should 0 because the lyric is longer than the chord')
+
+ def test_compare_chord_lyric_long_chord(self):
+ """
+ Test that the chord/lyric comparing works.
+ """
+ # GIVEN: A chord and some lyric
+ chord = 'Gsus'
+ lyrics = 'me'
+
+ # WHEN: Comparing the chord and lyrics
+ ret = compare_chord_lyric(chord, lyrics)
+
+ # THEN: The returned value should 4 because the chord is longer than the lyric
+ self.assertEquals(4, ret, 'The returned value should 4 because the chord is longer than the lyric')
+
+ def test_find_formatting_tags(self):
+ """
+ Test that find_formatting_tags works as expected
+ """
+ # GIVEN: Lyrics with formatting tags and a empty list of formatting tags
+ lyrics = '{st}Amazing {r}grace{/r} how sweet the sound'
+ tags = []
+ FormattingTags.load_tags()
+
+ # WHEN: Detecting active formatting tags
+ active_tags = find_formatting_tags(lyrics, tags)
+
+ # THEN: The list of active tags should contain only 'st'
+ self.assertListEqual(['st'], active_tags, 'The list of active tags should contain only "st"')