Skip to content

Commit

Permalink
written tests for issue 59
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeKovarik committed May 6, 2021
1 parent 2f78caf commit ae37a9d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2,042 deletions.
9 changes: 9 additions & 0 deletions test/issues.spec.mjs
Expand Up @@ -101,6 +101,15 @@ describe('issues (special cases)', () => {
// throws Unknown file format
})

it(`#59 - Region (incorrect XMP parsing)`, async () => {
let input = await getFile('issue-exifr-59.jpg')
var output = await exifr.parse(input, {xmp: true})
assert.isObject(output.Regions)
assert.isObject(output.Regions.RegionList)
assert.equal(output.Regions.RegionList.Name, 'Alvin the Squirrel')
assert.equal(output.Regions.RegionList.Area.x, 0.41794)
})

it(`fast-exif #2 - should not skip exif if 0xFF byte precedes marker`, async () => {
var output = await exifr.parse(await getFile('issue-fast-exif-2.jpg'), true)
assertOutputWithoutErrors(output)
Expand Down
68 changes: 68 additions & 0 deletions test/xmp-parser-issues.spec.mjs
@@ -0,0 +1,68 @@
import {assert, getFile} from './test-util-core.mjs'
import XmpParser from '../src/segment-parsers/xmp.mjs'


describe('XmpParser - issues', () => {

describe('#59 (regions): nested rdf:Description', () => {

it('RegionList with single item', () => {
let output = XmpParser.parse(`
<rdf:Description>
<mwg-rs:Regions rdf:parseType="Resource">
<mwg-rs:AppliedToDimensions stDim:w="1697" stDim:h="1132" stDim:unit="pixel"/>
<mwg-rs:RegionList>
<rdf:Bag>
<rdf:li>
<rdf:Description mwg-rs:Rotation="0.00000" mwg-rs:Name="Alvin the Squirrel" mwg-rs:Type="Face">
<mwg-rs:Area stArea:h="0.55270" stArea:w="0.39405" stArea:x="0.41794" stArea:y="0.58851"/>
</rdf:Description>
</rdf:li>
</rdf:Bag>
</mwg-rs:RegionList>
</mwg-rs:Regions>
</rdf:Description>
`)['mwg-rs']
assert.isObject(output)
assert.isObject(output.Regions)
assert.equal(output.Regions.parseType, 'Resource')
assert.isObject(output.Regions.AppliedToDimensions)
assert.equal(output.Regions.AppliedToDimensions.w, 1697)
assert.isObject(output.Regions.RegionList)
assert.equal(output.Regions.RegionList.Name, 'Alvin the Squirrel')
assert.equal(output.Regions.RegionList.Area.x, 0.41794)
})

it('RegionList with multiple items', () => {
let output = XmpParser.parse(`
<rdf:Description>
<mwg-rs:Regions rdf:parseType="Resource">
<mwg-rs:AppliedToDimensions stDim:w="1697" stDim:h="1132" stDim:unit="pixel"/>
<mwg-rs:RegionList>
<rdf:Bag>
<rdf:li>
<rdf:Description mwg-rs:Rotation="0.00000" mwg-rs:Name="Alvin the Squirrel" mwg-rs:Type="Face">
<mwg-rs:Area stArea:h="0.55270" stArea:w="0.39405" stArea:x="0.41794" stArea:y="0.58851"/>
</rdf:Description>
</rdf:li>
<rdf:li>
<rdf:Description mwg-rs:Rotation="1.00000" mwg-rs:Name="Another" mwg-rs:Type="Face">
<mwg-rs:Area stArea:h="0.5" stArea:w="0.3" stArea:x="0.4" stArea:y="0.5"/>
</rdf:Description>
</rdf:li>
</rdf:Bag>
</mwg-rs:RegionList>
</mwg-rs:Regions>
</rdf:Description>
`)['mwg-rs']
assert.isArray(output.Regions.RegionList)
assert.lengthOf(output.Regions.RegionList, 2)
assert.equal(output.Regions.RegionList[0].Name, 'Alvin the Squirrel')
assert.equal(output.Regions.RegionList[0].Area.x, 0.41794)
assert.equal(output.Regions.RegionList[1].Name, 'Another')
assert.equal(output.Regions.RegionList[1].Area.x, 0.4)
})

})

})

0 comments on commit ae37a9d

Please sign in to comment.