package solutions.tretter.githugandroid

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

class GitEditorCommandsTest {
    @Test
    fun commitWithoutMessageOpensEditor() {
        val invocation = parseGitEditorInvocation("git commit")

        assertEquals(GitEditorCommandKind.COMMIT_MESSAGE, invocation?.kind)
        assertEquals("Edit Commit Message", invocation?.title)
    }

    @Test
    fun commitWithMessageDoesNotOpenEditor() {
        assertNull(parseGitEditorInvocation("git commit -m \"message\""))
    }

    @Test
    fun commitAllWithCombinedMessageOptionDoesNotOpenEditor() {
        assertNull(parseGitEditorInvocation("git commit -am \"message\""))
    }

    @Test
    fun amendNoEditDoesNotOpenEditor() {
        assertNull(parseGitEditorInvocation("git commit --amend --no-edit"))
    }

    @Test
    fun interactiveRebaseOpensTodoEditor() {
        val invocation = parseGitEditorInvocation("git rebase -i HEAD~3")

        assertEquals(GitEditorCommandKind.REBASE_TODO, invocation?.kind)
        assertEquals("Edit Rebase Todo", invocation?.title)
    }

    @Test
    fun bareInteractiveRebaseDoesNotOpenTodoEditor() {
        assertNull(parseGitEditorInvocation("git rebase -i"))
    }

    @Test
    fun annotatedTagWithoutMessageOpensEditor() {
        val invocation = parseGitEditorInvocation("git tag -a v1.0")

        assertEquals(GitEditorCommandKind.TAG_MESSAGE, invocation?.kind)
        assertEquals("Edit Tag Message", invocation?.title)
    }

    @Test
    fun lightweightTagDoesNotOpenEditor() {
        assertNull(parseGitEditorInvocation("git tag v1.0"))
    }
}
