package com.correx.core.tasks

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

class CommitTaskParserTest {

    @Test
    fun `closing keywords mark refs closing`() {
        val refs = CommitTaskParser.parse("Fixes auth-12 and resolves billing-3")
        assertEquals(setOf(CommitTaskRef("auth-12", true), CommitTaskRef("billing-3", true)), refs.toSet())
    }

    @Test
    fun `plain mentions are non-closing`() {
        assertEquals(listOf(CommitTaskRef("auth-12", false)), CommitTaskParser.parse("see auth-12 for context"))
    }

    @Test
    fun `the closing form wins over a later plain mention of the same key`() {
        assertEquals(listOf(CommitTaskRef("auth-1", true)), CommitTaskParser.parse("fix auth-1\n\nfollow-up to auth-1"))
    }

    @Test
    fun `a message with no keys yields empty`() {
        assertTrue(CommitTaskParser.parse("just a normal commit message").isEmpty())
    }
}
