Commit d4de9df55d

d4de9df55d14c023d3bf718973705e5454aaf4e2

parent: f3889aac3f

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-22 18:19 UTC

Seed the random tests and refuse two Calc cases that diverge

Random tests use a fixed seed, printed on failure; ORGSTAR_SEED picks
another. Calc refuses `<` after a space in a vector without commas,
which Calc reads as a date, and products nested past 64 calls of mul,
where Calc hits max-lisp-eval-depth. The agenda test checks that file
stats run off the main thread instead of timing the main actor.

Closes #204

Layout: unified · split

CONTRIBUTING.org +3
@@ -143,6 +143,9 @@ swift test # all tests
143143ORGSTAR_GATES=1 swift test -c release --filter GateTests # performance gates
144144#+END_SRC
145145
146Randomised tests use a fixed seed and print it when they fail. =ORGSTAR_SEED=<n> swift test=
147runs them with another; the incremental-parse and restyle fuzz tests read =ORGSTAR_FUZZ_SEED= instead.
148
146149=swift test= covers the Developer ID build. =APPSTORE= is set only in the Xcode targets, so
147150also check that the App Store build and the iOS app compile:
148151
Sources/OrgApp/AgendaModel.swift +4
@@ -62,6 +62,8 @@ public final class AgendaModel {
6262 private let workspace: WorkspaceModel
6363 @ObservationIgnored public let cache: AgendaSourceCache
6464 @ObservationIgnored private var generation = 0
65 /// Called with each file's path before it is checked on disk. For tests.
66 @ObservationIgnored var willStat: (@Sendable (String) -> Void)?
6567
6668 public init(workspace: WorkspaceModel, cache: AgendaSourceCache = AgendaSourceCache()) {
6769 self.workspace = workspace
@@ -179,6 +181,7 @@ public final class AgendaModel {
179181 let blocking = options.dimBlockedTasks != .off && (options.enforceTodoDependencies || options.enforceTodoCheckboxDependencies)
180182 let files = files
181183 let (openCache, diskCache) = (cache.open, cache.entries)
184 let willStat = willStat
182185 let loaded = await Task.detached {
183186 var sources: [(path: String, mtime: Date, size: Int, source: AgendaSource, fromDisk: Bool)] = []
184187 for path in files {
@@ -194,6 +197,7 @@ public final class AgendaModel {
194197 sources.append((path, .distantPast, -1, cached ?? AgendaSource(path: path, text: text, defaults: defaults.resolvingSetupFiles(in: text, path: path, read: OrgSettings.readFile), checksBlocking: blocking), false))
195198 continue
196199 }
200 willStat?(path)
197201 let attributes = try? FileManager.default.attributesOfItem(atPath: path)
198202 let mtime = attributes?[.modificationDate] as? Date ?? .distantPast
199203 let size = (attributes?[.size] as? NSNumber)?.intValue ?? -1
Sources/OrgCore/Compute/BabelCalc.swift +1 −1
@@ -236,7 +236,7 @@ extension Calc {
236236 guard (3...18).contains(modes.precision) else { throw Unsupported("calc precision") }
237237 return try $precision.withValue(modes.precision) {
238238 try $fractions.withValue(modes.preferFractions) {
239 try $symbolicMode.withValue(modes.symbolic, operation: body)
239 try $symbolicMode.withValue(modes.symbolic) { try $nesting.withValue(Nesting(), operation: body) }
240240 }
241241 }
242242 }
Sources/OrgCore/Compute/Calc.swift +7 −2
@@ -62,7 +62,7 @@ public enum Calc {
6262 guard (3...18).contains(modes.precision) else { throw Unsupported("calc precision") }
6363 return try $precision.withValue(modes.precision) {
6464 try $fractions.withValue(modes.preferFractions) {
65 try $symbolicMode.withValue(modes.symbolic) {
65 try $symbolicMode.withValue(modes.symbolic) { try $nesting.withValue(Nesting()) {
6666 var parser = Parser(expression)
6767 let tree = try parser.parse()
6868 let value = try Evaluator(modes: modes).eval(tree)
@@ -78,7 +78,7 @@ public enum Calc {
7878 }
7979 }
8080 return try format(value, modes.format)
81 }
81 } }
8282 }
8383 }
8484 }
@@ -1142,6 +1142,11 @@ public enum Calc {
11421142 let left = try sum()
11431143 // Calc reads `<<` and `>>` as one token, so `1<<2026-10-05 Mon>` is a syntax error.
11441144 if take("<<") || take(">>") { throw Unsupported("formula syntax") }
1145 // In a vector without commas Calc reads `<` after a space as the start of a date:
1146 // `[0 < (1 > 2)]` is `[0, <2026-01-02 Fri>]`.
1147 if spaceSeparated, peek() == "<", chars[i - 1] == " " || chars[i - 1] == "\t", i + 1 < chars.count, !"=<>".contains(chars[i + 1]) {
1148 throw Unsupported("formula syntax")
1149 }
11451150 for (token, op) in [("==", "="), ("!=", "≠"), ("<=", "≤"), (">=", "≥"), ("<", "<"), (">", ">")] where take(token) {
11461151 let right = try sum()
11471152 if let next = peek(), "=!<>".contains(next) { throw Unsupported("chained comparison") }
Sources/OrgCore/Compute/CalcSymbolic.swift +12
@@ -26,6 +26,14 @@ extension Calc {
2626 /// `calc-prefer-frac`, for the division the arithmetic does.
2727 @TaskLocal static var fractions = false
2828
29 /// How deeply `mul` calls itself in one evaluation. Some products rewrite themselves
30 /// without end, where Calc stops at `max-lisp-eval-depth`; past `limit` they are refused.
31 final class Nesting: @unchecked Sendable {
32 static let limit = 64
33 var depth = 0
34 }
35 @TaskLocal static var nesting: Nesting?
36
2937 /// Variables Calc gives a value or a declaration, which would change the arithmetic.
3038 static let reserved: Set<String> = ["CommuteRules", "Decls", "DistribRules", "EvalRules", "FactorRules", "FitRules",
3139 "Holidays", "IntegAfterRules", "InvertRules", "JumpRules", "MergeRules", "Modes",
@@ -491,6 +499,10 @@ extension Calc {
491499
492500 /// `math-mul`.
493501 static func mul(_ a: Term, _ b: Term) throws -> Term {
502 let nesting = Calc.nesting
503 nesting?.depth += 1
504 defer { nesting?.depth -= 1 }
505 if let nesting, nesting.depth > Nesting.limit { throw Unsupported("symbolic arithmetic") }
494506 if let product = try numeric(a, b, { try multiply($0, $1) }) { return product }
495507 if zerop(a) { return try mulZero(a, b) }
496508 if zerop(b) { return try mulZero(b, a) }
Tests/OrgAppTests/AppTests.swift +10 −18
@@ -2,6 +2,7 @@ import Foundation
22import OrgCore
33import OrgDocument
44import OrgIndex
5import os
56import Testing
67@testable import OrgApp
78
@@ -595,32 +596,23 @@ struct AgendaModelTests {
595596 #expect(agenda.list.map(\.text) == ["TODO One"])
596597 }
597598
598 /// A refresh over cached files leaves the main actor free while it checks them on disk.
599 /// A refresh, the first and one over cached files, checks the files on disk off the main thread.
599600 @Test func checksFilesOffTheMainActor() async throws {
600601 let notes = try Folder()
601 for file in 0..<1_500 { try notes.write("f\(file).org", "* TODO Item\n") }
602 for file in 0..<20 { try notes.write("f\(file).org", "* TODO Item\n") }
602603 let model = try WorkspaceModel(directory: nil)
603604 try await model.addRoot(notes.url)
604605 let agenda = AgendaModel(workspace: model)
605606 agenda.mode = .todo(keywords: nil)
606 await agenda.refresh(open: [:])
607 let clock = ContinuousClock()
608 var longest = Duration.zero
609 let beat = Task { @MainActor in
610 var last = clock.now
611 while !Task.isCancelled {
612 await Task.yield()
613 longest = max(longest, clock.now - last)
614 last = clock.now
615 }
607 let stats = OSAllocatedUnfairLock(initialState: (all: 0, onMain: 0))
608 agenda.willStat = { _ in
609 let onMain = Thread.isMainThread
610 stats.withLock { $0 = ($0.all + 1, $0.onMain + (onMain ? 1 : 0)) }
616611 }
617 await Task.yield()
618 let start = clock.now
619612 await agenda.refresh(open: [:])
620 let took = clock.now - start
621 beat.cancel()
622 #expect(agenda.list.count == 1_500)
623 #expect(longest < took / 2, "main actor held for \(longest) of \(took)")
613 await agenda.refresh(open: [:])
614 #expect(agenda.list.count == 20)
615 #expect(stats.withLock { $0 } == (40, 0))
624616 }
625617
626618 @Test func entriesKnowTheirDoneKeyword() async throws {
Tests/OrgCoreTests/CalcNumericTests.swift +9 −7
@@ -5,7 +5,7 @@ import Testing
55struct CalcNumericTests {
66 /// A random real number up to `scale` digits before the point: an integer, a fraction or
77 /// a float, tiny to large.
8 static func argument(_ generator: inout SystemRandomNumberGenerator, scale: Int = 6) -> String {
8 static func argument(_ generator: inout SeededGenerator, scale: Int = 6) -> String {
99 let sign = Bool.random(using: &generator) ? "-" : ""
1010 let digits = Int.random(in: 1...9, using: &generator)
1111 let mantissa = String(Int.random(in: 1...999_999_999, using: &generator)).prefix(digits)
@@ -20,7 +20,7 @@ struct CalcNumericTests {
2020 }
2121
2222 /// A random number from -1 to 1.
23 static func unit(_ generator: inout SystemRandomNumberGenerator) -> String {
23 static func unit(_ generator: inout SeededGenerator) -> String {
2424 let sign = Bool.random(using: &generator) ? "-" : ""
2525 let mantissa = String(Int.random(in: 1...999_999_999, using: &generator)).prefix(Int.random(in: 1...9, using: &generator))
2626 switch Int.random(in: 0..<4, using: &generator) {
@@ -35,7 +35,8 @@ struct CalcNumericTests {
3535
3636 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
3737 func trigonometryMatchesCalc() throws {
38 var generator = SystemRandomNumberGenerator()
38 let seed = testSeed(20261122)
39 var generator = SeededGenerator(state: seed)
3940 for precision in [3, 6, 8, 12, 14, 15, 16, 17, 18] {
4041 for radians in [false, true] {
4142 var cases: [(String, String)] = ["sin(nan)", "cos(nan)", "arctan(nan)", "tan(180)", "tan(-360)", "tan(0)", "arcsin(0)",
@@ -66,9 +67,9 @@ struct CalcNumericTests {
6667 }
6768 continue
6869 }
69 #expect(ours == expected, "\(c.0) p\(precision) \(radians ? "rad" : "deg")")
70 #expect(ours == expected, "\(c.0) p\(precision) \(radians ? "rad" : "deg") seed \(seed)")
7071 }
71 #expect(refused == [], "p\(precision) \(radians ? "rad" : "deg") \(refused)")
72 #expect(refused == [], "p\(precision) \(radians ? "rad" : "deg") \(refused) seed \(seed)")
7273 }
7374 }
7475 }
@@ -89,7 +90,8 @@ struct CalcNumericTests {
8990
9091 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
9192 func fractionModeMatchesCalc() throws {
92 var generator = SystemRandomNumberGenerator()
93 let seed = testSeed(20261122)
94 var generator = SeededGenerator(state: seed)
9395 let numbers = ["0", "1", "2", "3", "-2", "7", "10", "12", "1:2", "1:3", "-5:4", "7:2", "-3:7", "0.5", "2.5", "-1.5", "0.25", "3.", "1.2e1",
9496 "100", "0.123456789", "0."]
9597 func number() -> String { numbers.randomElement(using: &generator)! }
@@ -113,7 +115,7 @@ struct CalcNumericTests {
113115 cases.append(("(\(number()))\(op)(\(number()))", "(float 12)"))
114116 }
115117 }
116 for fractions in [true, false] { _ = try CalcTests.compare(cases, fractions: fractions) }
118 for fractions in [true, false] { _ = try CalcTests.compare(cases, fractions: fractions, note: " seed \(seed)") }
117119 }
118120
119121 /// `math-mod` divides as a float, without F, unless both operands are natural numbers.
Tests/OrgCoreTests/CalcTests.swift +21 −13
@@ -269,7 +269,8 @@ struct CalcTests {
269269 for e in ["2/3", "3", "1.5", "1234.5678", "0.000123", "1e20*1", "-2/3", "1/7*100"] { cases.append((e, format)) }
270270 }
271271 // Generated: random operands and operators.
272 var generator = SystemRandomNumberGenerator()
272 let seed = testSeed(20261122)
273 var generator = SeededGenerator(state: seed)
273274 let numbers = ["1", "2", "3", "7", "10", "0.5", "1.25", "3.14159", "100", "0.001", "12.5", "99", "0.3", "1e3", "2.5e-2"]
274275 let ops = ["+", "-", "*", "/"]
275276 for _ in 0..<300 {
@@ -280,8 +281,8 @@ struct CalcTests {
280281 cases.append((e, "(float 8)"))
281282 }
282283 // Only what Calc itself can't show as a number.
283 let skipped = try Self.compare(cases)
284 #expect(skipped == [], "\(skipped)")
284 let skipped = try Self.compare(cases, note: " seed \(seed)")
285 #expect(skipped == [], "\(skipped) seed \(seed)")
285286 }
286287
287288 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
@@ -294,7 +295,8 @@ struct CalcTests {
294295 }
295296 // Generated: functions of random integers, fractions and floats. Arguments outside a
296297 // function's domain are refused, so only what is computed is compared.
297 var generator = SystemRandomNumberGenerator()
298 let seed = testSeed(20261122)
299 var generator = SeededGenerator(state: seed)
298300 let numbers = ["1", "2", "3", "7", "10", "0.5", "1.25", "3.14159", "100", "0.001", "12.5", "99", "1:3", "5:4", "2.5e-2"]
299301 let unary = ["sinh", "cosh", "tanh", "arcsinh", "rad", "deg", "frac", "sign", "rounde", "roundu", "float", "sqrt", "arctanh"]
300302 let binary = ["log", "hypot", "arctan2", "agmean", "nroot", "gcd", "lcm", "fdiv"]
@@ -305,13 +307,14 @@ struct CalcTests {
305307 cases.append(("\(binary.randomElement(using: &generator)!)(\(x),\(y))", "(float 12)"))
306308 cases.append(("vgmean([\(x),\(y),\(numbers.randomElement(using: &generator)!)])", "(float 12)"))
307309 }
308 let skipped = Set(try Self.compare(cases)).intersection(Self.functions + sample)
309 #expect(skipped == [], "\(skipped)")
310 let skipped = Set(try Self.compare(cases, note: " seed \(seed)")).intersection(Self.functions + sample)
311 #expect(skipped == [], "\(skipped) seed \(seed)")
310312 }
311313
312314 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
313315 func precisionMatchesCalc() throws {
314 var generator = SystemRandomNumberGenerator()
316 let seed = testSeed(20261122)
317 var generator = SeededGenerator(state: seed)
315318 let numbers = ["1", "2", "3", "7", "10", "0.5", "1.25", "3.14159", "100", "0.001", "12.5", "99", "0.3", "1e3", "2.5e-2",
316319 "1.23456789012345678", "123456789.987654321"]
317320 let ops = ["+", "-", "*", "/"]
@@ -347,8 +350,8 @@ struct CalcTests {
347350 }
348351 cases.append((e, "(float 0)"))
349352 }
350 let skipped = try Self.compare(cases, precision: precision)
351 #expect(skipped == [], "p\(precision) \(skipped)")
353 let skipped = try Self.compare(cases, precision: precision, note: " seed \(seed)")
354 #expect(skipped == [], "p\(precision) \(skipped) seed \(seed)")
352355 }
353356 }
354357
@@ -399,7 +402,8 @@ struct CalcTests {
399402 }
400403 // Generated: a variable or two mixed with numbers. What Calc would decide from more
401404 // than this arithmetic is refused, so only what is computed is compared.
402 var generator = SystemRandomNumberGenerator()
405 let seed = testSeed(20261122)
406 var generator = SeededGenerator(state: seed)
403407 let leaves = ["x", "x", "y", "1", "2", "3", "0", "0.5", "2.5", "1:3", "-1", "10", "inf", "a b"]
404408 let ops = ["+", "-", "*", "/", "^"]
405409 func expression(_ depth: Int) -> String {
@@ -410,9 +414,9 @@ struct CalcTests {
410414 return Int.random(in: 0..<6, using: &generator) == 0 ? "-\(e)" : e
411415 }
412416 for _ in 0..<2000 { cases.append((expression(4), "(float 8)")) }
413 let skipped = try Self.compare(cases)
417 let skipped = try Self.compare(cases, note: " seed \(seed)")
414418 #expect(Set(skipped).intersection(Self.symbolic) == [], "\(skipped)")
415 #expect(skipped.count < cases.count / 4, "\(skipped.count) of \(cases.count) refused")
419 #expect(skipped.count < cases.count / 4, "\(skipped.count) of \(cases.count) refused, seed \(seed)")
416420 }
417421
418422 /// Functions of formulas Calc simplifies, or keeps with their arguments.
@@ -448,7 +452,7 @@ struct CalcTests {
448452 }
449453 // Generated: the functions applied to formulas of a variable or two and numbers, and
450454 // their results combined again. What is refused is left to Emacs.
451 let seed = ProcessInfo.processInfo.environment["ORGSTAR_SEED"].flatMap { UInt64($0) } ?? UInt64.random(in: 0...UInt64.max)
455 let seed = testSeed(20261122)
452456 var generator = SeededGenerator(state: seed)
453457 let leaves = ["x", "x", "y", "1", "2", "3", "0", "0.5", "2.5", "1:3", "-1", "-2", "4", "inf", "e", "a b", "-inf", "uinf", "nan", "0.", "1.5e3", "-x", "2 x", "pi"]
454458 let unary = ["sqrt", "abs", "exp", "ln", "!", "-"]
@@ -500,6 +504,10 @@ struct CalcTests {
500504 "nroot(-8,3)", "vgmean([-1,2])", "vhmean([0,1])", "gcd(1.5,3)", "gcd(12,18,4)", "5%%3", "1:0", "1:2:3:4",
501505 "16#1.8", "16#FG", "2##11", "2.5!", "(-1)!", "(-3)!!", "choose(5.5,2)", "exp10(0.5)", "3!!!",
502506 "eq(1,1,1)", "percent(nan)", "frac(0.5,0.1)", "frac(1e-20)",
507 // Calc reads `<` after a space in a vector without commas as the start of a date.
508 "abs(vmin([(3 - uinf) ^ (-1)], [0. < (-1 > 2.5)]))", "vmin([1], [0 < (1 > 2)])", "vcount([0 <(1 > 2)])",
509 // Calc stops at `max-lisp-eval-depth`.
510 "2*(((-1)/0+1.)*(-24))",
503511 "(2..5)", "[2..5]", "vmax([1..5])", "vcount([1..5])", "2...5", "(-8)^(1:3)", "(-2)^1.5", "ln(0)", "ln(-1)",
504512 // Calc leaves these date expressions unevaluated.
505513 "<2026-10-05 Mon>*2", "2*<2026-10-05 Mon>", "<2026-10-05 Mon>/2", "<2026-10-05 Mon>*0", "<2026-10-05 Mon> < 5",
Tests/OrgCoreTests/ListItemScanTests.swift +6 −4
@@ -7,8 +7,10 @@ import Testing
77struct ListItemScanTests {
88 static let pieces = ["[@", "start:", "3", "12", "b", "B", "]", " ", "\t", "::", ":", "a", "é", "x y", "[", "\\n"]
99
10 static let seed = testSeed(20261122)
11
1012 static func strings() -> [Substring] {
11 var generator = SystemRandomNumberGenerator()
13 var generator = SeededGenerator(state: seed)
1214 var out: [Substring] = ["", "[@3]", "[@start:3] x", "[@b]", "[@start:]", "[@start:b]", "[@3", "[@ab]", "a :: b", "a ::", "a::b",
1315 "a :: b :: c", "a\t::\tb", " :: x", "::", "a ::b", "tag :: rest", "x :: y\nz :: w"]
1416 for _ in 0..<5000 {
@@ -21,7 +23,7 @@ struct ListItemScanTests {
2123 @Test func counterMatchesThePattern() {
2224 for s in Self.strings() {
2325 let expected = s.prefixMatch(of: /\[@(?:start:)?(?:[0-9]+|[A-Za-z])\]/).map { s[$0.range] }
24 #expect(Parser.counter(s) == expected, "\(s.debugDescription)")
26 #expect(Parser.counter(s) == expected, "\(s.debugDescription) seed \(Self.seed)")
2527 }
2628 }
2729
@@ -29,8 +31,8 @@ struct ListItemScanTests {
2931 for s in Self.strings() {
3032 let m = s.prefixMatch(of: /(.*)([ \t]+::)(?:[ \t]+|$)/.anchorsMatchLineEndings())
3133 let found = Parser.descriptionTag(s)
32 #expect(found?.tag == m.map { s[$0.1.startIndex..<$0.1.endIndex] }, "\(s.debugDescription)")
33 #expect(found?.separator == m.map { s[$0.2.startIndex..<$0.2.endIndex] }, "\(s.debugDescription)")
34 #expect(found?.tag == m.map { s[$0.1.startIndex..<$0.1.endIndex] }, "\(s.debugDescription) seed \(Self.seed)")
35 #expect(found?.separator == m.map { s[$0.2.startIndex..<$0.2.endIndex] }, "\(s.debugDescription) seed \(Self.seed)")
3436 }
3537 }
3638}
Tests/OrgCoreTests/RoundTripTests.swift +5
@@ -14,6 +14,11 @@ struct SeededGenerator: RandomNumberGenerator {
1414 }
1515}
1616
17/// `ORGSTAR_SEED` when set, else `fallback`, so random tests repeat unless asked to vary.
18func testSeed(_ fallback: UInt64) -> UInt64 {
19 ProcessInfo.processInfo.environment["ORGSTAR_SEED"].flatMap { UInt64($0) } ?? fallback
20}
21
1722let fragments = [
1823 "* ", "** TODO [#A] title :a:b:", "*** DONE", "#+TODO: NEXT | DONE", "#+begin_src sh", "#+end_src",
1924 "#+BEGIN_QUOTE", "#+end_quote", "#+BEGIN: clocktable", "#+END:", ":PROPERTIES:", ":ID: x", ":END:",
Tests/OrgEditorAppKitTests/LineIndexTests.swift +23 −4
@@ -3,6 +3,23 @@ import Testing
33import OrgPresentation
44@testable import OrgEditorAppKit
55
6/// SplitMix64, so failures reproduce from the seed.
7struct SeededGenerator: RandomNumberGenerator {
8 var state: UInt64
9 mutating func next() -> UInt64 {
10 state &+= 0x9E37_79B9_7F4A_7C15
11 var z = state
12 z = (z ^ (z >> 30)) &* 0xBF58_476D_1CE4_E5B9
13 z = (z ^ (z >> 27)) &* 0x94D0_49BB_1331_11EB
14 return z ^ (z >> 31)
15 }
16}
17
18/// `ORGSTAR_SEED` when set, else `fallback`, so random tests repeat unless asked to vary.
19func testSeed(_ fallback: UInt64) -> UInt64 {
20 ProcessInfo.processInfo.environment["ORGSTAR_SEED"].flatMap { UInt64($0) } ?? fallback
21}
22
623struct LineIndexTests {
724 func naive(_ text: String) -> [Int] {
825 var starts = [0]
@@ -11,7 +28,8 @@ struct LineIndexTests {
1128 }
1229
1330 @Test func followsRandomEdits() {
14 var generator = SystemRandomNumberGenerator()
31 let seed = testSeed(20261122)
32 var generator = SeededGenerator(state: seed)
1533 let pieces = ["a", "bc\n", "\n", "\n\n", "xyz", "é\n", "😀", ""]
1634 var text = "first\nsecond\n\nthird"
1735 let index = LineIndex(text as NSString)
@@ -22,7 +40,7 @@ struct LineIndexTests {
2240 let replacement = pieces.randomElement(using: &generator)!
2341 text = ns.replacingCharacters(in: NSRange(location: start, length: end - start), with: replacement)
2442 index.replace(start..<end, newLength: (replacement as NSString).length, in: text as NSString)
25 #expect(index.starts == naive(text))
43 #expect(index.starts == naive(text), "seed \(seed)")
2644 if index.starts != naive(text) { return }
2745 }
2846 #expect(index.line(of: 0) == 1)
@@ -34,7 +52,8 @@ struct LineIndexTests {
3452struct ShadedBlockTests {
3553 /// Bands after edits match a full search once typing settles.
3654 @Test func incrementalMatchesFull() {
37 var generator = SystemRandomNumberGenerator()
55 let seed = testSeed(20261122)
56 var generator = SeededGenerator(state: seed)
3857 let pieces = ["x", "word ", "\n", "#+begin_src sh\n", "#+end_src\n", ": fixed\n", "* H\n", "#+begin_quote\n", "#+end_quote\n", ""]
3958 let h = Harness("* A\n#+begin_src sh\nls\n#+end_src\ntext\n: one\n* B\nbody\n")
4059 for _ in 0..<400 {
@@ -45,7 +64,7 @@ struct ShadedBlockTests {
4564 h.textView.insertText(piece, replacementRange: NSRange(location: start, length: end - start))
4665 h.editor.settleBlocks()
4766 let full = Presentation.shadedBlocks(h.editor.document.tree)
48 #expect(h.editor.shaded.all == full, "\(h.editor.document.text)")
67 #expect(h.editor.shaded.all == full, "\(h.editor.document.text) seed \(seed)")
4968 if h.editor.shaded.all != full { return }
5069 }
5170 }