@@ -270,7 +270,7 @@ describe("string utils", () => {
270270 ) ;
271271 } ) ;
272272
273- describe ( "getWordDirection " , ( ) => {
273+ describe ( "isWordRightToLeft " , ( ) => {
274274 beforeEach ( ( ) => {
275275 Strings . clearWordDirectionCache ( ) ;
276276 } ) ;
@@ -321,13 +321,27 @@ describe("string utils", () => {
321321 languageRTL : boolean ,
322322 _description : string
323323 ) => {
324- expect ( Strings . getWordDirection ( word , languageRTL ) ) . toBe ( expected ) ;
324+ expect ( Strings . isWordRightToLeft ( word , languageRTL ) ) . toBe ( expected ) ;
325325 }
326326 ) ;
327327
328328 it ( "should return languageRTL for undefined word" , ( ) => {
329- expect ( Strings . getWordDirection ( undefined , false ) ) . toBe ( false ) ;
330- expect ( Strings . getWordDirection ( undefined , true ) ) . toBe ( true ) ;
329+ expect ( Strings . isWordRightToLeft ( undefined , false ) ) . toBe ( false ) ;
330+ expect ( Strings . isWordRightToLeft ( undefined , true ) ) . toBe ( true ) ;
331+ } ) ;
332+
333+ // testing reverseDirection
334+ it ( "should return true for LTR word with reversed direction" , ( ) => {
335+ expect ( Strings . isWordRightToLeft ( "hello" , false , true ) ) . toBe ( true ) ;
336+ expect ( Strings . isWordRightToLeft ( "hello" , true , true ) ) . toBe ( true ) ;
337+ } ) ;
338+ it ( "should return false for RTL word with reversed direction" , ( ) => {
339+ expect ( Strings . isWordRightToLeft ( "مرحبا" , true , true ) ) . toBe ( false ) ;
340+ expect ( Strings . isWordRightToLeft ( "مرحبا" , false , true ) ) . toBe ( false ) ;
341+ } ) ;
342+ it ( "should return reverse of languageRTL for undefined word with reversed direction" , ( ) => {
343+ expect ( Strings . isWordRightToLeft ( undefined , false , true ) ) . toBe ( true ) ;
344+ expect ( Strings . isWordRightToLeft ( undefined , true , true ) ) . toBe ( false ) ;
331345 } ) ;
332346
333347 describe ( "caching" , ( ) => {
@@ -349,7 +363,7 @@ describe("string utils", () => {
349363
350364 it ( "should use cache for repeated calls" , ( ) => {
351365 // First call should cache the result (cache miss)
352- const result1 = Strings . getWordDirection ( "hello" , false ) ;
366+ const result1 = Strings . isWordRightToLeft ( "hello" , false ) ;
353367 expect ( result1 ) . toBe ( false ) ;
354368 expect ( mapSetSpy ) . toHaveBeenCalledWith ( "hello" , false ) ;
355369
@@ -358,7 +372,7 @@ describe("string utils", () => {
358372 mapSetSpy . mockClear ( ) ;
359373
360374 // Second call should use cache (cache hit)
361- const result2 = Strings . getWordDirection ( "hello" , false ) ;
375+ const result2 = Strings . isWordRightToLeft ( "hello" , false ) ;
362376 expect ( result2 ) . toBe ( false ) ;
363377 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "hello" ) ;
364378 expect ( mapSetSpy ) . not . toHaveBeenCalled ( ) ; // Should not set again
@@ -367,47 +381,47 @@ describe("string utils", () => {
367381 mapGetSpy . mockClear ( ) ;
368382 mapSetSpy . mockClear ( ) ;
369383
370- const result3 = Strings . getWordDirection ( "hello" , true ) ;
384+ const result3 = Strings . isWordRightToLeft ( "hello" , true ) ;
371385 expect ( result3 ) . toBe ( false ) ; // Still false because "hello" is LTR regardless of language
372386 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "hello" ) ;
373387 expect ( mapSetSpy ) . not . toHaveBeenCalled ( ) ; // Should not set again
374388 } ) ;
375389
376390 it ( "should cache based on core word without punctuation" , ( ) => {
377391 // First call should cache the result for core "hello"
378- const result1 = Strings . getWordDirection ( "hello" , false ) ;
392+ const result1 = Strings . isWordRightToLeft ( "hello" , false ) ;
379393 expect ( result1 ) . toBe ( false ) ;
380394 expect ( mapSetSpy ) . toHaveBeenCalledWith ( "hello" , false ) ;
381395
382396 mapGetSpy . mockClear ( ) ;
383397 mapSetSpy . mockClear ( ) ;
384398
385399 // These should all use the same cache entry since they have the same core
386- const result2 = Strings . getWordDirection ( "hello!" , false ) ;
400+ const result2 = Strings . isWordRightToLeft ( "hello!" , false ) ;
387401 expect ( result2 ) . toBe ( false ) ;
388402 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "hello" ) ;
389403 expect ( mapSetSpy ) . not . toHaveBeenCalled ( ) ;
390404
391405 mapGetSpy . mockClear ( ) ;
392406 mapSetSpy . mockClear ( ) ;
393407
394- const result3 = Strings . getWordDirection ( "!hello" , false ) ;
408+ const result3 = Strings . isWordRightToLeft ( "!hello" , false ) ;
395409 expect ( result3 ) . toBe ( false ) ;
396410 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "hello" ) ;
397411 expect ( mapSetSpy ) . not . toHaveBeenCalled ( ) ;
398412
399413 mapGetSpy . mockClear ( ) ;
400414 mapSetSpy . mockClear ( ) ;
401415
402- const result4 = Strings . getWordDirection ( "!hello!" , false ) ;
416+ const result4 = Strings . isWordRightToLeft ( "!hello!" , false ) ;
403417 expect ( result4 ) . toBe ( false ) ;
404418 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "hello" ) ;
405419 expect ( mapSetSpy ) . not . toHaveBeenCalled ( ) ;
406420 } ) ;
407421
408422 it ( "should handle cache clearing" , ( ) => {
409423 // Cache a result
410- Strings . getWordDirection ( "test" , false ) ;
424+ Strings . isWordRightToLeft ( "test" , false ) ;
411425 expect ( mapSetSpy ) . toHaveBeenCalledWith ( "test" , false ) ;
412426
413427 // Clear cache
@@ -419,14 +433,14 @@ describe("string utils", () => {
419433 mapClearSpy . mockClear ( ) ;
420434
421435 // Should work normally after cache clear (cache miss again)
422- const result = Strings . getWordDirection ( "test" , false ) ;
436+ const result = Strings . isWordRightToLeft ( "test" , false ) ;
423437 expect ( result ) . toBe ( false ) ;
424438 expect ( mapSetSpy ) . toHaveBeenCalledWith ( "test" , false ) ;
425439 } ) ;
426440
427441 it ( "should demonstrate cache miss vs cache hit behavior" , ( ) => {
428442 // Test cache miss - first time seeing this word
429- const result1 = Strings . getWordDirection ( "unique" , false ) ;
443+ const result1 = Strings . isWordRightToLeft ( "unique" , false ) ;
430444 expect ( result1 ) . toBe ( false ) ;
431445 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "unique" ) ;
432446 expect ( mapSetSpy ) . toHaveBeenCalledWith ( "unique" , false ) ;
@@ -435,7 +449,7 @@ describe("string utils", () => {
435449 mapSetSpy . mockClear ( ) ;
436450
437451 // Test cache hit - same word again
438- const result2 = Strings . getWordDirection ( "unique" , false ) ;
452+ const result2 = Strings . isWordRightToLeft ( "unique" , false ) ;
439453 expect ( result2 ) . toBe ( false ) ;
440454 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "unique" ) ;
441455 expect ( mapSetSpy ) . not . toHaveBeenCalled ( ) ; // No cache set on hit
@@ -444,7 +458,7 @@ describe("string utils", () => {
444458 mapSetSpy . mockClear ( ) ;
445459
446460 // Test cache miss - different word
447- const result3 = Strings . getWordDirection ( "different" , false ) ;
461+ const result3 = Strings . isWordRightToLeft ( "different" , false ) ;
448462 expect ( result3 ) . toBe ( false ) ;
449463 expect ( mapGetSpy ) . toHaveBeenCalledWith ( "different" ) ;
450464 expect ( mapSetSpy ) . toHaveBeenCalledWith ( "different" , false ) ;
0 commit comments