package com.syncflow.data.providers.webdav

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

/**
 * Path-segment decoding must not apply the form-encoding `+` → space rule.
 * Regression coverage for the "6103+.pdf" file that 404'd forever.
 */
class WebDavDecodeTest {

    @Test fun `literal plus is preserved (the 6103 bug)`() =
        assertEquals("6103+.pdf", decodeWebDavSegment("6103+.pdf"))

    @Test fun `percent-encoded plus decodes to a plus`() =
        assertEquals("6103+.pdf", decodeWebDavSegment("6103%2B.pdf"))

    @Test fun `percent-twenty decodes to a space`() =
        assertEquals("my file.pdf", decodeWebDavSegment("my%20file.pdf"))

    @Test fun `space and plus stay distinct`() {
        assertEquals("a b", decodeWebDavSegment("a%20b"))   // %20 -> space
        assertEquals("a+b", decodeWebDavSegment("a+b"))     // literal + stays +, NOT space
    }

    @Test fun `utf8 percent sequences decode (persian)`() =
        assertEquals("عکس.jpg", decodeWebDavSegment("%D8%B9%DA%A9%D8%B3.jpg"))

    @Test fun `plain ascii passes through`() =
        assertEquals("photo.jpg", decodeWebDavSegment("photo.jpg"))

    @Test fun `trailing bare percent is left literal`() =
        assertEquals("50%", decodeWebDavSegment("50%"))
}
