Skip to content

Commit 4d4e9b6

Browse files
committed
Test fixes
1 parent 9c9f657 commit 4d4e9b6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/SwiftSafeNames.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ extension String {
126126
buffer.append(char)
127127
state = .preFirstWord
128128
} else if char.isNumber {
129-
// Prefix with an underscore if the first character is a number.
130-
buffer.append("_")
129+
// The underscore will be added by the defensive strategy.
131130
buffer.append(char)
132131
state = .accumulatingFirstWord(.init(isAccumulatingInitialUppercase: false))
133132
} else if char.isLetter {
@@ -138,7 +137,7 @@ extension String {
138137
)
139138
} else {
140139
// Illegal character, keep and let the defensive strategy deal with it.
141-
state = .preFirstWord
140+
state = .accumulatingFirstWord(.init(isAccumulatingInitialUppercase: false))
142141
buffer.append(char)
143142
}
144143
case .accumulatingFirstWord(var context):

Tests/OpenAPIGeneratorCoreTests/Extensions/Test_SwiftSafeNames.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ final class Test_SwiftSafeNames: Test_Core {
5858
// Technical strings
5959
("file/path/to/resource", "file_sol_path_sol_to_sol_resource", "FilePathToResource", "filePathToResource"),
6060
(
61-
"[email protected]", "user_period_name_commat_domain_period_com",
62-
"user_period_name_commat_domain_period_com", "user_period_name_commat_domain_period_com"
61+
"[email protected]", "user_period_name_commat_domain_period_com", "User_name_commat_domain_com",
62+
"user_name_commat_domain_com"
6363
), ("hello.world.2023", "hello_period_world_period_2023", "Hello_world_2023", "hello_world_2023"),
64-
("order#123", "order_num_123", "order_num_123", "order_num_123"),
65-
("pressKeys#123", "pressKeys_num_123", "pressKeys_num_123", "pressKeys_num_123"),
64+
("order#123", "order_num_123", "Order_num_123", "order_num_123"),
65+
("pressKeys#123", "pressKeys_num_123", "PressKeys_num_123", "pressKeys_num_123"),
6666

6767
// Non-English characters
6868
("naïve café", "naïve_space_café", "NaïveCafé", "naïveCafé"),
@@ -80,13 +80,13 @@ final class Test_SwiftSafeNames: Test_Core {
8080
("", "_empty", "_Empty_", "_empty_"),
8181

8282
// Special Char in middle
83-
("inv@lidName", "inv_commat_lidName", "inv_commat_lidName", "inv_commat_lidName"),
83+
("inv@lidName", "inv_commat_lidName", "Inv_commat_lidName", "inv_commat_lidName"),
8484

8585
// Special Char in first position
8686
("!nvalidName", "_excl_nvalidName", "_excl_nvalidName", "_excl_nvalidName"),
8787

8888
// Special Char in last position
89-
("invalidNam?", "invalidNam_quest_", "invalidNam_quest_", "invalidNam_quest_"),
89+
("invalidNam?", "invalidNam_quest_", "InvalidNam_quest_", "invalidNam_quest_"),
9090

9191
// Preserve leading underscores
9292
("__user_name", "__user_name", "__UserName", "__userName"),
@@ -110,14 +110,15 @@ final class Test_SwiftSafeNames: Test_Core {
110110
("$مرحبا", "_dollar_مرحبا", "_dollar_مرحبا", "_dollar_مرحبا"),
111111

112112
// Emoji
113-
("heart❤️emoji", "heart_x2764_️emoji", "heart_x2764_️emoji", "heart_x2764_️emoji"),
113+
("heart❤️emoji", "heart_x2764_️emoji", "Heart_x2764_️emoji", "heart_x2764_️emoji"),
114114

115115
// Content type components
116116
("application", "application", "Application", "application"),
117117
("vendor1+json", "vendor1_plus_json", "Vendor1Json", "vendor1Json"),
118118

119119
// Known real-world examples
120-
("+1", "_plus_1", "_plus_1", "_plus_1"), ("-1", "_hyphen_1", "_hyphen_1", "_hyphen_1"),
120+
("+1", "_plus_1", "_plus_1", "_plus_1"), ("one+two", "one_plus_two", "OneTwo", "oneTwo"),
121+
("-1", "_hyphen_1", "_hyphen_1", "_hyphen_1"), ("one-two", "one_hyphen_two", "OneTwo", "oneTwo"),
121122

122123
// Override
123124
("MEGA", "m_e_g_a", "m_e_g_a", "m_e_g_a"),

0 commit comments

Comments
 (0)