-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from mattpolzin/bugfix/yams-whole-number-floats
support whole number floats decoded as integers
- Loading branch information
Showing
5 changed files
with
99 additions
and
14 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
56 changes: 56 additions & 0 deletions
56
Tests/OpenAPIKitTests/Schema Object/SchemaObjectYamsTests.swift
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,56 @@ | ||
// | ||
// SchemaObjectYamsTests.swift | ||
// | ||
// | ||
// Created by Mathew Polzin on 4/22/20. | ||
// | ||
|
||
/// | ||
/// This file exists to facilitate regression tests for Yams-specific problems encountered | ||
/// and fixed. | ||
/// | ||
|
||
import Foundation | ||
import XCTest | ||
import OpenAPIKit | ||
import Yams | ||
|
||
final class SchemaObjectYamsTests: XCTestCase { | ||
func test_floatingPointWholeNumberIntegerDecode() throws { | ||
let integerString = | ||
""" | ||
type: integer | ||
minimum: 1.0 | ||
maximum: 10.0 | ||
""" | ||
|
||
let integer = try YAMLDecoder().decode(JSONSchema.self, from: integerString) | ||
|
||
XCTAssertEqual( | ||
integer, | ||
JSONSchema.integer(required: false, maximum: (10, exclusive: false), minimum: (1, exclusive: false)) | ||
) | ||
} | ||
|
||
func test_floatingPointIntegerDecodeFails() { | ||
let integerString = | ||
""" | ||
type: integer | ||
maximum: 10.2 | ||
""" | ||
|
||
XCTAssertThrowsError(try YAMLDecoder().decode(JSONSchema.self, from: integerString)) { error in | ||
XCTAssertEqual(OpenAPI.Error(from: error).localizedDescription, "Inconsistency encountered when parsing `maximum`: Expected an Integer literal but found a floating point value.") | ||
} | ||
|
||
let integerString2 = | ||
""" | ||
type: integer | ||
minimum: 1.1 | ||
""" | ||
|
||
XCTAssertThrowsError(try YAMLDecoder().decode(JSONSchema.self, from: integerString2)) { error in | ||
XCTAssertEqual(OpenAPI.Error(from: error).localizedDescription, "Inconsistency encountered when parsing `minimum`: Expected an Integer literal but found a floating point value.") | ||
} | ||
} | ||
} |