import { describe, it, expect } from 'vitest';
import { deriveAppName } from './deriveAppName';

describe('deriveAppName', () => {
  it('truncates at first digit', () => {
    expect(deriveAppName('payment-gateway-1.2.0.jar')).toBe('Payment Gateway');
  });

  it('returns clean title-cased name without digits', () => {
    expect(deriveAppName('order-service.jar')).toBe('Order Service');
  });

  it('strips orphan 1-char token after truncation (v from my-app-v2)', () => {
    expect(deriveAppName('my-app-v2.jar')).toBe('My App');
  });

  it('treats underscore like dash', () => {
    expect(deriveAppName('acme_billing-3.jar')).toBe('Acme Billing');
  });

  it('strips the .jar extension when no digits present', () => {
    expect(deriveAppName('acme-billing.jar')).toBe('Acme Billing');
  });

  it('returns empty string for empty input', () => {
    expect(deriveAppName('')).toBe('');
  });

  it('returns empty string when filename starts with a digit', () => {
    expect(deriveAppName('1-my-thing.jar')).toBe('');
  });

  it('mixed separators are both collapsed to spaces', () => {
    expect(deriveAppName('foo_bar-baz.jar')).toBe('Foo Bar Baz');
  });

  it('strips trailing orphan regardless of letter identity', () => {
    expect(deriveAppName('release-x9.jar')).toBe('Release');
  });
});
