import { shellQuote } from "../quote";

test("shellQuote should escape semicolon", () => {
  expect(shellQuote(";")).toBe("\\;");
});

test("shellQuote should return safe strings unchanged", () => {
  expect(shellQuote("hello")).toBe("hello");
  expect(shellQuote("test_123")).toBe("test_123");
  expect(shellQuote("path/to/file.txt")).toBe("path/to/file.txt");
  expect(shellQuote("user@domain.com")).toBe("user@domain.com");
  expect(shellQuote("key1=value1,key2=value2")).toBe("key1=value1,key2=value2");
});

test("shellQuote should handle key=value pattern", () => {
  expect(shellQuote("key=value with spaces")).toBe("key='value with spaces'");
  expect(shellQuote("database=my database")).toBe("database='my database'");
});

test("shellQuote should handle --key=value pattern", () => {
  expect(shellQuote("--verbose=true")).toBe("--verbose=true");
  expect(shellQuote("--database=my database")).toBe("--database='my database'");
});

test("shellQuote should quote strings with special characters", () => {
  expect(shellQuote("hello world")).toBe("'hello world'");
  expect(shellQuote("path with spaces")).toBe("'path with spaces'");
  expect(shellQuote("special!@#$%")).toBe("'special!@#$%'");
});

test("shellQuote should escape single quotes in quoted strings", () => {
  expect(shellQuote("don't")).toBe("'don'\\''t'");
  expect(shellQuote("it's a test")).toBe("'it'\\''s a test'");
  expect(shellQuote("'quoted'")).toBe("''\\''quoted'\\'''");
});

test("shellQuote should handle key=value with single quotes in value", () => {
  expect(shellQuote("name=John's file")).toBe("name='John'\\''s file'");
  expect(shellQuote("--title=Bob's Project")).toBe(
    "--title='Bob'\\''s Project'",
  );
});

test("shellQuote should handle empty string", () => {
  expect(shellQuote("")).toBe("''");
});
