All JS and Python tests passing.
This commit is contained in:
parent
e72ff2eccf
commit
c41990b793
@ -6,12 +6,17 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
|||||||
from parser import createLineData, parseLine
|
from parser import createLineData, parseLine
|
||||||
|
|
||||||
def next():
|
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 ():
|
def linedata_basic ():
|
||||||
lineData = createLineData('')
|
lineData = createLineData('')
|
||||||
|
|
||||||
while l := next():
|
while (l := next()) != None:
|
||||||
lineData['line'] = l
|
lineData['line'] = l
|
||||||
parseLine(lineData)
|
parseLine(lineData)
|
||||||
print("| level {level} | indent {indent} | offsetHead {offsetHead} | offsetTail {offsetTail} | line {line} |".format(
|
print("| level {level} | indent {indent} | offsetHead {offsetHead} | offsetTail {offsetTail} | line {line} |".format(
|
||||||
@ -21,7 +26,7 @@ def linedata_basic ():
|
|||||||
def linedata_tabs ():
|
def linedata_tabs ():
|
||||||
lineData = createLineData('', '\t')
|
lineData = createLineData('', '\t')
|
||||||
|
|
||||||
while l := next():
|
while (l := next()) != None:
|
||||||
lineData['line'] = l
|
lineData['line'] = l
|
||||||
parseLine(lineData)
|
parseLine(lineData)
|
||||||
print("| level {level} | indent {indent} | offsetHead {offsetHead} | offsetTail {offsetTail} | line {line} |".format(
|
print("| level {level} | indent {indent} | offsetHead {offsetHead} | offsetTail {offsetTail} | line {line} |".format(
|
||||||
@ -31,10 +36,10 @@ def linedata_tabs ():
|
|||||||
def linedata_head_tail ():
|
def linedata_head_tail ():
|
||||||
lineData = createLineData('')
|
lineData = createLineData('')
|
||||||
|
|
||||||
while l := next():
|
while (l := next()) != None:
|
||||||
lineData['line'] = l
|
lineData['line'] = l
|
||||||
parseLine(lineData)
|
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 ''
|
tail = lineData['line'][lineData['offsetTail'] + 1:] if len(lineData['line']) > lineData['offsetTail'] + 1 else ''
|
||||||
|
|
||||||
print("| head {head} | tail {tail} |".format(
|
print("| head {head} | tail {tail} |".format(
|
||||||
|
@ -4,7 +4,7 @@ import { execSync } from 'node:child_process'
|
|||||||
import { useDocument } from '@terrace/core'
|
import { useDocument } from '@terrace/core'
|
||||||
import { createFileReader } from '@terrace/core/readers/node-readline'
|
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 { next, level, head, tail, line, match } = useDocument(createFileReader(path))
|
||||||
|
|
||||||
const descriptions = {}
|
const descriptions = {}
|
||||||
@ -58,6 +58,20 @@ async function loadTests(path) {
|
|||||||
return descriptions
|
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) {
|
function callTest(pkg, name, input) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const stdout = execSync(`npm run --silent test ${name}`, {
|
const stdout = execSync(`npm run --silent test ${name}`, {
|
||||||
@ -69,17 +83,3 @@ function callTest(pkg, name, input) {
|
|||||||
resolve(stdout.toString().trim())
|
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
3
test/lineData.test.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { loadTestMap, defineTests } from './helpers.js'
|
||||||
|
|
||||||
|
defineTests(await loadTestMap('./lineData.test.tce'))
|
Loading…
x
Reference in New Issue
Block a user