this repo has no description
at main 118 lines 3.1 kB view raw
1import assert from 'node:assert' 2import { describe, test } from 'node:test' 3import { treeify } from './index.js' 4 5describe('readme examples', () => { 6 test('org chart example', () => { 7 const orgChart = treeify([ 8 'Lumon Industries', 9 [ 10 'Board of Directors', 11 ['Natalie (Representative)'], 12 'Departments', 13 [ 14 'Macrodata Refinement (Cobel)', 15 ['Milchick', 'Mark S.', ['Dylan G.', 'Irving B.', 'Helly R.']], 16 ], 17 'Other Departments', 18 [ 19 'Optics & Design', 20 'Wellness Center', 21 'Mammalians Nurturable', 22 'Choreography and Merriment', 23 ], 24 ], 25 ]) 26 const expected = `Lumon Industries 27├─ Board of Directors 28│ └─ Natalie (Representative) 29├─ Departments 30│ └─ Macrodata Refinement (Cobel) 31│ ├─ Milchick 32│ └─ Mark S. 33│ ├─ Dylan G. 34│ ├─ Irving B. 35│ └─ Helly R. 36└─ Other Departments 37 ├─ Optics & Design 38 ├─ Wellness Center 39 ├─ Mammalians Nurturable 40 └─ Choreography and Merriment` 41 42 console.log('\nOrg chart example:') 43 console.log(orgChart) 44 assert.strictEqual(orgChart, expected) 45 }) 46 47 test('basic example', () => { 48 const eagan = [ 49 'Kier Eagan', 50 ['...', ['...', 'Jame Eagan', ['Helena Eagan']], 'Ambrose Eagan'], 51 ] 52 const expected = `Kier Eagan 53├─ ... 54│ ├─ ... 55│ └─ Jame Eagan 56│ └─ Helena Eagan 57└─ Ambrose Eagan` 58 59 const result = treeify(eagan) 60 console.log('\nBasic example:') 61 console.log(result) 62 assert.strictEqual(result, expected) 63 64 const expectedPlain = `Kier Eagan 65 ... 66 ... 67 Jame Eagan 68 Helena Eagan 69 Ambrose Eagan` 70 const resultPlain = treeify(eagan, { plain: true }) 71 console.log('\nBasic example (plain):') 72 console.log(resultPlain) 73 assert.strictEqual(resultPlain, expectedPlain) 74 75 const expectedCustomChars = `Kier Eagan 76├• ... 77│ ├• ... 78│ └• Jame Eagan 79│ └• Helena Eagan 80└• Ambrose Eagan` 81 const resultCustomChars = treeify(eagan, { 82 chars: { branch: '├• ', lastBranch: '└• ', pipe: '│ ', space: ' ' }, 83 }) 84 console.log('\nBasic example (custom chars):') 85 console.log(resultCustomChars) 86 assert.strictEqual(resultCustomChars, expectedCustomChars) 87 }) 88 89 test('nested example', () => { 90 const orgChart = [ 91 'Lumon Industries', 92 [ 93 'Board of Directors', 94 ['Natalie (Representative)'], 95 'Department Heads', 96 [ 97 'Cobel (MDR)', 98 ['Milchick', 'Mark S.', ['Dylan G.', 'Irving B.', 'Helly R.']], 99 ], 100 ], 101 ] 102 const expected = `Lumon Industries 103├─ Board of Directors 104│ └─ Natalie (Representative) 105└─ Department Heads 106 └─ Cobel (MDR) 107 ├─ Milchick 108 └─ Mark S. 109 ├─ Dylan G. 110 ├─ Irving B. 111 └─ Helly R.` 112 113 const result = treeify(orgChart) 114 console.log('\nNested example:') 115 console.log(result) 116 assert.strictEqual(result, expected) 117 }) 118})