package solutions.tretter.githugandroid

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class GitHelpCommandsTest {
    @Test
    fun parsesGitHelpCommand() {
        val invocation = parseGitHelpInvocation("git help tag")

        assertEquals("tag", invocation?.topic)
        assertEquals("git help tag", invocation?.command)
    }

    @Test
    fun parsesGitSubcommandShortHelpCommand() {
        assertNull(parseGitHelpInvocation("git tag -h"))
    }

    @Test
    fun parsesGitGlobalShortHelpCommand() {
        val invocation = parseGitHelpInvocation("git --help tag")

        assertEquals("tag", invocation?.topic)
        assertEquals("git --help tag", invocation?.command)
    }

    @Test
    fun parsesManGitCommand() {
        val invocation = parseGitHelpInvocation("man git-cherry-pick")

        assertEquals("cherry-pick", invocation?.topic)
        assertEquals("man git-cherry-pick", invocation?.command)
    }

    @Test
    fun parsesSplitManGitCommand() {
        val invocation = parseGitHelpInvocation("man git cherry-pick")

        assertEquals("cherry-pick", invocation?.topic)
        assertEquals("man git cherry-pick", invocation?.command)
    }

    @Test
    fun parsesMainGitManpageCommand() {
        val invocation = parseGitHelpInvocation("man git")

        assertEquals("git", invocation?.topic)
        assertEquals("man git", invocation?.command)
    }

    @Test
    fun rejectsUnsafeHelpTopic() {
        assertNull(parseGitHelpInvocation("git help ../config"))
    }
}
