package com.correx.apps.server.tasks

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class GitCommandCommitReaderTest {

    private val us = ""
    private val rs = ""

    @Test
    fun `parseGitLog splits records and sha from message`() {
        val raw = "abc123${us}fix auth-1: rotate$rs\ndef456${us}wip on auth-2$rs\n"

        val commits = parseGitLog(raw)

        assertEquals(2, commits.size)
        assertEquals("abc123", commits[0].sha)
        assertEquals("fix auth-1: rotate", commits[0].message)
        assertEquals("def456", commits[1].sha)
        assertEquals("wip on auth-2", commits[1].message)
    }

    @Test
    fun `parseGitLog tolerates blank output and malformed records`() {
        assertTrue(parseGitLog("").isEmpty())
        assertTrue(parseGitLog("no-separator-here$rs").isEmpty())
    }
}
