@@ -32,7 +32,12 @@ import {
3232 toRomanNumerals ,
3333 validateCSSFont ,
3434} from "../../src/core/core_utils.js" ;
35- import { Dict , Ref } from "../../src/core/primitives.js" ;
35+ import {
36+ clearPrimitiveCaches ,
37+ Dict ,
38+ Name ,
39+ Ref ,
40+ } from "../../src/core/primitives.js" ;
3641import { XRefMock } from "./test_utils.js" ;
3742
3843describe ( "core_utils" , function ( ) {
@@ -499,6 +504,20 @@ describe("core_utils", function () {
499504 expect ( deepCompare ( a , b ) ) . toBeTrue ( ) ;
500505 } ) ;
501506
507+ it ( "should return true for Dicts with same Ref values, after clearing cached Refs" , function ( ) {
508+ const refA = Ref . get ( 10 , 0 ) ;
509+ clearPrimitiveCaches ( ) ;
510+ const refB = Ref . get ( 10 , 0 ) ;
511+ // Ensure that Ref-objects are not identical, after clearing the cache.
512+ expect ( refA ) . not . toBe ( refB ) ;
513+
514+ const a = new Dict ( ) ;
515+ a . set ( "Foo" , refA ) ;
516+ const b = new Dict ( ) ;
517+ b . set ( "Foo" , refB ) ;
518+ expect ( deepCompare ( a , b ) ) . toBeTrue ( ) ;
519+ } ) ;
520+
502521 it ( "should return false for Dicts with different Ref values" , function ( ) {
503522 const a = new Dict ( ) ;
504523 a . set ( "Foo" , Ref . get ( 10 , 0 ) ) ;
@@ -556,6 +575,30 @@ describe("core_utils", function () {
556575 it ( "should return false for arrays with different values" , function ( ) {
557576 expect ( deepCompare ( [ Ref . get ( 1 , 0 ) ] , [ Ref . get ( 2 , 0 ) ] ) ) . toBeFalse ( ) ;
558577 } ) ;
578+
579+ it ( "should return true for equal Names" , function ( ) {
580+ const name1 = Name . get ( "name" ) ,
581+ name2 = Name . get ( "name" ) ;
582+ expect ( name1 ) . toBe ( name2 ) ; // Names are cached.
583+
584+ expect ( deepCompare ( name1 , name2 ) ) . toBeTrue ( ) ;
585+ } ) ;
586+
587+ it ( "should return false for different Names" , function ( ) {
588+ const name1 = Name . get ( "name" ) ,
589+ name2 = Name . get ( "otherName" ) ;
590+ expect ( deepCompare ( name1 , name2 ) ) . toBeFalse ( ) ;
591+ } ) ;
592+
593+ it ( "should return true for equal Names, after clearing cached Names" , function ( ) {
594+ const name1 = Name . get ( "name" ) ;
595+ clearPrimitiveCaches ( ) ;
596+ const name2 = Name . get ( "name" ) ;
597+ // Ensure that Name-objects are not identical, after clearing the cache.
598+ expect ( name1 ) . not . toBe ( name2 ) ;
599+
600+ expect ( deepCompare ( name1 , name2 ) ) . toBeTrue ( ) ;
601+ } ) ;
559602 } ) ;
560603
561604 describe ( "getModificationDate" , function ( ) {
0 commit comments