Skip to content

Commit

Permalink
Fixed Data
Browse files Browse the repository at this point in the history
Also made Unit tests for OS X compile in debug configuration
  • Loading branch information
colemancda committed Jul 3, 2016
1 parent 405f355 commit 7d07d62
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 68 deletions.
5 changes: 5 additions & 0 deletions Sources/SwiftFoundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@
set { _bytes.replaceSubrange(bounds, with: newValue) }
}

public var count: Int {

return _bytes.count
}

/// The start `Index` in the data.
public var startIndex: Index {

Expand Down
43 changes: 43 additions & 0 deletions Sources/SwiftFoundation/JSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,46 @@ private extension JSON.Value {
}
}

// MARK: - Supporting Types

public extension JSON {

/// Options for serializing JSON.
///
/// - Note: Uses the [JSON-C](https://github.com/json-c/json-c) library.
public enum WritingOption: BitMaskOption {

/// Causes the output to have minimal whitespace inserted to make things slightly more readable.
case Spaced

/// Causes the output to be formatted. See the [Two Space Tab](http://jsonformatter.curiousconcept.com/) option
/// for an example of the format.
case Pretty

/// Drop trailing zero for float values
case NoZero

public init?(rawValue: Int32) {

switch rawValue {

case JSON_C_TO_STRING_SPACED: self = .Spaced
case JSON_C_TO_STRING_PRETTY: self = .Pretty
case JSON_C_TO_STRING_NOZERO: self = .NoZero

default: return nil
}
}

public var rawValue: Int32 {

switch self {

case Spaced: return JSON_C_TO_STRING_SPACED
case Pretty: return JSON_C_TO_STRING_PRETTY
case NoZero: return JSON_C_TO_STRING_NOZERO
}
}
}
}

55 changes: 0 additions & 55 deletions Sources/SwiftFoundation/JSONWritingOption.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/UnitTests/DataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class DataTests: XCTestCase {

memcpy(dataPointer, testData.bytes, testData.count)

let data = Data(bytes: dataPointer, count: testData.count)
let data = SwiftFoundation.Data(bytes: dataPointer, count: testData.count)

XCTAssert(data == testData, "\(data) == \(testData)")
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/UnitTests/POSIXTimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class POSIXTimeTests: XCTestCase {

func testTimeVal() {

let date = Date()
let date = SwiftFoundation.Date()

let time = timeval(timeInterval: date.timeIntervalSince1970)

Expand All @@ -47,7 +47,7 @@ final class POSIXTimeTests: XCTestCase {

func testTimeSpec() {

let date = Date()
let date = SwiftFoundation.Date()

let time = timespec(timeInterval: date.timeIntervalSince1970)

Expand Down
2 changes: 1 addition & 1 deletion Sources/UnitTests/UUIDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class UUIDTests: XCTestCase {

func testBytes() {

let expectedData = Data(bytes: [91, 254, 177, 148, 104, 196, 72, 232, 143, 67, 60, 88, 99, 100, 203, 111] as [Byte])
let expectedData = SwiftFoundation.Data(bytes: [91, 254, 177, 148, 104, 196, 72, 232, 143, 67, 60, 88, 99, 100, 203, 111] as [Byte])

let stringValue = "5BFEB194-68C4-48E8-8F43-3C586364CB6F"

Expand Down
8 changes: 0 additions & 8 deletions Xcode/SwiftFoundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@
6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */; };
6E957C2C1C43AA55003F3C51 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */; };
6E957C2D1C43AA55003F3C51 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */; };
6E957C2E1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */; };
6E957C2F1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */; };
6E957C301C43AA55003F3C51 /* JSONWritingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */; };
6E957C481C43B397003F3C51 /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E957C451C43B397003F3C51 /* JSON.framework */; };
6E957C491C43B397003F3C51 /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E957C451C43B397003F3C51 /* JSON.framework */; };
6E957C4A1C43B397003F3C51 /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E957C451C43B397003F3C51 /* JSON.framework */; };
Expand Down Expand Up @@ -256,7 +253,6 @@
6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparisonResult.swift; sourceTree = "<group>"; };
6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = "<group>"; };
6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = "<group>"; };
6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = "<group>"; };
6E957C451C43B397003F3C51 /* JSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSON.framework; sourceTree = "<group>"; };
6E957C471C43B397003F3C51 /* JSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSON.framework; sourceTree = "<group>"; };
6E957C561C442E3E003F3C51 /* JSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -356,7 +352,6 @@
6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */,
6E957C251C43A7C8003F3C51 /* JSONParse.swift */,
6E957C291C43AA55003F3C51 /* JSONSerialization.swift */,
6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */,
6E82FD711CBA06C10049CD1B /* Lock.swift */,
6E2C2B361C20F6EB00B2C995 /* Null.swift */,
6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */,
Expand Down Expand Up @@ -720,7 +715,6 @@
6E957C2C1C43AA55003F3C51 /* JSONSerialization.swift in Sources */,
6EE84DDA1CAF659800A40C4D /* Endianness.swift in Sources */,
6E2C2BCB1C20F76600B2C995 /* POSIXError.swift in Sources */,
6E957C2F1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */,
6E2C2BB81C20F76600B2C995 /* Date.swift in Sources */,
6E2C2BC71C20F76600B2C995 /* JSON.swift in Sources */,
6E2C2BAF1C20F76600B2C995 /* Base64.swift in Sources */,
Expand Down Expand Up @@ -766,7 +760,6 @@
6E957C2D1C43AA55003F3C51 /* JSONSerialization.swift in Sources */,
6EE84DDB1CAF659800A40C4D /* Endianness.swift in Sources */,
6E2C2B971C20F76600B2C995 /* POSIXError.swift in Sources */,
6E957C301C43AA55003F3C51 /* JSONWritingOption.swift in Sources */,
6E2C2B841C20F76600B2C995 /* Date.swift in Sources */,
6E2C2B931C20F76600B2C995 /* JSON.swift in Sources */,
6E2C2B7B1C20F76600B2C995 /* Base64.swift in Sources */,
Expand Down Expand Up @@ -830,7 +823,6 @@
6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */,
6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */,
6E2C2BFF1C20F76700B2C995 /* POSIXError.swift in Sources */,
6E957C2E1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */,
6E2C2BEC1C20F76700B2C995 /* Date.swift in Sources */,
6E2C2BFB1C20F76700B2C995 /* JSON.swift in Sources */,
6EE84DD91CAF659800A40C4D /* Endianness.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
Expand Down

0 comments on commit 7d07d62

Please sign in to comment.