This repository has been archived by the owner on Jun 30, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added processor to set the identifier of anonymous items to the paren…
…t identifier
- Loading branch information
1 parent
e5bfc82
commit 5bd35f0
Showing
7 changed files
with
249 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
const | ||
callWithProcessStandardStreamsOfYaml = require("../callWithProcessStandardStreamsOfYaml"), | ||
setIdentifierOfAnonymousToParent = require("./"); | ||
|
||
callWithProcessStandardStreamsOfYaml( | ||
parameters => setIdentifierOfAnonymousToParent(parameters.items), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
module.exports = | ||
items => | ||
items | ||
&& | ||
withParentIdentifier( | ||
null, | ||
) | ||
.getIdentifierOrSetInItemOrLevelOrStack( | ||
items, | ||
); | ||
|
||
function withParentIdentifier( | ||
parentIdentifier, | ||
) { | ||
return { getIdentifierOrSetInItemOrLevelOrStack }; | ||
|
||
function getIdentifierOrSetInItemOrLevelOrStack( | ||
identifierOrItemOrLevelOrStack, | ||
) { | ||
return ( | ||
getWhenIdentifier() | ||
|| | ||
setInWhenLevelOrStack() | ||
|| | ||
setInItem(identifierOrItemOrLevelOrStack) | ||
); | ||
|
||
function getWhenIdentifier() { | ||
return ( | ||
typeof identifierOrItemOrLevelOrStack === "string" | ||
&& | ||
identifierOrItemOrLevelOrStack | ||
); | ||
} | ||
|
||
function setInWhenLevelOrStack() { | ||
return ( | ||
Array.isArray(identifierOrItemOrLevelOrStack) | ||
&& | ||
identifierOrItemOrLevelOrStack.map(setInItemOrLevel) | ||
); | ||
} | ||
} | ||
|
||
function setInItemOrLevel( | ||
itemOrLevel, | ||
) { | ||
return ( | ||
setInWhenLevel(itemOrLevel) | ||
|| | ||
getIdentifierOrSetInItem(itemOrLevel) | ||
); | ||
} | ||
|
||
function setInWhenLevel( | ||
itemOrLevel, | ||
) { | ||
return ( | ||
Array.isArray(itemOrLevel) | ||
&& | ||
itemOrLevel.map(getIdentifierOrSetInItem) | ||
); | ||
} | ||
|
||
function getIdentifierOrSetInItem( | ||
identifierOrItem, | ||
) { | ||
return ( | ||
getWhenIdentifier() | ||
|| | ||
setInItem(identifierOrItem) | ||
); | ||
|
||
function getWhenIdentifier() { | ||
return ( | ||
typeof identifierOrItem === "string" | ||
&& | ||
identifierOrItem | ||
); | ||
} | ||
} | ||
|
||
function setInItem({ | ||
id: identifier = parentIdentifier, | ||
items, | ||
...restOrItem | ||
}) { | ||
return ( | ||
{ | ||
...identifier && { id: identifier }, | ||
...restOrItem, | ||
...items && { items: getItems() }, | ||
} | ||
); | ||
|
||
function getItems() { | ||
return ( | ||
withParentIdentifier( | ||
identifier, | ||
) | ||
.getIdentifierOrSetInItemOrLevelOrStack( | ||
items, | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const setIdentifierOfAnonymousToParent = require("."); | ||
|
||
test.each( | ||
[ | ||
[ null, null ], | ||
[ "item", "item" ], | ||
[ {}, {} ], | ||
[ | ||
{ aProperty: "aValue" }, | ||
{ aProperty: "aValue" }, | ||
], | ||
[ | ||
{ id: "item" }, | ||
{ id: "item" }, | ||
], | ||
[ | ||
[ "item1", "item2" ], | ||
[ "item1", "item2" ], | ||
], | ||
[ | ||
[ { id: "item1" }, { id: "item2" } ], | ||
[ { id: "item1" }, { id: "item2" } ], | ||
], | ||
[ | ||
[ | ||
[ "upper1", "upper2" ], | ||
[ "lower1", "lower2" ], | ||
], | ||
[ | ||
[ "upper1", "upper2" ], | ||
[ "lower1", "lower2" ], | ||
], | ||
], | ||
[ | ||
{ | ||
id: "parent", | ||
items: "child", | ||
}, | ||
{ | ||
id: "parent", | ||
items: "child", | ||
}, | ||
], | ||
[ | ||
{ | ||
id: "parent", | ||
items: {}, | ||
}, | ||
{ | ||
id: "parent", | ||
items: { id: "parent" }, | ||
}, | ||
], | ||
[ | ||
{ | ||
aParentProperty: "aParentValue", | ||
id: "parent", | ||
items: { aChildProperty: "aChildValue" }, | ||
}, | ||
{ | ||
aParentProperty: | ||
"aParentValue", | ||
id: | ||
"parent", | ||
items: | ||
{ | ||
aChildProperty: "aChildValue", | ||
id: "parent", | ||
}, | ||
}, | ||
], | ||
[ | ||
{ | ||
id: "grandparent", | ||
items: { items: { } }, | ||
}, | ||
{ | ||
id: | ||
"grandparent", | ||
items: | ||
{ | ||
id: "grandparent", | ||
items: { id: "grandparent" }, | ||
}, | ||
}, | ||
], | ||
], | ||
)( | ||
"%j returns %j", | ||
( | ||
items, | ||
expected, | ||
) => | ||
expect( | ||
setIdentifierOfAnonymousToParent( | ||
items, | ||
), | ||
) | ||
.toEqual(expected), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const | ||
processorPlugins = require("@devsnicket/eunice-test-harnesses-processor-plugins"), | ||
setIdentifierOfAnonymousToParent = require("./"); | ||
|
||
processorPlugins.plugIn({ | ||
action: setIdentifierOfAnonymousToParent, | ||
text: "set identifier of anonymous to parent", | ||
}); |