import { describe, expect, it } from "vitest"
import { parseAttrs } from "./attributes"

describe("parseAttrs", () => {
  it("parses a key-value attribute", () => {
    expect(parseAttrs('{type="TODO"}')).toEqual({ type: "TODO" })
  })

  it("parses multiple key-value attributes", () => {
    expect(parseAttrs('{key="val" color="red"}')).toEqual({ key: "val", color: "red" })
  })

  it("parses a boolean flag", () => {
    expect(parseAttrs("{disabled}")).toEqual({ disabled: true })
  })

  it("parses a class", () => {
    expect(parseAttrs("{.highlight}")).toEqual({ class: "highlight" })
  })

  it("parses multiple classes", () => {
    expect(parseAttrs("{.class-one .class-two}")).toEqual({
      class: "class-one class-two",
    })
  })

  it("parses an id", () => {
    expect(parseAttrs("{#my-id}")).toEqual({ id: "my-id" })
  })

  it("parses mixed attributes", () => {
    const result = parseAttrs('{key="val" .highlight #my-id boolflag}')
    expect(result).toEqual({
      key: "val",
      class: "highlight",
      id: "my-id",
      boolflag: true,
    })
  })

  it("handles empty attrs", () => {
    expect(parseAttrs("{}")).toEqual({})
  })

  it("handles empty input", () => {
    expect(parseAttrs("")).toEqual({})
  })

  it("handles hyphenated keys", () => {
    expect(parseAttrs('{data-value="test"}')).toEqual({ "data-value": "test" })
  })

  it("parses value with colon prefix (JSON-bound)", () => {
    expect(parseAttrs('{:count="5"}')).toEqual({ ":count": "5" })
  })
})
