aboutsummaryrefslogtreecommitdiff
path: root/Tests/barTests/BlockRefreshTests.swift
blob: 495bcac0c169253b33b283ad60685f8daa316f47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Combine
import Testing
@testable import bar

@Test @MainActor func unchangedOutputDoesNotPublish() {
	let block = Block(name: "test", placement: .left, command: "")
	var publications = 0
	let subscription = block.$cells.dropFirst().sink { _ in publications += 1 }
	defer { subscription.cancel() }

	block.apply(["same", "same"])
	block.apply(["same", "same"])
	#expect(publications == 1)
	#expect(block.cells.map(\.rawValue) == ["same", "same"])

	// A highlight-only change must still publish, even with identical text.
	block.apply(["&!1 same", "same"])
	#expect(publications == 2)
	#expect(block.cells[0].id == " same:1")
	block.apply([])
	block.apply([])
	#expect(publications == 3)
	#expect(block.cells.isEmpty)
}

@Test func runnerPreservesOutputAcrossPoolDrain() {
	#expect(Runner.run("printf 'first\\n\\nlast\\n'") == ["first", "", "last"])
	#expect(Runner.run("exit 1") == ["ERROR"])
}