All JS and Python tests passing.

This commit is contained in:
Joshua Bemenderfer 2023-02-10 13:07:10 -05:00
parent e72ff2eccf
commit c41990b793
4 changed files with 28 additions and 20 deletions

View File

@ -6,12 +6,17 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
from parser import createLineData, parseLine
def next():
return sys.stdin.readline().rstrip('\n')
# For blank lines, readline will return a newline.
# For no result, readline will return a string of length 0.
line = sys.stdin.readline()
# Since we strip trailing newlines resulting in an empty string for empty lines,
# return None if there actually is no result.
return line.rstrip('\n') if len(line) > 0 else None
def linedata_basic ():
lineData = createLineData('')
while l := next():
while (l := next()) != None:
lineData['line'] = l
parseLine(lineData)
print("| level {level} | indent {indent} | offsetHead {offsetHead} | offsetTail {offsetTail} | line {line} |".format(
@ -21,7 +26,7 @@ def linedata_basic ():
def linedata_tabs ():
lineData = createLineData('', '\t')
while l := next():
while (l := next()) != None:
lineData['line'] = l
parseLine(lineData)
print("| level {level} | indent {indent} | offsetHead {offsetHead} | offsetTail {offsetTail} | line {line} |".format(
@ -31,10 +36,10 @@ def linedata_tabs ():
def linedata_head_tail ():
lineData = createLineData('')
while l := next():
while (l := next()) != None:
lineData['line'] = l
parseLine(lineData)
head = lineData['line'][lineData['offsetHead']:lineData['offsetTail']] if len(lineData['line']) > lineData['offsetTail'] else ''
head = lineData['line'][lineData['offsetHead']:lineData['offsetTail']] if len(lineData['line']) > lineData['offsetHead'] else ''
tail = lineData['line'][lineData['offsetTail'] + 1:] if len(lineData['line']) > lineData['offsetTail'] + 1 else ''
print("| head {head} | tail {tail} |".format(

View File

@ -4,7 +4,7 @@ import { execSync } from 'node:child_process'
import { useDocument } from '@terrace/core'
import { createFileReader } from '@terrace/core/readers/node-readline'
async function loadTests(path) {
export async function loadTestMap(path) {
const { next, level, head, tail, line, match } = useDocument(createFileReader(path))
const descriptions = {}
@ -58,6 +58,20 @@ async function loadTests(path) {
return descriptions
}
export function defineTests(testMap) {
for (const [name, tests] of Object.entries(testMap)) {
describe(name, () => {
for (const test of tests) {
test.packages.forEach(pkg => {
it(`${pkg}: ${test.it}`, async () => {
expect(await callTest(pkg, test.key, test.input)).to.equal(test.output)
})
})
}
})
}
}
function callTest(pkg, name, input) {
return new Promise((resolve, reject) => {
const stdout = execSync(`npm run --silent test ${name}`, {
@ -69,17 +83,3 @@ function callTest(pkg, name, input) {
resolve(stdout.toString().trim())
})
}
const descriptions = await loadTests('./tests.tce')
for (const [name, tests] of Object.entries(descriptions)) {
describe(name, () => {
for (const test of tests) {
test.packages.forEach(pkg => {
it(`${pkg}: ${test.it}`, async () => {
expect(await callTest(pkg, test.key, test.input)).to.equal(test.output)
})
})
}
})
}

3
test/lineData.test.js Normal file
View File

@ -0,0 +1,3 @@
import { loadTestMap, defineTests } from './helpers.js'
defineTests(await loadTestMap('./lineData.test.tce'))