@@ -6,6 +6,7 @@ import * as assert from 'assert';
66import * as vscode from 'vscode' ;
77import * as J from '../..' ;
88import { TestLogger } from '../test-logger' ;
9+ import { SCOPE_DEFAULT } from '../../model/config' ;
910
1011suite ( 'Open Journal Entries' , ( ) => {
1112 vscode . window . showInformationMessage ( 'Start all tests.' ) ;
@@ -219,3 +220,53 @@ suite('Issue #170 — weekday/month/shortcut prefix collisions', () => {
219220 } ) ;
220221
221222} ) ;
223+
224+ suite ( 'NoteInput.extractScopeAndTags (#210)' , ( ) => {
225+
226+ test ( "noTags: text without tags stays unchanged, scope defaults" , ( ) => {
227+ const input = new J . Model . NoteInput ( ) ;
228+ input . text = "my note" ;
229+ input . extractScopeAndTags ( [ ] ) ;
230+ assert . strictEqual ( input . scope , SCOPE_DEFAULT ) ;
231+ assert . deepStrictEqual ( input . tags , [ ] ) ;
232+ assert . strictEqual ( input . text , "my note" ) ;
233+ } ) ;
234+
235+ test ( "namedScopeMatch: matching tag sets scope, strips from text" , ( ) => {
236+ const input = new J . Model . NoteInput ( ) ;
237+ input . text = "my note #work " ;
238+ input . extractScopeAndTags ( [ "work" ] ) ;
239+ assert . strictEqual ( input . scope , "work" ) ;
240+ assert . deepStrictEqual ( input . tags , [ "#work" ] ) ;
241+ assert . ok ( ! input . text . includes ( "#work" ) , "tag should be stripped from text" ) ;
242+ } ) ;
243+
244+ test ( "noScopeMatch: unknown tag collected but scope stays default" , ( ) => {
245+ const input = new J . Model . NoteInput ( ) ;
246+ input . text = "my note #unknown " ;
247+ input . extractScopeAndTags ( [ "work" ] ) ;
248+ assert . strictEqual ( input . scope , SCOPE_DEFAULT ) ;
249+ assert . deepStrictEqual ( input . tags , [ "#unknown" ] ) ;
250+ assert . ok ( ! input . text . includes ( "#unknown" ) , "tag should be stripped from text" ) ;
251+ } ) ;
252+
253+ test ( "multipleTags: both tags collected, first matching scope wins" , ( ) => {
254+ const input = new J . Model . NoteInput ( ) ;
255+ input . text = "note #work #meeting " ;
256+ input . extractScopeAndTags ( [ "work" ] ) ;
257+ assert . strictEqual ( input . scope , "work" ) ;
258+ assert . deepStrictEqual ( input . tags , [ "#work" , "#meeting" ] ) ;
259+ assert . ok ( ! input . text . includes ( "#work" ) , "#work should be stripped" ) ;
260+ assert . ok ( ! input . text . includes ( "#meeting" ) , "#meeting should be stripped" ) ;
261+ } ) ;
262+
263+ test ( "tagAtEndOfString: tag without trailing space is matched (regex fix)" , ( ) => {
264+ const input = new J . Model . NoteInput ( ) ;
265+ input . text = "note #work" ;
266+ input . extractScopeAndTags ( [ "work" ] ) ;
267+ assert . strictEqual ( input . scope , "work" ) ;
268+ assert . deepStrictEqual ( input . tags , [ "#work" ] ) ;
269+ assert . ok ( ! input . text . includes ( "#work" ) , "tag should be stripped from text" ) ;
270+ } ) ;
271+
272+ } ) ;
0 commit comments