|
1 | 1 | import { expect, test, describe } from "vitest";
|
2 |
| -import { transformCommaSeperatedName } from "../../../src/common/utils.js"; |
| 2 | +import { transformCommaSeperatedName, transformSigLeadToURI } from "../../../src/common/utils.js"; |
3 | 3 |
|
4 | 4 | describe("Comma-seperated name transformer tests", () => {
|
5 | 5 | test("Already-transformed names are returned as-is", () => {
|
@@ -27,3 +27,146 @@ describe("Comma-seperated name transformer tests", () => {
|
27 | 27 | expect(output).toEqual(", Test");
|
28 | 28 | });
|
29 | 29 | });
|
| 30 | + |
| 31 | +describe("transformSigLeadToURI tests", () => { |
| 32 | + |
| 33 | + // Basic Functionality Tests |
| 34 | + test("should convert simple names with spaces to lowercase hyphenated", () => { |
| 35 | + const output = transformSigLeadToURI("SIG Network"); |
| 36 | + expect(output).toEqual("sig-network"); |
| 37 | + }); |
| 38 | + |
| 39 | + test("should convert simple names to lowercase", () => { |
| 40 | + const output = transformSigLeadToURI("Testing"); |
| 41 | + expect(output).toEqual("testing"); |
| 42 | + }); |
| 43 | + |
| 44 | + test("should handle names already in the desired format", () => { |
| 45 | + const output = transformSigLeadToURI("already-transformed-name"); |
| 46 | + expect(output).toEqual("already-transformed-name"); |
| 47 | + }); |
| 48 | + |
| 49 | + // Camel Case Tests |
| 50 | + test("should add hyphens between camelCase words", () => { |
| 51 | + const output = transformSigLeadToURI("SIGAuth"); |
| 52 | + expect(output).toEqual("sig-auth"); |
| 53 | + }); |
| 54 | + |
| 55 | + test("should handle multiple camelCase words", () => { |
| 56 | + const output = transformSigLeadToURI("SuperCamelCaseProject"); |
| 57 | + expect(output).toEqual("super-camel-case-project"); |
| 58 | + }); |
| 59 | + |
| 60 | + test("should handle mixed camelCase and spaces", () => { |
| 61 | + const output = transformSigLeadToURI("SIG ContribEx"); // SIG Contributor Experience |
| 62 | + expect(output).toEqual("sig-contrib-ex"); |
| 63 | + }); |
| 64 | + |
| 65 | + test("should handle camelCase starting with lowercase", () => { |
| 66 | + const output = transformSigLeadToURI("myCamelCaseName"); |
| 67 | + expect(output).toEqual("my-camel-case-name"); |
| 68 | + }); |
| 69 | + |
| 70 | + // Reserved Character Tests (RFC 3986 gen-delims and sub-delims) |
| 71 | + test("should convert reserved characters like & to hyphens", () => { |
| 72 | + const output = transformSigLeadToURI("SIG Storage & Backup"); |
| 73 | + expect(output).toEqual("sig-storage-backup"); // & -> space -> hyphen |
| 74 | + }); |
| 75 | + |
| 76 | + test("should convert reserved characters like / and : to hyphens", () => { |
| 77 | + const output = transformSigLeadToURI("Project:Alpha/Beta"); |
| 78 | + expect(output).toEqual("project-alpha-beta"); // : -> space, / -> space, space+space -> hyphen |
| 79 | + }); |
| 80 | + |
| 81 | + test("should convert reserved characters like () and + to hyphens", () => { |
| 82 | + const output = transformSigLeadToURI("My Project (Test+Alpha)"); |
| 83 | + expect(output).toEqual("my-project-test-alpha"); |
| 84 | + }); |
| 85 | + |
| 86 | + test("should convert various reserved characters #[]@?$, to hyphens", () => { |
| 87 | + const output = transformSigLeadToURI("Special#Chars[Test]?@Value,$"); |
| 88 | + expect(output).toEqual("special-chars-test-value"); |
| 89 | + }); |
| 90 | + |
| 91 | + // Non-Allowed Character Removal Tests |
| 92 | + test("should remove characters not unreserved or reserved (e.g., ™, ©)", () => { |
| 93 | + const output = transformSigLeadToURI("MyOrg™ With © Symbols"); |
| 94 | + expect(output).toEqual("my-org-with-symbols"); |
| 95 | + }); |
| 96 | + |
| 97 | + test("should remove emoji", () => { |
| 98 | + const output = transformSigLeadToURI("Project ✨ Fun"); |
| 99 | + expect(output).toEqual("project-fun"); |
| 100 | + }); |
| 101 | + |
| 102 | + |
| 103 | + // Whitespace and Hyphen Collapsing Tests |
| 104 | + test("should handle multiple spaces between words", () => { |
| 105 | + const output = transformSigLeadToURI("SIG UI Project"); |
| 106 | + expect(output).toEqual("sig-ui-project"); |
| 107 | + }); |
| 108 | + |
| 109 | + test("should handle leading/trailing whitespace", () => { |
| 110 | + const output = transformSigLeadToURI(" Leading and Trailing "); |
| 111 | + expect(output).toEqual("leading-and-trailing"); |
| 112 | + }); |
| 113 | + |
| 114 | + test("should handle mixed whitespace (tabs, newlines)", () => { |
| 115 | + const output = transformSigLeadToURI("Mix\tOf\nWhite Space"); |
| 116 | + expect(output).toEqual("mix-of-white-space"); |
| 117 | + }); |
| 118 | + |
| 119 | + test("should collapse multiple hyphens resulting from transformations", () => { |
| 120 | + const output = transformSigLeadToURI("Test--Multiple / Spaces"); |
| 121 | + expect(output).toEqual("test-multiple-spaces"); |
| 122 | + }); |
| 123 | + |
| 124 | + test("should collapse hyphens from start/end after transformations", () => { |
| 125 | + const output = transformSigLeadToURI("&Another Test!"); |
| 126 | + expect(output).toEqual("another-test"); |
| 127 | + }); |
| 128 | + |
| 129 | + // Unreserved Character Tests (RFC 3986) |
| 130 | + test("should keep unreserved characters: hyphen, period, underscore, tilde", () => { |
| 131 | + const output = transformSigLeadToURI("Keep.These-Chars_Okay~123"); |
| 132 | + expect(output).toEqual("keep.these-chars_okay~123"); |
| 133 | + }); |
| 134 | + |
| 135 | + test("should handle unreserved chars next to reserved chars", () => { |
| 136 | + const output = transformSigLeadToURI("Test._~&Stuff"); |
| 137 | + expect(output).toEqual("test._~-stuff"); |
| 138 | + }); |
| 139 | + |
| 140 | + |
| 141 | + // Edge Case Tests |
| 142 | + test("should return an empty string for an empty input", () => { |
| 143 | + const output = transformSigLeadToURI(""); |
| 144 | + expect(output).toEqual(""); |
| 145 | + }); |
| 146 | + |
| 147 | + test("should return an empty string for input with only spaces", () => { |
| 148 | + const output = transformSigLeadToURI(" "); |
| 149 | + expect(output).toEqual(""); |
| 150 | + }); |
| 151 | + |
| 152 | + test("should return an empty string for input with only reserved/non-allowed chars and spaces", () => { |
| 153 | + const output = transformSigLeadToURI(" & / # ™ © "); |
| 154 | + expect(output).toEqual(""); |
| 155 | + }); |
| 156 | + |
| 157 | + test("should handle numbers correctly", () => { |
| 158 | + const output = transformSigLeadToURI("ProjectApollo11"); |
| 159 | + expect(output).toEqual("project-apollo11"); // Number doesn't trigger camel case break after letter |
| 160 | + }); |
| 161 | + |
| 162 | + test("should handle numbers triggering camel case break", () => { |
| 163 | + const output = transformSigLeadToURI("Project11Apollo"); |
| 164 | + expect(output).toEqual("project-11-apollo"); // Letter after number triggers camel case break |
| 165 | + }); |
| 166 | + |
| 167 | + test("should handle names starting with lowercase", () => { |
| 168 | + const output = transformSigLeadToURI("myOrg"); |
| 169 | + expect(output).toEqual("my-org"); |
| 170 | + }); |
| 171 | + |
| 172 | +}); |
0 commit comments