Skip to content

Commit ccd4012

Browse files
Fixed bug causing incorrect unwrapping of code blocks
1 parent 3a9366a commit ccd4012

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

CommentWrapper.xcodeproj/project.pbxproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,8 @@
716716
"$(inherited)",
717717
"@executable_path/../Frameworks",
718718
);
719-
MARKETING_VERSION = 1.0.2;
719+
MACOSX_DEPLOYMENT_TARGET = 11.1;
720+
MARKETING_VERSION = 1.1;
720721
PRODUCT_BUNDLE_IDENTIFIER = com.stevebarnegren.xcodecommentwrapper;
721722
PRODUCT_NAME = "Comment Wrapper";
722723
PROVISIONING_PROFILE = "a784e065-e7bf-4953-9d51-3adf4f335aab";
@@ -742,7 +743,8 @@
742743
"$(inherited)",
743744
"@executable_path/../Frameworks",
744745
);
745-
MARKETING_VERSION = 1.0.2;
746+
MACOSX_DEPLOYMENT_TARGET = 11.1;
747+
MARKETING_VERSION = 1.1;
746748
PRODUCT_BUNDLE_IDENTIFIER = com.stevebarnegren.xcodecommentwrapper;
747749
PRODUCT_NAME = "Comment Wrapper";
748750
PROVISIONING_PROFILE = "b08a48ba-3ea8-488b-a6f7-4f611e75051d";
@@ -766,6 +768,7 @@
766768
"@executable_path/../Frameworks",
767769
"@loader_path/../Frameworks",
768770
);
771+
MACOSX_DEPLOYMENT_TARGET = 11.1;
769772
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.CommentWrapperTests;
770773
PRODUCT_NAME = "$(TARGET_NAME)";
771774
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -789,6 +792,7 @@
789792
"@executable_path/../Frameworks",
790793
"@loader_path/../Frameworks",
791794
);
795+
MACOSX_DEPLOYMENT_TARGET = 11.1;
792796
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.CommentWrapperTests;
793797
PRODUCT_NAME = "$(TARGET_NAME)";
794798
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -812,7 +816,8 @@
812816
"@executable_path/../Frameworks",
813817
"@executable_path/../../../../Frameworks",
814818
);
815-
MARKETING_VERSION = 1.0.2;
819+
MACOSX_DEPLOYMENT_TARGET = 11.1;
820+
MARKETING_VERSION = 1.1;
816821
PRODUCT_BUNDLE_IDENTIFIER = com.stevebarnegren.xcodecommentwrapperext;
817822
PRODUCT_MODULE_NAME = CommentWrapperExt;
818823
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -838,7 +843,8 @@
838843
"@executable_path/../Frameworks",
839844
"@executable_path/../../../../Frameworks",
840845
);
841-
MARKETING_VERSION = 1.0.2;
846+
MACOSX_DEPLOYMENT_TARGET = 11.1;
847+
MARKETING_VERSION = 1.1;
842848
PRODUCT_BUNDLE_IDENTIFIER = com.stevebarnegren.xcodecommentwrapperext;
843849
PRODUCT_MODULE_NAME = CommentWrapperExt;
844850
PRODUCT_NAME = "$(TARGET_NAME)";

CommentWrapper.xcodeproj/xcshareddata/xcschemes/CommentWrapperExt.xcscheme

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Scheme
33
LastUpgradeVersion = "1220"
44
wasCreatedForAppExtension = "YES"
5-
version = "1.3">
5+
version = "2.0">
66
<BuildAction
77
parallelizeBuildables = "YES"
88
buildImplicitDependencies = "YES">
@@ -69,16 +69,18 @@
6969
selectedDebuggerIdentifier = ""
7070
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
7171
launchStyle = "0"
72+
askForAppToLaunch = "Yes"
7273
useCustomWorkingDirectory = "NO"
7374
ignoresPersistentStateOnLaunch = "NO"
7475
debugDocumentVersioning = "YES"
7576
debugServiceExtension = "internal"
76-
allowLocationSimulation = "YES">
77-
<PathRunnable
77+
allowLocationSimulation = "YES"
78+
launchAutomaticallySubstyle = "2">
79+
<RemoteRunnable
7880
runnableDebuggingMode = "0"
7981
BundleIdentifier = "com.apple.dt.Xcode"
80-
FilePath = "/Applications/Xcode.app">
81-
</PathRunnable>
82+
RemotePath = "/Applications/Xcode.app">
83+
</RemoteRunnable>
8284
<MacroExpansion>
8385
<BuildableReference
8486
BuildableIdentifier = "primary"
@@ -95,6 +97,7 @@
9597
savedToolIdentifier = ""
9698
useCustomWorkingDirectory = "NO"
9799
debugDocumentVersioning = "YES"
100+
askForAppToLaunch = "Yes"
98101
launchAutomaticallySubstyle = "2">
99102
<BuildableProductRunnable
100103
runnableDebuggingMode = "0">

CommentWrapperExt/CommentUnwrapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CommentUnwrapper {
4444
spacePending = false
4545
}
4646
}
47-
47+
4848
var reversed = Array(items.reversed())
4949
while let next = reversed.popLast() {
5050

@@ -78,6 +78,10 @@ class CommentUnwrapper {
7878
unwrappedString += "-"
7979
spacePending = false
8080
case .code(let value), .markdownReferenceLink(let value):
81+
if spacePending {
82+
unwrappedString += "\n"
83+
spacePending = false
84+
}
8185
unwrappedString.append(contentsOf: value)
8286
}
8387

CommentWrapperTests/CommentUnwrapperTests.swift

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class CommentUnwrapperTests: XCTestCase {
1313
// MARK: - Unwrapping
1414

1515
func testUnwrapsLines() {
16-
17-
//////////////////////////////////////// <-- Guide (40 chars)
16+
//-------------------------------------- <-- Guide (40 chars)
1817
let input = """
1918
ant bear cat dog emu fox gecko heron
2019
iguana jellyfish koala lion monkey newt
@@ -33,7 +32,7 @@ class CommentUnwrapperTests: XCTestCase {
3332
// If this wrapped input had been generated with two spaces between each line,
3433
// unwrapping will lose the double space where the line wraps
3534

36-
//////////////////////////////////////// <-- Guide (40 chars)
35+
//-------------------------------------- <-- Guide (40 chars)
3736
let input = """
3837
ant bear cat dog emu fox gecko
3938
heron iguana jellyfish koala lion
@@ -57,8 +56,7 @@ class CommentUnwrapperTests: XCTestCase {
5756
// MARK: - Comment prefix
5857

5958
func testHandlesCommentPrefix() {
60-
61-
////////////////////////////////////////*** <-- Guide (40 chars + 3 prefix)
59+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
6260
let input = """
6361
// ant bear cat dog emu fox gecko heron
6462
// iguana jellyfish koala lion monkey newt
@@ -76,7 +74,7 @@ class CommentUnwrapperTests: XCTestCase {
7674

7775
func testHandlesNewlines() {
7876

79-
////////////////////////////////////////*** <-- Guide (40 chars + 3 prefix)
77+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
8078
let input = """
8179
// ant bear cat dog emu fox gecko heron
8280
// iguana jellyfish koala lion monkey newt
@@ -99,7 +97,7 @@ class CommentUnwrapperTests: XCTestCase {
9997

10098
func testHandlesCode() {
10199

102-
////////////////////////////////////////*** <-- Guide (40 chars + 3 prefix)
100+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
103101
let input = """
104102
// ant bear cat dog emu fox gecko heron
105103
// iguana jellyfish koala lion monkey newt
@@ -127,7 +125,7 @@ class CommentUnwrapperTests: XCTestCase {
127125

128126
func testHandlesMultipleLinesOfCode() {
129127

130-
////////////////////////////////////////*** <-- Guide (40 chars + 3 prefix)
128+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
131129
let input = """
132130
// ant bear cat dog emu fox gecko heron
133131
// iguana jellyfish koala lion monkey newt
@@ -158,8 +156,7 @@ class CommentUnwrapperTests: XCTestCase {
158156
// MARK: - Bullets
159157

160158
func testHandlesBullets() {
161-
162-
////////////////////////////////////////*** <-- Guide (40 chars + 3 prefix)
159+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
163160
let input = """
164161
// - First item
165162
// - Second item
@@ -172,7 +169,7 @@ class CommentUnwrapperTests: XCTestCase {
172169

173170
func testHandlesBulletsAfterRegularComments() {
174171

175-
////////////////////////////////////////*** <-- Guide (40 chars + 3 prefix)
172+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
176173
let input = """
177174
// This is a comment
178175
//
@@ -193,4 +190,29 @@ class CommentUnwrapperTests: XCTestCase {
193190
XCTAssertEqual(output, expected)
194191
}
195192

193+
func testHandlesMarkdownCodeBlocks() {
194+
195+
//*---------------------------------------- <-- Guide (40 chars + 3 prefix)
196+
let input = """
197+
// Below is some code that should not be
198+
// unwrapped.
199+
// ```
200+
// this is the code that should not be unwrapped.
201+
// ```
202+
// Above is some code that should not be
203+
// unwrapped.
204+
"""
205+
206+
let expected = """
207+
// Below is some code that should not be unwrapped.
208+
// ```
209+
// this is the code that should not be unwrapped.
210+
// ```
211+
// Above is some code that should not be unwrapped.
212+
"""
213+
214+
let output = CommentUnwrapper.unwrap(string: input)
215+
XCTAssertEqual(output, expected)
216+
}
217+
196218
}

0 commit comments

Comments
 (0)