diff options
Diffstat (limited to 'test/unit/data/composite')
5 files changed, 398 insertions, 84 deletions
diff --git a/test/unit/data/composite/control-flow/withResultOfAvailabilityCheck.js b/test/unit/data/composite/control-flow/withResultOfAvailabilityCheck.js index 2bcabb4f..9d588e4c 100644 --- a/test/unit/data/composite/control-flow/withResultOfAvailabilityCheck.js +++ b/test/unit/data/composite/control-flow/withResultOfAvailabilityCheck.js @@ -177,10 +177,11 @@ t.test(`withResultOfAvailabilityCheck: validate dynamic inputs`, t => { mode: 'banana', }), {message: `Error computing composition`, cause: - {message: `Error computing composition withResultOfAvailabilityCheck`, cause: - {message: `Errors in input values provided to withResultOfAvailabilityCheck`, errors: [ - {message: `mode: Expected one of null empty falsy index, got banana`}, - ]}}}); + {message: `Error in step 1 of 2, withResultOfAvailabilityCheck`, cause: + {message: `Error computing composition withResultOfAvailabilityCheck`, cause: + {message: `Errors in input values provided to withResultOfAvailabilityCheck`, errors: [ + {message: `mode: Expected one of null empty falsy index, got banana`}, + ]}}}}); t.throws( () => composite.expose.compute({ @@ -188,8 +189,9 @@ t.test(`withResultOfAvailabilityCheck: validate dynamic inputs`, t => { mode: null, }), {message: `Error computing composition`, cause: - {message: `Error computing composition withResultOfAvailabilityCheck`, cause: - {message: `Errors in input values provided to withResultOfAvailabilityCheck`, errors: [ - {message: `mode: Expected a value, got null`}, - ]}}}); + {message: `Error in step 1 of 2, withResultOfAvailabilityCheck`, cause: + {message: `Error computing composition withResultOfAvailabilityCheck`, cause: + {message: `Errors in input values provided to withResultOfAvailabilityCheck`, errors: [ + {message: `mode: Expected a value, got null`}, + ]}}}}); }); diff --git a/test/unit/data/composite/data/withPropertiesFromObject.js b/test/unit/data/composite/data/withPropertiesFromObject.js index 750dc8c4..b81d51a5 100644 --- a/test/unit/data/composite/data/withPropertiesFromObject.js +++ b/test/unit/data/composite/data/withPropertiesFromObject.js @@ -1,4 +1,5 @@ import t from 'tap'; +import {quickCheckCompositeOutputs} from '#test-lib'; import {compositeFrom, input} from '#composite'; import {exposeDependency} from '#composite/control-flow'; @@ -62,6 +63,8 @@ t.test(`withPropertiesFromObject: output shapes & values`, t => { ['foo', 'baz', 'missing3'], }; + const qcco = quickCheckCompositeOutputs(t, dependencies); + const mapLevel1 = [ [input.value('prefix_value'), [ ['object_dependency', [ @@ -153,28 +156,10 @@ t.test(`withPropertiesFromObject: output shapes & values`, t => { properties: propertiesInput, }); - quickCheckOutputs(step, outputDict); + qcco(step, outputDict); } } } - - function quickCheckOutputs(step, outputDict) { - t.same( - Object.keys(step.toDescription().outputs), - Object.keys(outputDict)); - - const composite = compositeFrom({ - compose: false, - steps: [step, { - dependencies: Object.keys(outputDict), - compute: dependencies => dependencies, - }], - }); - - t.same( - composite.expose.compute(dependencies), - outputDict); - } }); t.test(`withPropertiesFromObject: validate static inputs`, t => { @@ -226,11 +211,12 @@ t.test(`withPropertiesFromObject: validate dynamic inputs`, t => { properties: 'onceMore', }), {message: `Error computing composition`, cause: - {message: `Error computing composition withPropertiesFromObject`, cause: - {message: `Errors in input values provided to withPropertiesFromObject`, errors: [ - {message: `object: Expected an object, got string`}, - {message: `properties: Expected an array, got string`}, - ]}}}); + {message: `Error in step 1 of 2, withPropertiesFromObject`, cause: + {message: `Error computing composition withPropertiesFromObject`, cause: + {message: `Errors in input values provided to withPropertiesFromObject`, errors: [ + {message: `object: Expected an object, got string`}, + {message: `properties: Expected an array, got string`}, + ]}}}}); t.throws( () => composite.expose.compute({ @@ -238,17 +224,18 @@ t.test(`withPropertiesFromObject: validate dynamic inputs`, t => { properties: ['abc', 'def', 123], }), {message: `Error computing composition`, cause: - {message: `Error computing composition withPropertiesFromObject`, cause: - {message: `Errors in input values provided to withPropertiesFromObject`, errors: [ - {message: `object: Expected an object, got array`}, - {message: `properties: Errors validating array items`, errors: [ - { - [Symbol.for('hsmusic.annotateError.indexInSourceArray')]: 2, - message: `Error at zero-index 2: 123`, - cause: { - message: `Expected a string, got number`, + {message: `Error in step 1 of 2, withPropertiesFromObject`, cause: + {message: `Error computing composition withPropertiesFromObject`, cause: + {message: `Errors in input values provided to withPropertiesFromObject`, errors: [ + {message: `object: Expected an object, got array`}, + {message: `properties: Errors validating array items`, errors: [ + { + [Symbol.for('hsmusic.annotateError.indexInSourceArray')]: 2, + message: `Error at zero-index 2: 123`, + cause: { + message: `Expected a string, got number`, + }, }, - }, - ]}, - ]}}}); + ]}, + ]}}}}); }); diff --git a/test/unit/data/composite/data/withPropertyFromObject.js b/test/unit/data/composite/data/withPropertyFromObject.js index 6a772c36..912c924c 100644 --- a/test/unit/data/composite/data/withPropertyFromObject.js +++ b/test/unit/data/composite/data/withPropertyFromObject.js @@ -1,5 +1,7 @@ import t from 'tap'; +import {quickCheckCompositeOutputs} from '#test-lib'; +import CacheableObject from '#cacheable-object'; import {compositeFrom, input} from '#composite'; import {exposeDependency} from '#composite/control-flow'; import {withPropertyFromObject} from '#composite/data'; @@ -42,6 +44,89 @@ t.test(`withPropertyFromObject: basic behavior`, t => { }), null); }); +t.test(`withPropertyFromObject: "internal" input`, t => { + t.plan(7); + + const composite = compositeFrom({ + compose: false, + + steps: [ + withPropertyFromObject({ + object: 'object', + property: 'property', + internal: 'internal', + }), + + exposeDependency({dependency: '#value'}), + ], + }); + + const thing = new (class extends CacheableObject { + static [CacheableObject.propertyDescriptors] = { + foo: { + flags: {update: true, expose: false}, + }, + + bar: { + flags: {update: true, expose: true}, + }, + + baz: { + flags: {update: true, expose: true}, + expose: { + transform: baz => baz * 2, + }, + }, + }; + }); + + thing.foo = 100; + thing.bar = 200; + thing.baz = 300; + + t.match(composite, { + expose: { + dependencies: ['object', 'property', 'internal'], + }, + }); + + t.equal(composite.expose.compute({ + object: thing, + property: 'foo', + internal: true, + }), 100); + + t.equal(composite.expose.compute({ + object: thing, + property: 'bar', + internal: true, + }), 200); + + t.equal(composite.expose.compute({ + object: thing, + property: 'baz', + internal: true, + }), 300); + + t.equal(composite.expose.compute({ + object: thing, + property: 'baz', + internal: false, + }), 600); + + t.equal(composite.expose.compute({ + object: thing, + property: 'bimbam', + internal: false, + }), null); + + t.equal(composite.expose.compute({ + object: null, + property: 'bambim', + internal: false, + }), null); +}); + t.test(`withPropertyFromObject: output shapes & values`, t => { t.plan(2 * 3 ** 2); @@ -56,6 +141,8 @@ t.test(`withPropertyFromObject: output shapes & values`, t => { 'baz', }; + const qcco = quickCheckCompositeOutputs(t, dependencies); + const mapLevel1 = [ ['object_dependency', [ ['property_dependency', { @@ -98,25 +185,7 @@ t.test(`withPropertyFromObject: output shapes & values`, t => { property: propertyInput, }); - quickCheckOutputs(step, outputDict); + qcco(step, outputDict); } } - - function quickCheckOutputs(step, outputDict) { - t.same( - Object.keys(step.toDescription().outputs), - Object.keys(outputDict)); - - const composite = compositeFrom({ - compose: false, - steps: [step, { - dependencies: Object.keys(outputDict), - compute: dependencies => dependencies, - }], - }); - - t.same( - composite.expose.compute(dependencies), - outputDict); - } }); diff --git a/test/unit/data/composite/data/withUniqueItemsOnly.js b/test/unit/data/composite/data/withUniqueItemsOnly.js index 965b14b5..50b16f43 100644 --- a/test/unit/data/composite/data/withUniqueItemsOnly.js +++ b/test/unit/data/composite/data/withUniqueItemsOnly.js @@ -1,4 +1,5 @@ import t from 'tap'; +import {quickCheckCompositeOutputs} from '#test-lib'; import {compositeFrom, input} from '#composite'; import {exposeDependency} from '#composite/control-flow'; @@ -44,6 +45,8 @@ t.test(`withUniqueItemsOnly: output shapes & values`, t => { [8, 8, 7, 6, 6, 5, 'bar', true, true, 5], }; + const qcco = quickCheckCompositeOutputs(t, dependencies); + const mapLevel1 = [ ['list_dependency', { '#list_dependency': [1, 2, 3, 4, 'foo', false], @@ -61,24 +64,6 @@ t.test(`withUniqueItemsOnly: output shapes & values`, t => { list: listInput, }); - quickCheckOutputs(step, outputDict); - } - - function quickCheckOutputs(step, outputDict) { - t.same( - Object.keys(step.toDescription().outputs), - Object.keys(outputDict)); - - const composite = compositeFrom({ - compose: false, - steps: [step, { - dependencies: Object.keys(outputDict), - compute: dependencies => dependencies, - }], - }); - - t.same( - composite.expose.compute(dependencies), - outputDict); + qcco(step, outputDict); } }); diff --git a/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js b/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js index babe4fae..411fd11d 100644 --- a/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js +++ b/test/unit/data/composite/wiki-data/withParsedCommentaryEntries.js @@ -28,12 +28,13 @@ function stubArtist(artistName = `Test Artist`) { } t.test(`withParsedCommentaryEntries: basic behavior`, t => { - t.plan(3); + t.plan(7); const artist1 = stubArtist(`Mobius Trip`); const artist2 = stubArtist(`Hadron Kaleido`); + const artist3 = stubArtist('Homestuck'); - const artistData = [artist1, artist2]; + const artistData = [artist1, artist2, artist3]; t.match(composite, { expose: { @@ -53,6 +54,10 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => { artistDisplayText: null, annotation: null, date: null, + accessDate: null, + accessKind: null, + secondDate: null, + dateKind: null, body: `Some commentary.\nVery cool.`, }, ]); @@ -76,6 +81,10 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => { annotation: `music, art`, date: new Date('12 January 2015'), body: `First commentary entry.\nVery cool.`, + secondDate: null, + dateKind: null, + accessDate: null, + accessKind: null, }, { artists: [artist2], @@ -83,6 +92,10 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => { annotation: `moral support`, date: new Date('4 April 2022'), body: `Second commentary entry. Yes. So cool.`, + secondDate: null, + dateKind: null, + accessDate: null, + accessKind: null, }, { artists: [], @@ -90,6 +103,10 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => { annotation: `pingas`, date: new Date('25 August 2023'), body: `Oh no.. Oh dear...`, + secondDate: null, + dateKind: null, + accessDate: null, + accessKind: null, }, { artists: [artist1, artist2], @@ -97,6 +114,260 @@ t.test(`withParsedCommentaryEntries: basic behavior`, t => { annotation: null, date: null, body: `And back around we go.`, + secondDate: null, + dateKind: null, + accessDate: null, + accessKind: null, + }, + ]); + + t.same(composite.expose.compute({ + artistData, + from: + `<i>Homestuck:</i> ([Bandcamp credits blurb](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/track/sburban-countdown-3) on "Homestuck Vol. 1-4 (with Midnight Crew: Drawing Dead)", 10/25/2019)\n` + + `\n` + + `Written by [[artist:michael-guy-bowman|Michael Guy Bowman]]<br>\n` + + `Arrangement by [[artist:mark-j-hadley|Mark Hadley]]\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), 7/20/2019 captured 4/13/2024)\n` + + `This isn't real!\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://homestuck.com/fake), 10/25/2011 accessed 10/27/2011)\n` + + `This isn't real either!\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), 7/20/2019 accessed 4/13/2024)\n` + + `Not this one, neither!\n` + }), [ + { + artists: [artist3], + artistDisplayText: null, + annotation: `[Bandcamp credits blurb](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/track/sburban-countdown-3) on "Homestuck Vol. 1-4 (with Midnight Crew: Drawing Dead)"`, + date: new Date('10/25/2019'), + body: + `Written by [[artist:michael-guy-bowman|Michael Guy Bowman]]<br>\n` + + `Arrangement by [[artist:mark-j-hadley|Mark Hadley]]`, + secondDate: null, + dateKind: null, + accessDate: new Date('10/24/2020'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + date: new Date('7/20/2019'), + body: `This isn't real!`, + secondDate: null, + dateKind: null, + accessDate: new Date('4/13/2024'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://homestuck.com/fake)`, + date: new Date('10/25/2011'), + body: `This isn't real either!`, + secondDate: null, + dateKind: null, + accessDate: new Date('10/27/2011'), + accessKind: 'accessed', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + date: new Date('7/20/2019'), + body: `Not this one, neither!`, + secondDate: null, + dateKind: null, + accessDate: new Date('4/13/2024'), + accessKind: 'accessed', + }, + ]); + + t.same(composite.expose.compute({ + artistData, + from: + `<i>Homestuck:</i> ([MSPA sound credits](https://web.archive.org/web/20120805031705/http://www.mspaintadventures.com:80/soundcredits.html), sometime 6/21/2012 - 8/5/2012)\n` + + `\n` + + `[[flash:246|Page 2146]] - <b>"Sburban Countdown"</b><br>\n` + + `Available on Bandcamp in [[album:homestuck-vol-1-4|Homestuck Vol. 1-4]]<br>\n` + + `Written by [[artist:michael-guy-bowman|Michael Guy Bowman]]<br>\n` + + `Arrangement by [[artist:mark-j-hadley|Mark Hadley]]\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), 7/20/2019 - 7/20/2022 captured 4/13/2024)\n` + + `It's goin' once.\n` + + `\n` + + `<i>Homestuck:</i> (10/25/2011 - 10/28/2011 accessed 10/27/2011)\n` + + `It's goin' twice.\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), 7/20/2019 - 7/20/2022 accessed 4/13/2024)\n` + + `It's goin' thrice!\n` + }), [ + { + artists: [artist3], + artistDisplayText: null, + annotation: `[MSPA sound credits](https://web.archive.org/web/20120805031705/http://www.mspaintadventures.com:80/soundcredits.html)`, + body: + `[[flash:246|Page 2146]] - <b>"Sburban Countdown"</b><br>\n` + + `Available on Bandcamp in [[album:homestuck-vol-1-4|Homestuck Vol. 1-4]]<br>\n` + + `Written by [[artist:michael-guy-bowman|Michael Guy Bowman]]<br>\n` + + `Arrangement by [[artist:mark-j-hadley|Mark Hadley]]`, + date: new Date('6/21/2012'), + secondDate: new Date('8/5/2012'), + dateKind: 'sometime', + accessDate: new Date('8/5/2012'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + body: `It's goin' once.`, + date: new Date('7/20/2019'), + secondDate: new Date('7/20/2022'), + dateKind: null, + accessDate: new Date('4/13/2024'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: '', // TODO: This should be null, but the regex isn't structured for that, at the moment. + body: `It's goin' twice.`, + date: new Date('10/25/2011'), + secondDate: new Date('10/28/2011'), + dateKind: null, + accessDate: new Date('10/27/2011'), + accessKind: 'accessed', + + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + body: `It's goin' thrice!`, + date: new Date('7/20/2019'), + secondDate: new Date('7/20/2022'), + dateKind: null, + accessDate: new Date('4/13/2024'), + accessKind: 'accessed', + }, + ]); + + t.same(composite.expose.compute({ + artistData, + from: + `<i>Homestuck:</i> ([MSPA sound credits](https://web.archive.org/web/20120805031705/http://www.mspaintadventures.com:80/soundcredits.html), sometime 6/21/2012 - 8/5/2012)\n` + + `\n` + + `[[flash:246|Page 2146]] - <b>"Sburban Countdown"</b><br>\n` + + `Available on Bandcamp in [[album:homestuck-vol-1-4|Homestuck Vol. 1-4]]<br>\n` + + `Written by [[artist:michael-guy-bowman|Michael Guy Bowman]]<br>\n` + + `Arrangement by [[artist:mark-j-hadley|Mark Hadley]]\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), 7/20/2019 - 7/20/2022 captured 4/13/2024)\n` + + `It's goin' once.\n` + + `\n` + + `<i>Homestuck:</i> (10/25/2011 - 10/28/2011 accessed 10/27/2011)\n` + + `It's goin' twice.\n` + + `\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), 7/20/2019 - 7/20/2022 accessed 4/13/2024)\n` + + `It's goin' thrice!\n` + }), [ + { + artists: [artist3], + artistDisplayText: null, + annotation: `[MSPA sound credits](https://web.archive.org/web/20120805031705/http://www.mspaintadventures.com:80/soundcredits.html)`, + body: + `[[flash:246|Page 2146]] - <b>"Sburban Countdown"</b><br>\n` + + `Available on Bandcamp in [[album:homestuck-vol-1-4|Homestuck Vol. 1-4]]<br>\n` + + `Written by [[artist:michael-guy-bowman|Michael Guy Bowman]]<br>\n` + + `Arrangement by [[artist:mark-j-hadley|Mark Hadley]]`, + date: new Date('6/21/2012'), + secondDate: new Date('8/5/2012'), + dateKind: 'sometime', + accessDate: new Date('8/5/2012'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + body: `It's goin' once.`, + date: new Date('7/20/2019'), + secondDate: new Date('7/20/2022'), + dateKind: null, + accessDate: new Date('4/13/2024'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: '', // TODO: This should be null, but the regex isn't structured for that, at the moment. + body: `It's goin' twice.`, + date: new Date('10/25/2011'), + secondDate: new Date('10/28/2011'), + dateKind: null, + accessDate: new Date('10/27/2011'), + accessKind: 'accessed', + + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + body: `It's goin' thrice!`, + date: new Date('7/20/2019'), + secondDate: new Date('7/20/2022'), + dateKind: null, + accessDate: new Date('4/13/2024'), + accessKind: 'accessed', + }, + ]); + + t.same(composite.expose.compute({ + artistData, + from: + `<i>Homestuck:</i> ([Homestuck sound credits](https://web.archive.org/web/20180717171235/https://www.homestuck.com/credits/sound), excerpt, around 4/3/2018)\n` + + `blablabla\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), around 7/20/2019 - 7/20/2022 captured 4/13/2024)\n` + + `Snoopin', snoopin', snoo,\n` + + `<i>Homestuck:</i> ([fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake), throughout 7/20/2019 - 7/20/2022 accessed 4/13/2024)\n` + + `~ pingas ~\n` + }), [ + { + artists: [artist3], + artistDisplayText: null, + annotation: `[Homestuck sound credits](https://web.archive.org/web/20180717171235/https://www.homestuck.com/credits/sound), excerpt`, + body: `blablabla`, + date: new Date('4/3/2018'), + secondDate: null, + dateKind: 'around', + accessDate: new Date('7/17/2018'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + body: `Snoopin', snoopin', snoo,`, + date: new Date('7/20/2019'), + secondDate: new Date('7/20/2022'), + dateKind: 'around', + accessDate: new Date('4/13/2024'), + accessKind: 'captured', + }, + { + artists: [artist3], + artistDisplayText: null, + annotation: `[fake](https://web.archive.org/web/20201024170202/https://homestuck.bandcamp.com/fake)`, + body: `~ pingas ~`, + date: new Date('7/20/2019'), + secondDate: new Date('7/20/2022'), + dateKind: 'throughout', + accessDate: new Date('4/13/2024'), + accessKind: 'accessed', }, ]); }); |