From 6ddf3e910c8f29ef9823c2f5cd6af8763ae77ed0 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Mon, 26 Dec 2016 00:01:25 +0900 Subject: [PATCH] Add `NodeTests.testTypedAccessorProperties()` --- Tests/YamsTests/NodeTests.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tests/YamsTests/NodeTests.swift b/Tests/YamsTests/NodeTests.swift index bb6ea76..e2e8860 100644 --- a/Tests/YamsTests/NodeTests.swift +++ b/Tests/YamsTests/NodeTests.swift @@ -48,6 +48,32 @@ class NodeTests: XCTestCase { XCTAssertEqual(sequence, expected) } + func testTypedAccessorProperties() { + let scalarBool: Node = "true" + XCTAssertEqual(scalarBool.bool, true) + + let scalarFloat: Node = "1.0" + XCTAssertEqual(scalarFloat.float, 1.0) + + let scalarNull: Node = "null" + XCTAssertEqual(scalarNull.null, NSNull()) + + let scalarInt: Node = "1" + XCTAssertEqual(scalarInt.int, 1) + + let base64String = [ + " R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5", + " OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+", + " +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC", + " AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" + ].joined() + let scalarBinary: Node = .scalar(base64String, .implicit) + XCTAssertEqual(scalarBinary.binary, Data(base64Encoded: base64String, options: .ignoreUnknownCharacters)!) + + let scalarTimestamp: Node = "2001-12-15T02:59:43.1Z" + XCTAssertEqual(scalarTimestamp.timestamp, timestamp( 0, 2001, 12, 15, 02, 59, 43, 0.1)) + } + func testSubscriptMapping() { let mapping: Node = ["key1": "value1", "key2": "value2"] let valueForKey1 = mapping["key1"]?.string