package ca.ksamad.encore.mpd

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

class MpdProtocolTest {
    @Test
    fun quote_wrapsPlainArg() {
        assertEquals("\"hello\"", MpdProtocol.quote("hello"))
    }

    @Test
    fun quote_escapesQuotesAndBackslashes() {
        // Input: he"llo\world  ->  "he\"llo\\world"
        assertEquals("\"he\\\"llo\\\\world\"", MpdProtocol.quote("he\"llo\\world"))
    }

    @Test
    fun quote_handlesEmptyString() {
        assertEquals("\"\"", MpdProtocol.quote(""))
    }

    @Test
    fun command_noArgsIsBareName() {
        assertEquals("status", MpdProtocol.command("status"))
    }

    @Test
    fun command_quotesEachArg() {
        assertEquals(
            "find \"Artist\" \"Nine Inch Nails\"",
            MpdProtocol.command("find", "Artist", "Nine Inch Nails"),
        )
    }

    @Test
    fun commands_builderProducesExpectedWireForm() {
        assertEquals("setvol \"75\"", MpdCommands.setVolume(75))
        assertEquals("pause \"1\"", MpdCommands.pause(true))
        assertEquals("playid \"42\"", MpdCommands.playId(42))
        assertEquals("idle", MpdCommands.idle())
        assertEquals("idle \"player\" \"mixer\"", MpdCommands.idle("player", "mixer"))
    }

    @Test
    fun setVolume_clampsToValidRange() {
        assertEquals("setvol \"100\"", MpdCommands.setVolume(150))
        assertEquals("setvol \"0\"", MpdCommands.setVolume(-5))
    }
}
