Skip to content

Commit

Permalink
Split resolveDependencyNodesets set-like behavior tests
Browse files Browse the repository at this point in the history
- Cases which previously exercised set-like behvaior implicitly are broken into individual tests, e.g. demonstrating cases where `current()` and `.` are treated the same way
- Adds an explicit set-like behavior test
  • Loading branch information
eyelidlessness committed Jul 22, 2024
1 parent 413819d commit c5b8ac7
Showing 1 changed file with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,29 @@ describe('Dependency analysis', () => {

{
description:
'Context is instance("id") descendant. Expression references another instance (resolved as-is); relative sibling and relative child (resolved from context); relative sibling and child with current() calls (likewise resolved from context); absolute reference (resolved as-is)',
'Context is instance("id") descendant. Expression references another instance (resolved as-is); relative sibling and relative child (resolved from context); absolute reference (resolved as-is)',

contextNodeset: 'instance("foo")/bar',
expression:
'if(position() > 2, instance("quux")/zig, ../zag | ./zag | current()/zag | current()/../zag) or /beep//boop',
expression: 'if(position() > 2, instance("quux")/zig, ./zag | ../zag) or /beep//boop',
expected: [
'instance("quux")/zig',
'instance("foo")/bar/zag',
'instance("foo")/zag',
'/beep//boop',
],
},

{
description:
'Context is instance("id") descendant. Expression references another instance (resolved as-is); relative sibling and child with current() calls (likewise resolved from context); absolute reference (resolved as-is)',

contextNodeset: 'instance("foo")/bar',
expression:
'if(position() > 2, instance("quux")/zig, current()/zag | current()/../zag) or /beep//boop',
expected: [
'instance("quux")/zig',
'instance("foo")/bar/zag',
'instance("foo")/zag',
'/beep//boop',
],
},
Expand Down Expand Up @@ -306,11 +320,28 @@ describe('Dependency analysis', () => {
},

{
description: '// special cases',

description: 'descendant-or-self case: //.',
contextNodeset: null,
expression: 'fn-name-does-not-matter(//.)',
expected: ['//.'],
},
{
description: 'descendant-or-self case: //./foo',
contextNodeset: null,
expression: 'yep(//./foo)',
expected: ['//foo'],
},
{
description: 'descendant-or-self case: //..',
contextNodeset: null,
expression: 'nope(//..)',
expected: ['//..'],
},
{
description: 'descendant-or-self case: //../foo',
contextNodeset: null,
expression: '//. | //./foo | //.. | //../foo',
expected: ['//.', '//foo', '//..'],
expression: 'maybe(//../foo)',
expected: ['//foo'],
},

// This case exists to test removal of such a special case.
Expand All @@ -322,6 +353,24 @@ describe('Dependency analysis', () => {
expression: 'count(null) > count(foo/null)',
expected: ['/data/null', '/data/foo/null'],
},

{
description:
'Results are set-like: each resolved path is only produced once, even if the resolved from multiple sub-expressions',

contextNodeset: '/data/foo',
expression: `count(
bar |
bar/bat |
./bar |
./bar/bat |
bat/../bar |
quux/../bar/bat
)`,
expected: ['/data/foo/bar', '/data/foo/bar/bat'],
},
])('$description', ({ contextNodeset, expression, expected }) => {
it(`resolves nodeset dependencies in expression ${JSON.stringify(expression)}, with context ${JSON.stringify(contextNodeset)}, producing nodesets: ${JSON.stringify(expected)}`, () => {
const actual = resolveDependencyNodesets(contextNodeset, expression);
Expand Down

0 comments on commit c5b8ac7

Please sign in to comment.