@@ -33,6 +33,14 @@ import { WriteTags } from "./WriteTags";
33
33
34
34
describe ( "WriteTask" , function ( ) {
35
35
this . slow ( 1 ) ; // always show timings
36
+
37
+ const ImageExifData = {
38
+ UserComment : "This is a user comment added by exiftool." ,
39
+ Artist : "Arturo DeImage" ,
40
+ Copyright : "© Chuckles McSnortypants, Inc." ,
41
+ Credit : "photo by Jenny Snapsalot" ,
42
+ } ;
43
+
36
44
for ( const opts of [
37
45
{ maxProcs : 1 , maxRetries : 0 , useMWG : true } ,
38
46
{ maxProcs : 3 , maxRetries : 3 , useMWG : false } ,
@@ -101,7 +109,7 @@ describe("WriteTask", function () {
101
109
} ) ;
102
110
} ) ;
103
111
104
- type InputValue = string | number | Struct | ResourceEvent ;
112
+ type InputValue = string | number | Struct | ResourceEvent | boolean ;
105
113
106
114
async function assertRoundTrip ( {
107
115
dest,
@@ -324,6 +332,28 @@ describe("WriteTask", function () {
324
332
return ;
325
333
} ) ;
326
334
335
+ it ( "round-trips a boolean true value" , async ( ) => {
336
+ const file = await dest ( ) ;
337
+ // Using a native boolean tag
338
+ return assertRoundTrip ( {
339
+ dest : file ,
340
+ tagName : "AlreadyApplied" ,
341
+ inputValue : true ,
342
+ expectedValue : true ,
343
+ } ) ;
344
+ } ) ;
345
+
346
+ it ( "round-trips a boolean false value" , async ( ) => {
347
+ const file = await dest ( ) ;
348
+ // Using a native boolean tag
349
+ return assertRoundTrip ( {
350
+ dest : file ,
351
+ tagName : "AlreadyApplied" ,
352
+ inputValue : false ,
353
+ expectedValue : false ,
354
+ } ) ;
355
+ } ) ;
356
+
327
357
function randomFloat ( min : number , max : number ) {
328
358
return Math . random ( ) * ( max - min ) + min ;
329
359
}
@@ -418,6 +448,17 @@ describe("WriteTask", function () {
418
448
) . to . match ( / V a l u e b e l o w i n t 1 6 u m i n i m u m / i) ;
419
449
} ) ;
420
450
451
+ it ( "rejects an invalid string Orientation" , async ( ) => {
452
+ const src = await dest ( ) ;
453
+ expect (
454
+ (
455
+ await exiftool . write ( src , {
456
+ Orientation : "this isn't a valid orientation" ,
457
+ } )
458
+ ) . warnings ?. join ( "\n" ) ,
459
+ ) . to . be . match ( / C a n ' t c o n v e r t I F D 0 : O r i e n t a t i o n / i) ;
460
+ } ) ;
461
+
421
462
it ( "tags case-insensitively" , async ( ) => {
422
463
const src = await dest ( ) ;
423
464
await exiftool . write ( src , { rating : 12 } as any , [
@@ -441,17 +482,6 @@ describe("WriteTask", function () {
441
482
) . to . match ( / I m a g e O f f s e t i s n o t w r i t a b l e / i) ;
442
483
} ) ;
443
484
444
- it ( "rejects an invalid string Orientation" , async ( ) => {
445
- const src = await dest ( ) ;
446
- expect (
447
- (
448
- await exiftool . write ( src , {
449
- Orientation : "this isn't a valid orientation" ,
450
- } )
451
- ) . warnings ?. join ( "\n" ) ,
452
- ) . to . be . match ( / C a n ' t c o n v e r t I F D 0 : O r i e n t a t i o n / i) ;
453
- } ) ;
454
-
455
485
it ( "handles deleting tags from empty files" , async ( ) => {
456
486
const src = await dest ( ) ;
457
487
const isSidecar = isSidecarExt ( src ) ;
@@ -757,13 +787,6 @@ describe("WriteTask", function () {
757
787
const exiftool = new ExifTool ( ) ;
758
788
after ( ( ) => end ( exiftool ) ) ;
759
789
760
- const exp = {
761
- UserComment : "This is a user comment added by exiftool." ,
762
- Artist : "Arturo DeImage" ,
763
- Copyright : "© Chuckles McSnortypants, Inc." ,
764
- Credit : "photo by Jenny Snapsalot" ,
765
- } ;
766
-
767
790
const expectedDefinedTags = [
768
791
"Make" ,
769
792
"Model" ,
@@ -820,13 +843,14 @@ describe("WriteTask", function () {
820
843
it ( "deletes all tags by default" , async ( ) => {
821
844
const img = await testImg ( { srcBasename : "oly.jpg" } ) ;
822
845
const before = await exiftool . read ( img ) ;
823
- expect ( before ) . to . containSubset ( exp ) ;
846
+
847
+ expect ( before ) . to . containSubset ( ImageExifData ) ;
824
848
assertDefinedGeneralTags ( before ) ;
825
849
await exiftool . deleteAllTags ( img ) ;
826
850
const after = await exiftool . read ( img ) ;
827
851
assertMissingGeneralTags ( after ) ;
828
- expect ( after ) . to . not . containSubset ( exp ) ;
829
- for ( const k in exp ) {
852
+ expect ( after ) . to . not . containSubset ( ImageExifData ) ;
853
+ for ( const k in ImageExifData ) {
830
854
expect ( after ) . to . not . haveOwnProperty ( k ) ;
831
855
}
832
856
// And make sure everything else is gone:
@@ -840,17 +864,17 @@ describe("WriteTask", function () {
840
864
}
841
865
} ) ;
842
866
843
- for ( const key in exp ) {
867
+ for ( const key in ImageExifData ) {
844
868
it ( `deletes all tags except ${ key } ` , async ( ) => {
845
869
const img = await testImg ( { srcBasename : "oly.jpg" } ) ;
846
870
const before = await exiftool . read ( img ) ;
847
- expect ( before ) . to . containSubset ( exp ) ;
871
+ expect ( before ) . to . containSubset ( ImageExifData ) ;
848
872
assertDefinedGeneralTags ( before ) ;
849
873
await exiftool . deleteAllTags ( img , { retain : [ key ] } ) ;
850
874
const after = await exiftool . read ( img ) ;
851
875
assertMissingGeneralTags ( after ) ;
852
876
expect ( after ) . to . haveOwnProperty ( key ) ;
853
- for ( const k in Object . keys ( exp ) ) {
877
+ for ( const k in Object . keys ( ImageExifData ) ) {
854
878
if ( k !== key ) {
855
879
expect ( after ) . to . not . haveOwnProperty ( k ) ;
856
880
}
@@ -860,12 +884,12 @@ describe("WriteTask", function () {
860
884
it ( "supports deleting everything-except (issue #178)" , async ( ) => {
861
885
const img = await testImg ( { srcBasename : "oly.jpg" } ) ;
862
886
const before = await exiftool . read ( img ) ;
863
- expect ( before ) . to . containSubset ( exp ) ;
887
+ expect ( before ) . to . containSubset ( ImageExifData ) ;
864
888
assertDefinedGeneralTags ( before ) ;
865
- await exiftool . deleteAllTags ( img , { retain : Object . keys ( exp ) } ) ;
889
+ await exiftool . deleteAllTags ( img , { retain : Object . keys ( ImageExifData ) } ) ;
866
890
const after = await exiftool . read ( img ) ;
867
891
assertMissingGeneralTags ( after ) ;
868
- expect ( after ) . to . containSubset ( exp ) ;
892
+ expect ( after ) . to . containSubset ( ImageExifData ) ;
869
893
} ) ;
870
894
871
895
it ( "supports creating arrays in structs" , async ( ) => {
0 commit comments