Skip to content

Commit e7a570d

Browse files
Kyle-Yefranklinsch
andauthored
Update SourceLocation doc and add test case (#51)
Co-authored-by: Franklin Schrans <[email protected]>
1 parent 2c2354d commit e7a570d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Sources/Markdown/Infrastructure/SourceLocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct SourceLocation: Hashable, CustomStringConvertible, Comparable {
2525
/// The line number of the location.
2626
public var line: Int
2727

28-
/// The number of Unicode code units from the start of the line to the character at this source location.
28+
/// The number of bytes in UTF-8 encoding from the start of the line to the character at this source location.
2929
public var column: Int
3030

3131
/// The source file for which this location applies, if it came from an accessible location.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
@testable import Markdown
12+
import XCTest
13+
14+
class SourceLoacationTests: XCTestCase {
15+
func testNonAsciiCharacterColumn() throws {
16+
func assertColumnNumberAssumesUTF8Encoding(text: String) throws {
17+
let document = Document(parsing: text)
18+
let range = try XCTUnwrap(document.range)
19+
XCTAssertEqual(range.upperBound.column - 1, text.utf8.count)
20+
}
21+
22+
// Emoji
23+
try assertColumnNumberAssumesUTF8Encoding(text: "🇺🇳")
24+
// CJK Character
25+
try assertColumnNumberAssumesUTF8Encoding(text: "")
26+
}
27+
}

0 commit comments

Comments
 (0)