LemonJS/test.js

66 lines
2.3 KiB
JavaScript

/**
* Created by Aleksey Chichenkov <a.chichenkov@initi.ru> on 1/29/19.
*/
var fs = require("fs");
var exec = require('child_process').exec;
var args = require("args-parser")(process.argv);
var cfg_path = "config.js";
var config;
if(args["c"] !== undefined) {
config = require("./" + args["c"]);
cfg_path = args["c"];
} else {
config = require("./config.js");
}
exec("node main.js -o=" + cfg_path + " -t=node", function(err, stdout, stderr) {
err && console.log("ERROR: ", err);
err && process.exit(1);
test();
});
var test = function() {
var LemonJS = require("./" + config.input_path + "/" + config.file_name + ".js");
if (!fs.existsSync("tests")) {
fs.mkdirSync("tests");
}
var test_and = LemonJS("abc == 1 and abc1 == 2 and (bbc == 5)").tree;
fs.writeFileSync("./tests/test_and.json", JSON.stringify(test_and, true, 3));
var test_address = LemonJS('abc == Address ["a", "b", "c"]').tree;
fs.writeFileSync("./tests/test_address.json", JSON.stringify(test_address, true, 3));
var test_float = LemonJS('abc == 23.2').tree;
fs.writeFileSync("./tests/test_float.json", JSON.stringify(test_float, true, 3));
var test_string = LemonJS('abc == "sadfasdf"').tree;
fs.writeFileSync("./tests/test_string.json", JSON.stringify(test_string, true, 3));
var test_bool = LemonJS('abc == true or cab == false').tree;
fs.writeFileSync("./tests/test_bool.json", JSON.stringify(test_bool, true, 3));
var test_not = LemonJS('not cab == false').tree;
fs.writeFileSync("./tests/test_not.json", JSON.stringify(test_not, true, 3));
var test_oid = LemonJS('abc == Oid[1.2.3] and abd == Oid [ 1.2.3 ]').tree;
fs.writeFileSync("./tests/test_oid.json", JSON.stringify(test_oid, true, 3));
var test_timediff = LemonJS('add == TimeDiff [17924 15:01:24 441000]').tree;
fs.writeFileSync("./tests/test_timediff.json", JSON.stringify(test_timediff, true, 3));
var test_time = LemonJS('add == Time [29/12/2019 15:01:24 441000]').tree;
fs.writeFileSync("./tests/test_time.json", JSON.stringify(test_time, true, 3));
var test_exp_1 = LemonJS('(add == Time [29/12/2019 15:01:24 441000]) and ddds == "sdfasdf" or a == 123 and v == 155').tree;
fs.writeFileSync("./tests/test_exp_1.json", JSON.stringify(test_exp_1, true, 3));
};