package com.atlassian.stash.internal.web.soy.functions.nav;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class PreventDomainInferenceFunctionTest {

    private PreventDomainInferenceFunction function = new PreventDomainInferenceFunction();

    @Test
    public void shouldInsertSpanIfDotPresent() {
        assertEquals("example<span>.</span>bbc<span>.</span>co<span>.</span>uk", function.apply("example.bbc.co.uk").getValue());
    }

    @Test
    public void shouldNotInsertSpanIfSpaceIsBeforeOrAfterADot() {
        assertEquals("My .git file is awesome.  Really.", function.apply("My .git file is awesome.  Really.").getValue());
    }

    @Test
    public void shouldEscapeNormallyIfINestTheCall() {
        assertEquals("example&lt;span&gt;.&lt;/span&gt;com", function.apply("example<span>.</span>com").getValue());
    }

    @Test
    public void shouldSafelyEscapeSuspiciousFileNameAttempts() {
        assertEquals("ex&lt;script&gt;javascript: alert();&lt;/script&gt;ample<span>.</span>com", function.apply("ex<script>javascript: alert();</script>ample.com").getValue());
    }
}
