Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4.1 #1

Merged
merged 2 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private extension FileFinder {
let fileManager: FileManager = FileManager()
let folderContents: [String] = try fileManager.contentsOfDirectory(atPath: folderPath)

return folderContents.flatMap { (path: String) -> String? in
return folderContents.compactMap { (path: String) -> String? in
var isFolder: ObjCBool = ObjCBool(false)
let fullPath: String = folderPath + "/" + path

Expand Down
44 changes: 36 additions & 8 deletions Source/ModelCompiler/ModelCompiler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
02E207DE208DD9620015A11E /* StringTruncateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E207DD208DD9620015A11E /* StringTruncateTests.swift */; };
512356791E6989B30090462A /* Account.swift.test in Resources */ = {isa = PBXBuildFile; fileRef = 512356731E6989A40090462A /* Account.swift.test */; };
5123567B1E6989B30090462A /* Protocol.swift.test in Resources */ = {isa = PBXBuildFile; fileRef = 512356751E6989A40090462A /* Protocol.swift.test */; };
51421C931E66FCC60021D448 /* Typê.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51421C921E66FCC60021D448 /* Typê.swift */; };
Expand Down Expand Up @@ -72,6 +73,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
02E207DD208DD9620015A11E /* StringTruncateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringTruncateTests.swift; sourceTree = "<group>"; };
512356731E6989A40090462A /* Account.swift.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Account.swift.test; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
512356751E6989A40090462A /* Protocol.swift.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Protocol.swift.test; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
51421C921E66FCC60021D448 /* Typê.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Typê.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,6 +155,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
02E207DF208DD96A0015A11E /* Helper */ = {
isa = PBXGroup;
children = (
02E207DD208DD9620015A11E /* StringTruncateTests.swift */,
);
path = Helper;
sourceTree = "<group>";
};
5123566E1E6989760090462A /* SourceCode */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -299,8 +309,9 @@
8ABCC0EB1CABE3A1003CCDBA /* Classes */ = {
isa = PBXGroup;
children = (
51587B341E6DB9100043879D /* Parser */,
8ABCC0EE1CABE3E0003CCDBA /* CompilerTests.swift */,
02E207DF208DD96A0015A11E /* Helper */,
51587B341E6DB9100043879D /* Parser */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -462,7 +473,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "RedMadRobot LLC.";
TargetAttributes = {
51C4D8A81E8023710095C2E4 = {
Expand Down Expand Up @@ -550,6 +561,7 @@
5192FC481E812E2F007EEA00 /* ArgumentParserTests.swift in Sources */,
8AA288CE1E76CD8A00FE6F97 /* PropertyParserTests.swift in Sources */,
8ABCC0EF1CABE3E0003CCDBA /* CompilerTests.swift in Sources */,
02E207DE208DD9620015A11E /* StringTruncateTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -615,7 +627,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "Jeorge-Taflanidi.ComposerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
Expand All @@ -630,7 +642,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Jeorge-Taflanidi.ComposerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
Expand All @@ -646,7 +658,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ModelCompilerTests/SupportingFiles/ModelCompilerTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
Expand All @@ -661,7 +673,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.redmadrobot.ModelCompilerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ModelCompilerTests/SupportingFiles/ModelCompilerTests-Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
Expand All @@ -675,14 +687,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -726,14 +746,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -780,7 +808,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
Expand All @@ -802,7 +830,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.redmadrobot.ModelCompiler;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Source/ModelCompiler/ModelCompiler/Classes/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Compiler {
utilities for `throw CompilerMessage` line.
*/
public func compile(files: [SourceCodeFile]) throws -> [Klass] {
return try files.flatMap { (file: SourceCodeFile) -> Klass? in
return try files.compactMap { (file: SourceCodeFile) -> Klass? in
return try self.compile(file: file)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ open class TypeParser {
// check type ends with ?
if rawType.hasSuffix("?") {
return Typê.OptionalType(
wrapped: try parse(rawType: String(rawType.characters.dropLast()), declaration: declaration)
wrapped: try parse(rawType: String(rawType.dropLast()), declaration: declaration)
)
}

Expand Down Expand Up @@ -156,8 +156,8 @@ open class TypeParser {
}

var objectTypeName: String = rawType.firstWord()
if objectTypeName.characters.last == "?" {
objectTypeName = String(objectTypeName.characters.dropLast())
if objectTypeName.last == "?" {
objectTypeName = String(objectTypeName.dropLast())
}

if objectTypeName.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public extension String {
return self
}

return deleteWord ? substring(from: wordRange.upperBound) : substring(from: wordRange.lowerBound)
return deleteWord ? String(self[wordRange.upperBound...]) : String(self[wordRange.lowerBound...])
}

/**
Expand All @@ -46,7 +46,7 @@ public extension String {
return self
}

return deleteWord ? substring(to: wordRange.lowerBound) : substring(to: wordRange.upperBound)
return deleteWord ? String(self[..<wordRange.lowerBound]) : String(self[..<wordRange.upperBound])
}

/**
Expand Down Expand Up @@ -113,30 +113,30 @@ public extension String {
*/
public func truncateLeadingWhitespace() -> String {
if hasPrefix(" ") {
return substring(from: characters.index(startIndex, offsetBy: 1)).truncateLeadingWhitespace()
return String(self[index(startIndex, offsetBy: 1)...]).truncateLeadingWhitespace()
}

if hasPrefix("\n") {
return substring(from: characters.index(startIndex, offsetBy: 1)).truncateLeadingWhitespace()
return String(self[index(startIndex, offsetBy: 1)...]).truncateLeadingWhitespace()
}

return self
}

public func truncateToWordFromBehind(_ word: String, deleteWord: Bool = true) -> String {
let drow: String = String(word.characters.reversed())
let fles: String = String(self.characters.reversed())
let drow: String = String(word.reversed())
let fles: String = String(self.reversed())

let cut: String = fles.truncateAllBeforeWord(drow, deleteWord: deleteWord)
return String(cut.characters.reversed())
return String(cut.reversed())
}

public func truncateUntilWord(_ word: String) -> String {
let drow: String = String(word.characters.reversed())
let fles: String = String(self.characters.reversed())
let drow: String = String(word.reversed())
let fles: String = String(self.reversed())

let cut: String = fles.truncateFromWord(drow, deleteWord: false)
return String(cut.characters.reversed())
return String(cut.reversed())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// String+TruncateTests.swift
// ModelCompilerTests
//
// Created by Anton Glezman on 23.04.2018.
// Copyright © 2018 RedMadRobot LLC. All rights reserved.
//

import XCTest
@testable import ModelCompiler

class StringTruncateTests: XCTestCase {

func testTruncateAllBeforeWord_deleteWordFalse_equalsExpectedResult() {
let sourceStr = "text @annotation name"
let result = sourceStr.truncateAllBeforeWord("@annotation", deleteWord: false)
XCTAssertEqual(result, "@annotation name")
}

func testTruncateAllBeforeWord_deleteWordTrue_equalsExpectedResult() {
let sourceStr = "text @annotation name"
let result = sourceStr.truncateAllBeforeWord("@annotation", deleteWord: true)
XCTAssertEqual(result, " name")
}

func testTruncateAllBeforeWord_withoutWord_equalsExpectedResult() {
let sourceStr = "text annotation name"
let result = sourceStr.truncateAllBeforeWord("@annotation", deleteWord: true)
XCTAssertEqual(result, "text annotation name")
}

func testTruncateFromWord_deleteWordFalse_equalsExpectedResult() {
let sourceStr = "code //comment"
let result = sourceStr.truncateFromWord("//", deleteWord: false)
XCTAssertEqual(result, "code //")
}

func testTruncateFromWord_deleteWordTrue_equalsExpectedResult() {
let sourceStr = "code //comment"
let result = sourceStr.truncateFromWord("//", deleteWord: true)
XCTAssertEqual(result, "code ")
}

func testTruncateFromWord_withoutWord_equalsExpectedResult() {
let sourceStr = "code comment"
let result = sourceStr.truncateFromWord("//", deleteWord: true)
XCTAssertEqual(result, "code comment")
}

func testLastWord_afterSpace_equalsExpectedResult() {
let sourceStr = "first second third"
let result = sourceStr.lastWord()
XCTAssertEqual(result, "third")
}

func testLastWord_afterLineBreak_equalsExpectedResult() {
let sourceStr = "first second\nthird"
let result = sourceStr.lastWord()
XCTAssertEqual(result, "third")
}

func testFirstWord_beforeSpace_equalsExpectedResult() {
let sourceStr = "first second third"
let result = sourceStr.firstWord()
XCTAssertEqual(result, "first")
}

func testFirstWord_beforeDivider_equalsExpectedResult() {
let sourceStr = "first.second.third"
let result = sourceStr.firstWord(sentenceDividers: ["."])
XCTAssertEqual(result, "first")
}

func testEnumerateWords_equalsExpectedResult() {
let sourceStr = "first line\n" +
"second line"

var result = [String]()
sourceStr.enumerateWords { (word) in
result.append(word)
}

let expectedResult = ["first", "line", "\n", "second", "line", "\n"]
XCTAssertEqual(result, expectedResult)
}

func testTruncateLeadingWhitespace_multipleSpaces_equalsExpectedResult() {
let sourceStr = " \n \n text"
let result = sourceStr.truncateLeadingWhitespace()
XCTAssertEqual(result, "text")
}

func testTruncateToWordFromBehind_deleteWordFalse_equalsExpectedResult() {
let sourceStr = "text @annotation name"
let result = sourceStr.truncateToWordFromBehind("@annotation", deleteWord: false)
XCTAssertEqual(result, "text @annotation")
}

func testTruncateToWordFromBehind_deleteWordTrue_equalsExpectedResult() {
let sourceStr = "text @annotation name"
let result = sourceStr.truncateToWordFromBehind("@annotation", deleteWord: true)
XCTAssertEqual(result, "text ")
}

func testTruncateUntilWord_equalsExpectedResult() {
let sourceStr = "text @annotation name"
let result = sourceStr.truncateUntilWord("@annotation")
XCTAssertEqual(result, "@annotation name")
}
}