updates plug with all sorts of awesome improvements
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import Foundation
|
||||
import PlakCore
|
||||
import Testing
|
||||
|
||||
@Suite struct BookmarkTests {
|
||||
@Test("a line that starts with = directly followed by a title is a bookmark, with the trimmed title and the range of the line")
|
||||
func finds() {
|
||||
let text = "=update on this\nsome text\n=second one \n" as NSString
|
||||
#expect(Bookmark.find(in: text) == [
|
||||
Bookmark(title: "update on this", range: NSRange(location: 0, length: 15)),
|
||||
Bookmark(title: "second one", range: NSRange(location: 26, length: 13)),
|
||||
])
|
||||
}
|
||||
|
||||
@Test("a bookmark on the last line, without a newline, runs to the end of the text")
|
||||
func lastLine() {
|
||||
let text = "a\n\n=end" as NSString
|
||||
#expect(Bookmark.find(in: text) == [Bookmark(title: "end", range: NSRange(location: 3, length: 4))])
|
||||
}
|
||||
|
||||
@Test("= alone, = with a space before the title, an = inside a line and an indented = are no bookmarks")
|
||||
func none() {
|
||||
for text in ["=", "= ", "= \n", "= title", "=\ttitle", "a = b", " =title", "x\n=\n= \t\n"] {
|
||||
#expect(Bookmark.find(in: text as NSString).isEmpty, "text: \(text)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test("a line that starts with two = is no bookmark, so a == title == line is none")
|
||||
func doubleEquals() {
|
||||
for text in ["==twice", "== Contact ==", "== Contact, eerdere versie (entry 974, 1 okt 2026) ==\n=real"] {
|
||||
#expect(Bookmark.find(in: text as NSString).map(\.title) == (text.hasSuffix("=real") ? ["real"] : []), "text: \(text)")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user