|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { dedupFlags } from "./flags.js"; |
| 3 | + |
| 4 | +describe("dedupFlags", () => { |
| 5 | + it("should keep single flags unchanged", () => { |
| 6 | + expect(dedupFlags("--verbose")).toBe("--verbose"); |
| 7 | + expect(dedupFlags("-v")).toBe("-v"); |
| 8 | + expect(dedupFlags("--debug=true")).toBe("--debug=true"); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should preserve multiple different flags", () => { |
| 12 | + expect(dedupFlags("--quiet --verbose")).toBe("--quiet --verbose"); |
| 13 | + expect(dedupFlags("-v -q --log=debug")).toBe("-v -q --log=debug"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should use last value when flags are duplicated", () => { |
| 17 | + expect(dedupFlags("--debug=false --debug=true")).toBe("--debug=true"); |
| 18 | + expect(dedupFlags("--log=info --log=warn --log=error")).toBe("--log=error"); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should handle mix of flags with and without values", () => { |
| 22 | + expect(dedupFlags("--debug=false -v --debug=true")).toBe("-v --debug=true"); |
| 23 | + expect(dedupFlags("-v --quiet -v")).toBe("--quiet -v"); |
| 24 | + }); |
| 25 | + |
| 26 | + // Edge cases |
| 27 | + it("should handle empty string", () => { |
| 28 | + expect(dedupFlags("")).toBe(""); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should handle multiple spaces between flags", () => { |
| 32 | + expect(dedupFlags("--debug=false --verbose --debug=true")).toBe("--verbose --debug=true"); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should handle flags with empty values", () => { |
| 36 | + expect(dedupFlags("--path= --path=foo")).toBe("--path=foo"); |
| 37 | + expect(dedupFlags("--path=foo --path=")).toBe("--path="); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should preserve values containing equals signs", () => { |
| 41 | + expect(dedupFlags("--url=http://example.com?foo=bar")).toBe("--url=http://example.com?foo=bar"); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should handle flags with special characters", () => { |
| 45 | + expect(dedupFlags("--path=/usr/local --path=/home/user")).toBe("--path=/home/user"); |
| 46 | + expect(dedupFlags('--name="John Doe" --name="Jane Doe"')).toBe('--name="Jane Doe"'); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should handle multiple flag variants", () => { |
| 50 | + const input = "--env=dev -v --env=prod --quiet -v --env=staging"; |
| 51 | + expect(dedupFlags(input)).toBe("--quiet -v --env=staging"); |
| 52 | + }); |
| 53 | +}); |
0 commit comments