const ScopeParser = require("../lib/ScopeParser.js");
const fs = require('fs');
const path = require('path');
const beautify = require('js-beautify').js_beautify;
const assert = require('assert');

let scope = new ScopeParser();
let srcDir = path.join(__dirname, "scopeSrc");
let libDir = path.join(__dirname, "scopeLib"); 
let expectDir = path.join(__dirname, "scopeExpect");
let srcFiles = fs.readdirSync(srcDir);

const tests = [];

srcFiles.forEach((f) => {
	let srcFilename = path.join(srcDir, f);
	let libFilename = path.join(libDir, f.replace(".sc", ".js"));
	let expectFilename = path.join(expectDir, f.replace(".sc", ".js"));
	//let astFilename = path.join(libDir, f.replace(".sc", ".json"));
	let srcCode = fs.readFileSync(srcFilename, "utf8");
	let translation = scope.translate(srcCode);
	//let libAst = JSON.stringify(translation.ast, null, "  ");
	//fs.writeFileSync(astFilename, libAst);
	fs.writeFileSync(libFilename, beautify(translation.js, {indent_size: 2}));
	tests.push({
		program: require(libFilename),
		expectation: require(expectFilename)
	});
});

tests.forEach((obj) => {
	obj.expectation(assert, obj.program);
});
@@ -896,16 +896,74 @@
 ibAst);%0A
+%09if (!fs.existsSync(libDir)) %7B%0A%09%09fs.mkdirSync(libDir);%0A%09%7D%0A
 %09fs.writ

Create lib dir if it doesn't exist