From 331201e287b62c02e4c5cbdc7d1e97cffa6748cf Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Wed, 13 May 2026 06:37:14 +0200 Subject: [PATCH] test sweep: cover src/editor/ tail paths (T-91) Adds 6 tests in test/editor/registry_test.dart closing out the EditorRegistry methods the existing suite didn't reach: - activate(id): unknown id is a no-op (no event emitted); known id flips the active buffer and emits editor.active-changed. - setContent(id, content, selection?): explicit selection clamped to new content length, missing selection falls back to clamping the existing one, missing id is a silent no-op. Each emits the editor.edited replace event. - contentFromArgs(args): the content_b64 fallback when text is absent, plus the empty-args default. - Selection.hashCode + .toString. Coverage: src/editor/buffer.dart 20/24 -> 24/24; src/editor/registry .dart 87/105 -> 105/105. Both at 100%. Total coverage 74.79% -> 75.11%; floor bumped to 75. Co-Authored-By: Claude Opus 4.7 (1M context) --- pubspec.yaml | 2 +- test/editor/registry_test.dart | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 4d0aa330..794c6130 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ repository: https://github.com/postmeridiem/clide # Pre-push line-coverage floor. Ratchets up only — see D-66. # Reading: `awk -F: '/^coverage_floor:/ {gsub(/ /,"",$2); print $2}' pubspec.yaml`. -coverage_floor: 74 +coverage_floor: 75 # Project metadata (was project.yaml, folded in per D-056). # version: above is the single source of truth. The Makefile reads diff --git a/test/editor/registry_test.dart b/test/editor/registry_test.dart index e46d3dba..8be218a4 100644 --- a/test/editor/registry_test.dart +++ b/test/editor/registry_test.dart @@ -93,4 +93,62 @@ void main() { expect(buf.content, isEmpty); expect(buf.dirty, isFalse); }); + + test('activate(unknown id) is a no-op; activate(known) flips the active buffer', () async { + final a = await reg.open('README.md'); + final b = await reg.open('NEW.md'); + // b is currently active. + expect(reg.active, same(b)); + sink.events.clear(); + reg.activate('does-not-exist'); // no-op, no emit + expect(sink.ofKind('editor.active-changed'), isEmpty); + reg.activate(a.id); + expect(reg.active, same(a)); + expect(sink.ofKind('editor.active-changed'), hasLength(1)); + }); + + test('setContent with explicit selection clamps + emits editor.edited replace', () async { + final buf = await reg.open('README.md'); + sink.events.clear(); + reg.setContent(buf.id, 'short', selection: const Selection(start: 1, end: 99)); + expect(buf.content, 'short'); + // 99 clamped to content.length (5). + expect(buf.selection.end, 5); + expect(buf.dirty, isTrue); + final emitted = sink.ofKind('editor.edited').single; + expect(emitted.data['kind'], 'replace'); + expect(emitted.data['length'], 5); + }); + + test('setContent without selection clamps the existing selection to the new content', () async { + final buf = await reg.open('README.md'); + reg.setSelection(buf.id, const Selection(start: 6, end: 8)); + expect(buf.selection.start, 6); + reg.setContent(buf.id, 'XY'); // shorter than the selection's offsets + expect(buf.content, 'XY'); + expect(buf.selection.start, 2); + expect(buf.selection.end, 2); + }); + + test('setContent on a missing id is a silent no-op', () { + sink.events.clear(); + reg.setContent('no-such-id', 'whatever'); + expect(sink.events, isEmpty); + }); + + test('contentFromArgs decodes content_b64 when text is absent', () { + expect(EditorRegistry.contentFromArgs({'text': 'plain'}), 'plain'); + expect( + EditorRegistry.contentFromArgs({'content_b64': 'aGVsbG8='}), + 'hello', + ); + expect(EditorRegistry.contentFromArgs(const {}), ''); + }); + + test('Selection hashCode + toString round-trip and serialise', () { + const s = Selection(start: 3, end: 7); + expect(s.hashCode, const Selection(start: 3, end: 7).hashCode); + expect(s.hashCode, isNot(equals(const Selection(start: 3, end: 8).hashCode))); + expect(s.toString(), 'Selection(3-7)'); + }); }