@@ -69,6 +69,12 @@ func TestDecodeWebP(t *testing.T) {
6969 c .Assert (tags .XMP ()["City" ].Value , qt .Equals , "Benalmádena" )
7070}
7171
72+ // For development.
73+ func TestDecodeAdhoc (t * testing.T ) {
74+ t .Skip ("used in development" )
75+ extractTags (t , "/Users/bep/dump/summer.webp" , imagemeta .EXIF )
76+ }
77+
7278func TestDecodeJPEG (t * testing.T ) {
7379 c := qt .New (t )
7480
@@ -615,15 +621,6 @@ func compareWithExiftoolOutput(t testing.TB, filename string, sources imagemeta.
615621 case imagemeta.Rat [int32 ]:
616622 return v .Float64 ()
617623 case float64 :
618- if math .IsInf (v , 1 ) {
619- panic (fmt .Errorf ("inf: %s" , s ))
620- }
621- if math .IsInf (v , - 1 ) {
622- panic (fmt .Errorf ("-inf: %s" , s ))
623- }
624- if math .IsNaN (v ) {
625- panic (fmt .Errorf ("nan: %s" , s ))
626- }
627624 return v
628625 case int64 :
629626 return float64 (v )
@@ -710,6 +707,17 @@ func compareWithExiftoolOutput(t testing.TB, filename string, sources imagemeta.
710707 if found {
711708 expect := normalizeThem (v .Tag , exifToolValue , v .Source )
712709 got := normalizeUs (v .Tag , v .Value , v .Source )
710+ if v , ok := got .(float64 ); ok {
711+ if math .IsInf (v , 1 ) {
712+ panic (fmt .Errorf ("inf: %v" , v ))
713+ }
714+ if math .IsInf (v , - 1 ) {
715+ panic (fmt .Errorf ("-inf: %v" , v ))
716+ }
717+ if math .IsNaN (v ) {
718+ panic (fmt .Errorf ("nan: %v" , v ))
719+ }
720+ }
713721 c .Assert (got , eq , expect , qt .Commentf ("%s (%s): got: %T/%T %v %q\n \n %s\n \n %s" , v .Tag , v .Source , got , expect , v .Value , filename , got , expect ))
714722 }
715723 }
@@ -740,7 +748,10 @@ func extractTags(t testing.TB, filename string, sources imagemeta.Source) imagem
740748
741749func extractTagsWithFilter (t testing.TB , filename string , sources imagemeta.Source , shouldHandle func (ti imagemeta.TagInfo ) bool ) imagemeta.Tags {
742750 t .Helper ()
743- f , err := os .Open (filepath .Join ("testdata" , "images" , filename ))
751+ if ! filepath .IsAbs (filename ) {
752+ filename = filepath .Join ("testdata" , "images" , filename )
753+ }
754+ f , err := os .Open (filename )
744755 if err != nil {
745756 t .Fatal (err )
746757 }
@@ -775,6 +786,12 @@ func extractTagsWithFilter(t testing.TB, filename string, sources imagemeta.Sour
775786 // Verify that it can be marshaled to JSON.
776787 _ , err = json .Marshal (tags .All ())
777788 if err != nil {
789+ for tag , ti := range tags .All () {
790+ _ , err2 := json .Marshal (ti .Value )
791+ if err2 != nil {
792+ t .Fatal (fmt .Errorf ("failed to marshal tag %q in source %s with value %v/%T to JSON: %w" , tag , ti .Source , ti .Value , ti .Value , err2 ))
793+ }
794+ }
778795 t .Fatal (fmt .Errorf ("failed to marshal tags in %q to JSON: %w" , filename , err ))
779796 }
780797
0 commit comments