Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Nov 4, 2021
1 parent bda86ef commit bcc718d
Show file tree
Hide file tree
Showing 173 changed files with 26,601 additions and 14 deletions.
41 changes: 27 additions & 14 deletions scripts/generate-tests
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,32 @@ if ask "Are you sure?"; then
for width in 10 20 40 60 80
do
echo "Copying cli-*-100.js to cli-$width.js"
rm test/cli-$width-soft.js 2>/dev/null
rm test/cli-$width-soft-tabbed.js 2>/dev/null
rm test/cli-$width-hard.js 2>/dev/null
rm test/cli-$width-hard-tabbed.js 2>/dev/null
rm test/cli-$width-keep.js 2>/dev/null
rm test/cli-$width-panel.js 2>/dev/null
rm test/cli-$width-stamp.js 2>/dev/null
cp test/cli-100-soft.js test/cli-$width-soft.js
cp test/cli-100-soft-tabbed.js test/cli-$width-soft-tabbed.js
cp test/cli-100-hard.js test/cli-$width-hard.js
cp test/cli-100-hard-tabbed.js test/cli-$width-hard-tabbed.js
cp test/cli-100-keep.js test/cli-$width-keep.js
cp test/cli-100-panel.js test/cli-$width-panel.js
cp test/cli-100-stamp.js test/cli-$width-stamp.js
rm test/stream-$width-soft.js 2>/dev/null
rm test/stream-$width-soft-tabbed.js 2>/dev/null
rm test/stream-$width-hard.js 2>/dev/null
rm test/stream-$width-hard-tabbed.js 2>/dev/null
rm test/stream-$width-keep.js 2>/dev/null
rm test/stream-$width-panel.js 2>/dev/null
rm test/stream-$width-stamp.js 2>/dev/null
cp test/stream-100-soft.js test/stream-$width-soft.js
cp test/stream-100-soft-tabbed.js test/stream-$width-soft-tabbed.js
cp test/stream-100-hard.js test/stream-$width-hard.js
cp test/stream-100-hard-tabbed.js test/stream-$width-hard-tabbed.js
cp test/stream-100-keep.js test/stream-$width-keep.js
cp test/stream-100-panel.js test/stream-$width-panel.js

rm test/direct-$width-soft.js 2>/dev/null
rm test/direct-$width-soft-tabbed.js 2>/dev/null
rm test/direct-$width-hard.js 2>/dev/null
rm test/direct-$width-hard-tabbed.js 2>/dev/null
rm test/direct-$width-keep.js 2>/dev/null
rm test/direct-$width-panel.js 2>/dev/null
rm test/direct-$width-stamp.js 2>/dev/null
cp test/direct-100-soft.js test/direct-$width-soft.js
cp test/direct-100-soft-tabbed.js test/direct-$width-soft-tabbed.js
cp test/direct-100-hard.js test/direct-$width-hard.js
cp test/direct-100-hard-tabbed.js test/direct-$width-hard-tabbed.js
cp test/direct-100-keep.js test/direct-$width-keep.js
cp test/direct-100-panel.js test/direct-$width-panel.js
done
fi
24 changes: 24 additions & 0 deletions test/direct-10-hard-tabbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const tabbed = readFileSync('test/fixtures/in/tabbed.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Hard wrap tabbed source to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'hard',
})
renderer.write(tabbed)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-10-hard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const lorem = readFileSync('test/fixtures/in/lorem.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Hard wrap to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'hard',
})
renderer.write(lorem)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-10-keep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const ls = readFileSync('test/fixtures/in/ls.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Keep wrap to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'keep',
})
renderer.write(ls)
t.snapshot(renderer.end())
})
}
}
33 changes: 33 additions & 0 deletions test/direct-10-panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap, parsePanel} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const panel = readFileSync('test/fixtures/in/panel.txt').toString()

if ([40, 60, 80, 100].includes(Number(width))) {
test(`Direct: Panel w${width} l0 r0`, t => {
const renderer = truwrap({
left: 0,
right: 0,
width,
mode: 'soft',
})
const panelSource = parsePanel(panel, '|', renderer.getWidth())
const panelOptions = {
maxLineWidth: renderer.getWidth(),
showHeaders: false,
truncate: false,
config: panelSource.configuration,
}
renderer.panel(panelSource.content, panelOptions)
t.snapshot(renderer.end())
})
} else {
test(`Panel w${width} l0 r0`, t => {
t.pass()
})
}
24 changes: 24 additions & 0 deletions test/direct-10-soft-tabbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const tabbed = readFileSync('test/fixtures/in/tabbed.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Soft wrap tabbed source to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'soft',
})
renderer.write(tabbed)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-10-soft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const lorem = readFileSync('test/fixtures/in/lorem.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Soft wrap to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'soft',
})
renderer.write(lorem)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-20-hard-tabbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const tabbed = readFileSync('test/fixtures/in/tabbed.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Hard wrap tabbed source to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'hard',
})
renderer.write(tabbed)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-20-hard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const lorem = readFileSync('test/fixtures/in/lorem.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Hard wrap to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'hard',
})
renderer.write(lorem)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-20-keep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const ls = readFileSync('test/fixtures/in/ls.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Keep wrap to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'keep',
})
renderer.write(ls)
t.snapshot(renderer.end())
})
}
}
33 changes: 33 additions & 0 deletions test/direct-20-panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap, parsePanel} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const panel = readFileSync('test/fixtures/in/panel.txt').toString()

if ([40, 60, 80, 100].includes(Number(width))) {
test(`Direct: Panel w${width} l0 r0`, t => {
const renderer = truwrap({
left: 0,
right: 0,
width,
mode: 'soft',
})
const panelSource = parsePanel(panel, '|', renderer.getWidth())
const panelOptions = {
maxLineWidth: renderer.getWidth(),
showHeaders: false,
truncate: false,
config: panelSource.configuration,
}
renderer.panel(panelSource.content, panelOptions)
t.snapshot(renderer.end())
})
} else {
test(`Panel w${width} l0 r0`, t => {
t.pass()
})
}
24 changes: 24 additions & 0 deletions test/direct-20-soft-tabbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const tabbed = readFileSync('test/fixtures/in/tabbed.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Soft wrap tabbed source to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'soft',
})
renderer.write(tabbed)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-20-soft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const lorem = readFileSync('test/fixtures/in/lorem.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Soft wrap to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'soft',
})
renderer.write(lorem)
t.snapshot(renderer.end())
})
}
}
24 changes: 24 additions & 0 deletions test/direct-40-hard-tabbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {basename} from 'node:path'
import {fileURLToPath} from 'node:url'
import {readFileSync} from 'node:fs'
import test from 'ava'
import {truwrap} from '../index.js'

const width = basename(fileURLToPath(import.meta.url), '.js').split('-')[1] // 10, 20, 40, 60, 80, 100

const tabbed = readFileSync('test/fixtures/in/tabbed.txt').toString()

for (const right of [0, 1, 5]) {
for (const left of [0, 1, 2, 5, 10]) {
test(`Direct: Hard wrap tabbed source to w${width} l${left} r${right}`, t => {
const renderer = truwrap({
left,
right,
width,
mode: 'hard',
})
renderer.write(tabbed)
t.snapshot(renderer.end())
})
}
}
Loading

0 comments on commit bcc718d

Please sign in to comment.