diff --git a/src/print/__tests__/printBinary.spec.ts b/src/print/__tests__/printBinary.spec.ts deleted file mode 100644 index 620e508..0000000 --- a/src/print/__tests__/printBinary.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -import {printBinary} from '../printBinary'; - -test('renders a single left child', () => { - const str = 'Node' + printBinary('', [() => `foo`]); - expect(str).toBe( - `Node -← foo`, - ); -}); - -test('renders a single right child', () => { - const str = 'Node' + printBinary('', [null, () => `foo`]); - expect(str).toBe( - `Node -→ foo`, - ); -}); - -test('renders one level of left and right children', () => { - const str = 'Node' + printBinary('', [() => 'left', () => 'right']); - expect(str).toBe( - `Node -← left -→ right`, - ); -}); - -test('renders two levels of left and right children', () => { - const str = - 'Node' + - printBinary('', [ - (tab) => 'left' + printBinary(tab, [() => 'left', () => 'right']), - (tab) => 'right' + printBinary(tab, [() => 'left', () => 'right']), - ]); - expect(str).toBe( - `Node -← left - ← left - → right -→ right - ← left - → right`, - ); -}); diff --git a/src/print/__tests__/printTree.spec.ts b/src/print/__tests__/printTree.spec.ts deleted file mode 100644 index 3ca7e39..0000000 --- a/src/print/__tests__/printTree.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import {printTree} from '../printTree'; - -test('renders a single child node', () => { - const str = 'Node' + printTree('', [() => `foo`]); - - expect(str).toBe( - `Node -└─ foo`, - ); -}); - -test('renders two children node', () => { - const str = 'Node' + printTree('', [() => `foo`, () => `bar`]); - - expect(str).toBe( - `Node -├─ foo -└─ bar`, - ); -}); - -test('renders two levels of nodes', () => { - const str = 'Node' + printTree('', [() => `foo`, (tab) => `bar` + printTree(tab, [() => `baz`])]); - - expect(str).toBe( - `Node -├─ foo -└─ bar - └─ baz`, - ); -}); - -test('renders two levels of nodes, with double tree line', () => { - const str = - 'Node' + - printTree('', [(tab) => `foo` + printTree(tab, [() => `baz`]), (tab) => `bar` + printTree(tab, [() => `baz`])]); - - expect(str).toBe( - `Node -├─ foo -│ └─ baz -└─ bar - └─ baz`, - ); -}); diff --git a/src/print/printBinary.ts b/src/print/printBinary.ts deleted file mode 100644 index 48a7878..0000000 --- a/src/print/printBinary.ts +++ /dev/null @@ -1,9 +0,0 @@ -type Child = (tab: string) => string; - -export const printBinary = (tab = '', children: [left?: null | Child, right?: null | Child]): string => { - const [left, right] = children; - let str = ''; - if (left) str += `\n${tab}← ${left(tab + ' ')}`; - if (right) str += `\n${tab}→ ${right(tab + ' ')}`; - return str; -}; diff --git a/src/print/printTree.ts b/src/print/printTree.ts deleted file mode 100644 index a054a55..0000000 --- a/src/print/printTree.ts +++ /dev/null @@ -1,15 +0,0 @@ -type Child = (tab: string) => string; - -export const printTree = (tab = '', children: (Child | null)[]): string => { - children = children.filter(Boolean); - let str = ''; - for (let i = 0; i < children.length; i++) { - const isLast = i >= children.length - 1; - const fn = children[i]; - if (!fn) continue; - const child = fn(tab + `${isLast ? ' ' : '│'} `); - const branch = child ? (isLast ? '└─' : '├─') : '│ '; - str += `\n${tab}${branch} ${child}`; - } - return str; -}; diff --git a/src/print/types.ts b/src/print/types.ts deleted file mode 100644 index 801a45d..0000000 --- a/src/print/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface Printable { - /** - * Returns a human-readable tabbed string representation of the object as a tree. - * - * @param tab String to use for indentation. - */ - toString(tab?: string): string; -}