From 116629e57af56f6f21f574d6a6e377ceaccb5530 Mon Sep 17 00:00:00 2001 From: Ilia Kosynkin Date: Sun, 17 Jul 2022 09:15:27 +0200 Subject: [PATCH] Small improvement for snake case handling (#179) * Small improvement for snake case handling * Added tests Co-authored-by: Ilia <> --- Sources/FigmaExportCore/Extensions/StringCase.swift | 2 +- Tests/FigmaExportCoreTests/Extensions/StringCaseTests.swift | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/FigmaExportCore/Extensions/StringCase.swift b/Sources/FigmaExportCore/Extensions/StringCase.swift index dfe1adb9..4c5ad09e 100644 --- a/Sources/FigmaExportCore/Extensions/StringCase.swift +++ b/Sources/FigmaExportCore/Extensions/StringCase.swift @@ -49,7 +49,7 @@ public extension String { if results.isEmpty && (character.isLetter || character.isNumber) { results.append(String(character)) } else if ((lastCharacter.isLetter || lastCharacter.isNumber) && character.isLowercase) || - (lastCharacter.isNumber && character.isNumber) { + (lastCharacter.isNumber && character.isNumber) || (lastCharacter.isUppercase && character.isUppercase) { results[results.count - 1] = results[results.count - 1] + String(character) } else if (character.isLetter || character.isNumber) { results.append(String(character)) diff --git a/Tests/FigmaExportCoreTests/Extensions/StringCaseTests.swift b/Tests/FigmaExportCoreTests/Extensions/StringCaseTests.swift index 430a76f3..35b2238f 100644 --- a/Tests/FigmaExportCoreTests/Extensions/StringCaseTests.swift +++ b/Tests/FigmaExportCoreTests/Extensions/StringCaseTests.swift @@ -7,6 +7,7 @@ final class StringCaseTests: XCTestCase { XCTAssertTrue("snake".isSnakeCase) XCTAssertTrue("snake_case".isSnakeCase) XCTAssertTrue("snake_case_example".isSnakeCase) + XCTAssertFalse("NOTSNAKECASE".isSnakeCase) XCTAssertFalse("not_a_SNAKECASE_String".isSnakeCase) XCTAssertFalse("notSnakeCase".isSnakeCase) XCTAssertFalse("AlsoNotSnakeCase".isSnakeCase) @@ -16,6 +17,7 @@ final class StringCaseTests: XCTestCase { XCTAssertEqual("snakeCased".snakeCased(), "snake_cased") XCTAssertEqual("snake Cased_String".snakeCased(), "snake_cased_string") XCTAssertEqual("_this is* not-Very%difficult".snakeCased(), "this_is_not_very_difficult") + XCTAssertEqual("snakeCASE".snakeCased(), "snake_case") } func testLowerCamelCase() throws {