Skip to content

Commit

Permalink
Small improvement for snake case handling (#179)
Browse files Browse the repository at this point in the history
* Small improvement for snake case handling

* Added tests

Co-authored-by: Ilia <>
  • Loading branch information
IljaKosynkin authored Jul 17, 2022
1 parent f2321f1 commit 116629e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/FigmaExportCore/Extensions/StringCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions Tests/FigmaExportCoreTests/Extensions/StringCaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 116629e

Please sign in to comment.