-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This breaks up index into multiple files to simplify the move to a DAG representation of a plan. Change-type: minor
- Loading branch information
Showing
9 changed files
with
101 additions
and
100 deletions.
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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
import { expect } from '~/test-utils'; | ||
import { plan } from './builder'; | ||
|
||
describe('testing/builder', () => { | ||
it('builds a plan representation', () => { | ||
expect(plan().end()).to.deep.equal([]); | ||
expect(plan().action('a').end()).to.deep.equal(['a']); | ||
expect(plan().action('a').action('b').action('c').end()).to.deep.equal([ | ||
'a', | ||
'b', | ||
'c', | ||
]); | ||
}); | ||
}); |
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,34 @@ | ||
import { SimplePlan } from './types'; | ||
|
||
export interface Builder { | ||
/** | ||
* Adds a next node to the plan | ||
*/ | ||
action(description: string): Builder; | ||
|
||
/** | ||
* Builds the test plan | ||
*/ | ||
end(): SimplePlan; | ||
} | ||
|
||
/** | ||
* Start building a plan | ||
*/ | ||
export function plan(): Builder { | ||
const repr: SimplePlan = []; | ||
|
||
const builder = { | ||
action(description: string) { | ||
repr.push(description); | ||
|
||
return builder; | ||
}, | ||
|
||
end() { | ||
return repr; | ||
}, | ||
}; | ||
|
||
return builder; | ||
} |
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 |
---|---|---|
@@ -1,66 +1,4 @@ | ||
import { Node, Plan } from '../planner'; | ||
|
||
export * from './mermaid'; | ||
|
||
/** | ||
* A "serialized" plan. | ||
* | ||
* It's not really serialized as plan cannot be reconstructed | ||
* from the serialization. But is really an object representation | ||
* of a plan that's easier to print and compare. | ||
*/ | ||
export type Serialized = string[]; | ||
|
||
export interface Builder { | ||
/** | ||
* Adds a next node to the plan | ||
*/ | ||
action(description: string): Builder; | ||
|
||
/** | ||
* Builds the test plan | ||
*/ | ||
end(): Serialized; | ||
} | ||
|
||
function toArray<T>(n: Node<T> | null): Serialized { | ||
if (n == null) { | ||
return []; | ||
} | ||
|
||
return [n.action.description, ...toArray(n.next)]; | ||
} | ||
|
||
/** | ||
* Return a serialized version of the plan for comparison | ||
* | ||
* The function will throw if the plan is not successful | ||
*/ | ||
export function serialize<T>(p: Plan<T>): Serialized { | ||
if (!p.success) { | ||
throw new Error('Plan not found'); | ||
} | ||
|
||
return toArray(p.start); | ||
} | ||
|
||
/** | ||
* Start building a plan | ||
*/ | ||
export function plan(): Builder { | ||
const repr: Serialized = []; | ||
|
||
const builder = { | ||
action(description: string) { | ||
repr.push(description); | ||
|
||
return builder; | ||
}, | ||
|
||
end() { | ||
return repr; | ||
}, | ||
}; | ||
|
||
return builder; | ||
} | ||
export * from './types'; | ||
export * from './builder'; | ||
export * from './simplify'; |
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,24 @@ | ||
import { Node, Plan } from '../planner'; | ||
|
||
import { SimplePlan } from './types'; | ||
|
||
function toArray<T>(n: Node<T> | null): SimplePlan { | ||
if (n == null) { | ||
return []; | ||
} | ||
|
||
return [n.action.description, ...toArray(n.next)]; | ||
} | ||
|
||
/** | ||
* Return a serialized version of the plan for comparison | ||
* | ||
* The function will throw if the plan is not successful | ||
*/ | ||
export function simplified<T>(p: Plan<T>): SimplePlan { | ||
if (!p.success) { | ||
throw new Error('Plan not found'); | ||
} | ||
|
||
return toArray(p.start); | ||
} |
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,7 @@ | ||
/** | ||
* A "simplified" plan. | ||
* | ||
* It is an object representation | ||
* of a plan that's easier to print and compare. | ||
*/ | ||
export type SimplePlan = string[]; |
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