hindiscript-lang
Version:
HindiScript – A tiny Hindi-first toy language that runs .hs files. Created by Atikin Verse.
45 lines (38 loc) • 1.21 kB
JavaScript
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
function run(file) {
const out = execFileSync(process.execPath, [path.resolve('bin/hindiscript'), file], {
encoding: 'utf8'
});
return out.trim().split(/\r?\n/);
}
const expected = JSON.parse(fs.readFileSync(path.resolve('tests/expected.json'), 'utf8'));
const cases = [
['examples/hello.hs', expected.hello],
['examples/control_flow.hs', expected.control_flow],
['examples/functions.hs', expected.functions],
['examples/arrays_objects.hs', expected.arrays_objects]
];
let pass = 0;
for (const [file, want] of cases) {
const got = run(file);
const ok = arraysEqual(got, want);
console.log(`${ok ? '✅' : '❌'} ${file}`);
if (!ok) {
console.log('Expected:', want);
console.log('Got :', got);
process.exitCode = 1;
} else {
pass++;
}
}
console.log(`\n${pass}/${cases.length} test(s) passed.`);
function arraysEqual(a, b) {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) return false;
}
return true;
}