@@ -307,4 +307,60 @@ suite('LogtalkRenameProvider Test Suite', () => {
307307 // Should NOT find 'member(+term, ?list)' because it's looking for indicator format
308308 assert . strictEqual ( ranges . length , 0 ) ;
309309 } ) ;
310+
311+ // Tests for character code notation handling (0'Char)
312+ test ( 'countSingleQuotesExcludingCharCodes - no quotes' , ( ) => {
313+ const count = ( renameProvider as any ) . countSingleQuotesExcludingCharCodes ( 'hello world' ) ;
314+ assert . strictEqual ( count , 0 ) ;
315+ } ) ;
316+
317+ test ( 'countSingleQuotesExcludingCharCodes - regular quoted atom' , ( ) => {
318+ const count = ( renameProvider as any ) . countSingleQuotesExcludingCharCodes ( "'hello'" ) ;
319+ assert . strictEqual ( count , 2 ) ;
320+ } ) ;
321+
322+ test ( 'countSingleQuotesExcludingCharCodes - character code notation 0\'0' , ( ) => {
323+ // Character code notation should not count the quote
324+ const count = ( renameProvider as any ) . countSingleQuotesExcludingCharCodes ( "Code >= 0'0, Code =< 0'9" ) ;
325+ assert . strictEqual ( count , 0 ) ;
326+ } ) ;
327+
328+ test ( 'countSingleQuotesExcludingCharCodes - character code with escape sequence' , ( ) => {
329+ // Character code with escape like 0'\n should not count the quote
330+ const count = ( renameProvider as any ) . countSingleQuotesExcludingCharCodes ( "Code = 0'\\n" ) ;
331+ assert . strictEqual ( count , 0 ) ;
332+ } ) ;
333+
334+ test ( 'countSingleQuotesExcludingCharCodes - mixed quotes and char codes' , ( ) => {
335+ // Mix of quoted atoms and character codes
336+ const count = ( renameProvider as any ) . countSingleQuotesExcludingCharCodes ( "'atom', 0'x, 'another'" ) ;
337+ assert . strictEqual ( count , 4 ) ; // 2 for 'atom' + 2 for 'another', 0 for 0'x
338+ } ) ;
339+
340+ test ( 'isValidVariableContextInLine - variable after character code notation' , ( ) => {
341+ // Variable Code after 0'0 should be in valid context (not inside quotes)
342+ const isValid = ( renameProvider as any ) . isValidVariableContextInLine (
343+ "hex_digit(Code, Value) :- Code >= 0'0, Code =< 0'9, !, Value is Code - 0'0." ,
344+ 61 , 65 // Position of the last "Code" before "- 0'0"
345+ ) ;
346+ assert . strictEqual ( isValid , true ) ;
347+ } ) ;
348+
349+ test ( 'isValidVariableContextInLine - variable between character codes' , ( ) => {
350+ // Variable Code between 0'0 and 0'9 should be in valid context
351+ const isValid = ( renameProvider as any ) . isValidVariableContextInLine (
352+ "hex_digit(Code, Value) :- Code >= 0'0, Code =< 0'9, !, Value is Code - 0'0." ,
353+ 39 , 43 // Position of "Code" in "Code =< 0'9"
354+ ) ;
355+ assert . strictEqual ( isValid , true ) ;
356+ } ) ;
357+
358+ test ( 'isValidVariableContextInLine - variable inside actual quoted atom should be invalid' , ( ) => {
359+ // Variable inside a quoted atom should not be valid
360+ const isValid = ( renameProvider as any ) . isValidVariableContextInLine (
361+ "test('Code is here', Code)." ,
362+ 6 , 10 // Position of "Code" inside the quoted atom
363+ ) ;
364+ assert . strictEqual ( isValid , false ) ;
365+ } ) ;
310366} ) ;
0 commit comments