2020-08-12 00:15:16 +00:00
|
|
|
import { ResolveInput, ResolveResult } from '../../src/resolve';
|
2020-08-29 07:16:53 +00:00
|
|
|
import { StateLabel } from '../../src';
|
2020-08-12 00:15:16 +00:00
|
|
|
|
|
|
|
export interface ResolveTestCase {
|
|
|
|
input: ResolveInput;
|
|
|
|
name: string;
|
2020-08-29 07:16:53 +00:00
|
|
|
result: Partial<ResolveResult>;
|
2020-08-12 00:15:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 07:16:53 +00:00
|
|
|
export const TWO_STATE_CYCLE: StateLabel = {
|
|
|
|
adds: [],
|
|
|
|
divider: '/',
|
|
|
|
name: 'foo',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
values: [{
|
|
|
|
adds: [{
|
|
|
|
name: 'fin',
|
|
|
|
}],
|
|
|
|
becomes: [{
|
|
|
|
adds: [{
|
|
|
|
name: 'foo/bin',
|
|
|
|
}],
|
|
|
|
matches: [{
|
|
|
|
name: 'next',
|
|
|
|
}],
|
|
|
|
removes: [],
|
|
|
|
}],
|
|
|
|
name: 'bar',
|
|
|
|
priority: 1,
|
|
|
|
removes: [{
|
|
|
|
name: 'bob',
|
|
|
|
}],
|
|
|
|
requires: [],
|
|
|
|
}, {
|
|
|
|
adds: [],
|
|
|
|
becomes: [{
|
|
|
|
adds: [{
|
|
|
|
name: 'foo/bar',
|
|
|
|
}],
|
|
|
|
matches: [{
|
|
|
|
name: 'next',
|
|
|
|
}],
|
|
|
|
removes: [],
|
|
|
|
}],
|
|
|
|
name: 'bin',
|
|
|
|
priority: 1,
|
|
|
|
removes: [{
|
|
|
|
name: 'bob',
|
|
|
|
}],
|
|
|
|
requires: [],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SECOND_STATE_FALLBACK: StateLabel = {
|
|
|
|
adds: [],
|
|
|
|
divider: '/',
|
|
|
|
name: 'foo',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
values: [{
|
|
|
|
adds: [],
|
|
|
|
becomes: [{
|
|
|
|
adds: [{
|
|
|
|
name: 'fin',
|
|
|
|
}],
|
|
|
|
matches: [{
|
|
|
|
name: 'next',
|
|
|
|
}],
|
|
|
|
removes: [],
|
|
|
|
}],
|
|
|
|
name: 'bar',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [{
|
|
|
|
name: 'bob',
|
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
adds: [],
|
|
|
|
becomes: [{
|
|
|
|
adds: [],
|
|
|
|
matches: [{
|
|
|
|
name: 'next',
|
|
|
|
}],
|
|
|
|
removes: [],
|
|
|
|
}],
|
|
|
|
name: 'bin',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2020-08-12 00:15:16 +00:00
|
|
|
export const TEST_CASES: Array<ResolveTestCase> = [{
|
|
|
|
input: {
|
2020-08-12 01:39:53 +00:00
|
|
|
flags: [],
|
2020-08-12 00:15:16 +00:00
|
|
|
labels: [],
|
2020-08-12 01:39:53 +00:00
|
|
|
states: [],
|
2020-08-12 00:15:16 +00:00
|
|
|
},
|
2020-08-12 01:39:53 +00:00
|
|
|
name: 'empty',
|
2020-08-12 00:15:16 +00:00
|
|
|
result: {
|
|
|
|
changes: [],
|
|
|
|
errors: [],
|
|
|
|
labels: [],
|
|
|
|
},
|
2020-08-12 01:39:53 +00:00
|
|
|
}, {
|
|
|
|
input: {
|
|
|
|
flags: [{
|
|
|
|
adds: [],
|
|
|
|
name: 'test',
|
|
|
|
priority: 1,
|
|
|
|
removes: [],
|
|
|
|
requires: [],
|
|
|
|
}],
|
|
|
|
labels: [
|
|
|
|
'test',
|
|
|
|
],
|
|
|
|
states: [],
|
|
|
|
},
|
|
|
|
name: 'basic flags',
|
|
|
|
result: {
|
|
|
|
changes: [],
|
|
|
|
errors: [],
|
|
|
|
labels: [
|
|
|
|
'test',
|
|
|
|
],
|
|
|
|
},
|
2020-08-29 07:16:53 +00:00
|
|
|
}, {
|
|
|
|
input: {
|
|
|
|
flags: [],
|
|
|
|
labels: ['foo/bar', 'next'],
|
|
|
|
states: [TWO_STATE_CYCLE],
|
|
|
|
},
|
|
|
|
name: 'become adds',
|
|
|
|
result: {
|
|
|
|
errors: [],
|
|
|
|
labels: ['fin', 'foo/bin'],
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
input: {
|
|
|
|
flags: [],
|
|
|
|
labels: ['foo/bar', 'next', 'bob'],
|
|
|
|
states: [TWO_STATE_CYCLE],
|
|
|
|
},
|
|
|
|
name: 'become removes',
|
|
|
|
result: {
|
|
|
|
errors: [],
|
|
|
|
labels: ['fin', 'foo/bin'],
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
input: {
|
|
|
|
flags: [],
|
|
|
|
labels: ['foo/bar', 'foo/bin'],
|
|
|
|
states: [TWO_STATE_CYCLE],
|
|
|
|
},
|
|
|
|
name: 'state single value',
|
|
|
|
result: {
|
|
|
|
errors: [],
|
|
|
|
labels: ['foo/bar', 'fin'],
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
input: {
|
|
|
|
flags: [],
|
|
|
|
labels: ['foo/bar', 'foo/bin'],
|
|
|
|
states: [SECOND_STATE_FALLBACK],
|
|
|
|
},
|
|
|
|
name: 'second state requires missing',
|
|
|
|
result: {
|
|
|
|
errors: [],
|
|
|
|
labels: ['foo/bin'],
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
input: {
|
|
|
|
flags: [],
|
|
|
|
labels: ['foo/bar', 'foo/bin', 'bob'],
|
|
|
|
states: [SECOND_STATE_FALLBACK],
|
|
|
|
},
|
|
|
|
name: 'second state requires present',
|
|
|
|
result: {
|
|
|
|
errors: [],
|
|
|
|
labels: ['foo/bar', 'bob'],
|
|
|
|
},
|
2020-08-12 00:15:16 +00:00
|
|
|
}];
|