import Foundation
import Testing
@testable import Forji

struct MarkdownComponentsTests {

    @Test func repoRelativePathExtractsFilePath() {
        let url = URL(string: "https://forgejo.example.com/owner/repo/src/branch/main/path/to/file.swift")!
        #expect(repoRelativePath(from: url) == "path/to/file.swift")
    }

    @Test func repoRelativePathReturnsNilForBranchOnly() {
        // URL ends right after the ref — no file path follows
        let url = URL(string: "https://forgejo.example.com/owner/repo/src/branch/main")!
        #expect(repoRelativePath(from: url) == nil)
    }

    @Test func repoRelativePathReturnsNilForUnrelatedURL() {
        let url = URL(string: "https://example.com/some/other/page")!
        #expect(repoRelativePath(from: url) == nil)
    }

    @Test func repoRelativePathHandlesSubpath() {
        let url = URL(string: "https://example.com/forgejo/owner/repo/src/branch/main/README.md")!
        #expect(repoRelativePath(from: url) == "README.md")
    }

    @Test func repoRelativePathHandlesNestedFilePath() {
        let url = URL(string: "https://forgejo.example.com/owner/repo/src/branch/feature/a/b/c.txt")!
        #expect(repoRelativePath(from: url) == "a/b/c.txt")
    }
}
