import { describe, expect, it } from 'vitest'
import { validate } from '../validate.js'

const ok = (type: string, name: string) => validate({ type, name }).valid

describe('start validate — release/hotfix names must be semver (Model B)', () => {
  it('accepts a proper semver release', () => {
    expect(ok('release', '5.1.0')).toBe(true)
    expect(ok('hotfix', '5.0.1')).toBe(true)
  })

  it('tolerates a leading v and a pre-release suffix', () => {
    expect(ok('release', 'v5.1.0')).toBe(true)
    expect(ok('hotfix', '5.0.1-beta.1')).toBe(true)
  })

  it('rejects build-metadata (+) — not a valid branch-name character', () => {
    expect(ok('release', '5.1.0+build.7')).toBe(false)
  })

  it('rejects non-semver release/hotfix names', () => {
    expect(ok('release', 'my-release')).toBe(false)
    expect(ok('release', '5.1')).toBe(false)
    expect(ok('hotfix', '5')).toBe(false)
    const r = validate({ type: 'release', name: 'oops' })
    expect(r.blockers.some((b) => /semver/i.test(b))).toBe(true)
  })

  it('does NOT impose semver on feature names', () => {
    expect(ok('feature', 'add-login')).toBe(true)
    expect(ok('feature', 'whatever-name')).toBe(true)
  })

  it('still rejects empty names and invalid characters', () => {
    expect(ok('release', '')).toBe(false)
    expect(ok('feature', 'bad name!')).toBe(false) // space + ! caught by the char rule
  })
})
