-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added StringFilters.camelToSnakeCase filter (#35)
* Added StringFilters.camelToSnakeCase filter, registered for Stencil Swift extensions. Added test coverage Updated README.md * updated camelToSnakeCase to take a single optional boolean argument (default true) for lower casing the string. Updated README to describe filter usage Updated CHANGELOG * Plugged the code into Sourcery and found that Stencil only parses strings and numbers for parameters, so rewrote the filter to always lowercase, except when the arg is either "false", "no" or "0" * Based on PR comments, factored out argument parsing into a separate function with its own tests * Forgot to update comments and test names after renaming function * Refactored parseBool based on PR comments - it now supports both optional and required values to be in the arguments. If optional and not found, returns nil. If not optional and not found, throws exception. Separated out parseBool tests into separate test class Added XCTAssertThrows for testing * Good call in PR comments to simplify parseBool logic. * Trigger CI build * Cleaned up lint issues * Removed XCTest+Assertions file and using XCTAssertThrowsError instead. Corrected indentation in new tests. * Move new filter documentation in appropriate Markdown file * Move `parseBool` out of `StringFilters`
- Loading branch information
1 parent
02169c3
commit b2f4141
Showing
8 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// StencilSwiftKit | ||
// Copyright (c) 2017 SwiftGen | ||
// MIT Licence | ||
// | ||
|
||
import XCTest | ||
@testable import StencilSwiftKit | ||
|
||
class ParseBoolTests: XCTestCase { | ||
|
||
func testParseBool_WithTrueString() throws { | ||
let value = try Filters.parseBool(from: ["true"], index: 0) | ||
XCTAssertTrue(value!) | ||
} | ||
|
||
func testParseBool_WithFalseString() throws { | ||
let value = try Filters.parseBool(from: ["false"], index: 0) | ||
XCTAssertFalse(value!) | ||
} | ||
|
||
func testParseBool_WithYesString() throws { | ||
let value = try Filters.parseBool(from: ["yes"], index: 0) | ||
XCTAssertTrue(value!) | ||
} | ||
|
||
func testParseBool_WithNoString() throws { | ||
let value = try Filters.parseBool(from: ["no"], index: 0) | ||
XCTAssertFalse(value!) | ||
} | ||
|
||
func testParseBool_WithOneString() throws { | ||
let value = try Filters.parseBool(from: ["1"], index: 0) | ||
XCTAssertTrue(value!) | ||
} | ||
|
||
func testParseBool_WithZeroString() throws { | ||
let value = try Filters.parseBool(from: ["0"], index: 0) | ||
XCTAssertFalse(value!) | ||
} | ||
|
||
func testParseBool_WithOptionalInt() throws { | ||
let value = try Filters.parseBool(from: [1], index: 0, required: false) | ||
XCTAssertNil(value) | ||
} | ||
|
||
func testParseBool_WithRequiredInt() throws { | ||
XCTAssertThrowsError(try Filters.parseBool(from: [1], index: 0, required: true)) | ||
} | ||
|
||
func testParseBool_WithOptionalDouble() throws { | ||
let value = try Filters.parseBool(from: [1.0], index: 0, required: false) | ||
XCTAssertNil(value) | ||
} | ||
|
||
func testParseBool_WithRequiredDouble() throws { | ||
XCTAssertThrowsError(try Filters.parseBool(from: [1.0], index: 0, required: true)) | ||
} | ||
|
||
func testParseBool_WithEmptyString() throws { | ||
XCTAssertThrowsError(try Filters.parseBool(from: [""], index: 0, required: false)) | ||
} | ||
|
||
func testParseBool_WithEmptyStringAndRequiredArg() throws { | ||
XCTAssertThrowsError(try Filters.parseBool(from: [""], index: 0, required: true)) | ||
} | ||
|
||
func testParseBool_WithEmptyArray() throws { | ||
let value = try Filters.parseBool(from: [], index: 0, required: false) | ||
XCTAssertNil(value) | ||
} | ||
|
||
func testParseBool_WithEmptyArrayAndRequiredArg() throws { | ||
XCTAssertThrowsError(try Filters.parseBool(from: [], index: 0, required: true)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters