define([
    'bitbucket/internal/util/highlight-text'
], function(
    highlightUtil
) {

    'use strict';

    var highlight = highlightUtil.highlight;

    function assertHighlight(sourceText, highlightText, expectedResult) {
        strictEqual(highlight(sourceText, highlightText), expectedResult);
    }

    module('util-highlight-text');

    test('No match', function() {
        assertHighlight('abcd', 'efg', 'abcd');
    });

    test('No highlight text', function() {
        assertHighlight('abcd', '', 'abcd');
        assertHighlight('abcd', [], 'abcd');
    });

    test('Highlight entire source text', function() {
        assertHighlight('abcd', 'abcd', '<mark>abcd</mark>');
    });

    test('Highlight multiple words', function() {
        assertHighlight('one two three', ['three', 'one', 'two'],
            '<mark>one</mark> <mark>two</mark> <mark>three</mark>');
    });

    test('Highlight partial words', function() {
        assertHighlight('one two three', 'wo thr', 'one t<mark>wo thr</mark>ee');
    });

    test('Matching is case insensitive', function() {
        assertHighlight('one TwO Three', 'two thrEE', 'one <mark>TwO Three</mark>');
    });

    test('Result is html-escaped', function() {
        assertHighlight('abc<&>123', '1', 'abc&lt;&amp;&gt;<mark>1</mark>23');
    });

    test('Result with no matches is html-escaped', function() {
        assertHighlight('<script>', '', '&lt;script&gt;');
        assertHighlight('<script>', 'not there', '&lt;script&gt;');
    });

    test('Highlight special html characters', function() {
        assertHighlight('abc<&>123', '&>1', 'abc&lt;<mark>&amp;&gt;1</mark>23');
    });

    test('Highlight special regexp characters', function() {
        assertHighlight('a/\\|()[]{}z', '/\\|()[]{}', 'a<mark>/\\|()[]{}</mark>z');
    });

    test('Highlight same word multiple times', function() {
        assertHighlight('abcabcZabc', 'abc',
            '<mark>abc</mark><mark>abc</mark>Z<mark>abc</mark>');
    });

    test('Overlapping matches', function() {
        assertHighlight('aaaaa', 'aa', '<mark>aa</mark><mark>aa</mark>a');
    });

    test('Custom options', function() {
        strictEqual(highlight('blAhBlahbLah', 'blah', 'i'), '<mark>blAh</mark>BlahbLah');
    });

});