Skip to content

Commit

Permalink
delete #export syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Sep 6, 2024
1 parent 25799b1 commit 550f157
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
6 changes: 3 additions & 3 deletions bin/heta-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ program
.description('Compile Heta based platform and create set of export files.')
//.arguments('<cmd> [dir]')
.usage('[options] [dir]')
.option('-d, --declaration <filepath>', 'declaration file name without extension to search throught extensions: ["", ".json", ".json5", ".yml"]')
.option('-d, --declaration <filepath>', 'declaration file name without extension to search throught extensions: ["", ".json", ".yml"]')
// options
.option('--units-check', 'Check all Records for unit consistency.')
.option('-L, --log-mode <never|error|always>', 'When to create log file.')
Expand All @@ -33,7 +33,7 @@ program
// moduleImport
.option('-s, --source <filepath>', 'path to main heta module.')
.option('-t, --type <heta|table|xlsx|json|yaml|sbml>', 'type of source file.')
.option('-e, --export <formats>', 'format names or structures: "JSON,XLSX" or "{format:JSON},{format:XLSX,omitRows:3}"')
.option('-e, --export <formats>', 'export formats: "JSON,XLSX" or "{format:JSON},{format:XLSX,omitRows:3}"')
// checking newer version of heta-compiler
.option('--skip-updates', 'Skip checking newer version of heta-compiler.')
.parse(process.argv);
Expand All @@ -53,7 +53,7 @@ async function main() {

// === read declaration file ===
// search
let searches = ['', '.json', '.json5', '.yml']
let searches = ['', '.json', '.yml']
.map((ext) => path.join(targetDir, (opts.declaration || 'platform') + ext));
let extensionNumber = searches
.map((x) => fs.existsSync(x) && fs.statSync(x).isFile() ) // check if it exist and is file
Expand Down
9 changes: 3 additions & 6 deletions src/container/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const reservedWords = [
* The inheritor depends on `q.format` property.
* For example `{id: 'output', format: 'JSON', ...}` creates the object of `JSONExport` type.
*
* @param {object} q The `#export` statement in JS object format.
* @param {object} q The `export` object in JS object format.
* @param {Boolean} isCore Set element as a "core" which means you cannot rewrite or delete it.
*
* @returns {AbstractExport} The created object.
Expand All @@ -25,14 +25,11 @@ const reservedWords = [
Container.prototype.export = function(q = {}, isCore = false) {
let { exportClasses, exportArray } = this._builder;
if (q.format === undefined) {
this.logger.error(
'Empty "format" option in #export',
{type: 'QError'}
);
this.logger.error('Empty "format" option in export', {type: 'QError'});
return; // BRAKE
}
if (typeof exportClasses[q.format] !== 'function') {
this.logger.error(`Unknown format "${q.format}" in #export action.`, {type: 'QError'});
this.logger.error(`Unknown format "${q.format}" in export.`, {type: 'QError'});

return; // BRAKE
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/simbio.m.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
This model was created by Heta compiler.
Additional functions see in the directory
export from : #export { format: Simbio, namespace: {{ population.spaceName }}, ...};
export from : { format: Simbio, namespace: {{ population.spaceName }}, ...};
%}

%sbioaddtolibrary(sbiounit('week', 'day', 7));
Expand Down
16 changes: 8 additions & 8 deletions test/cases/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,45 @@ describe('Testing "cases/0-hello-world"', () => {
b.run();
});

it('Run #export {format: SBML}, check and compare.', () => {
it('Run {format: SBML}, check and compare.', () => {
let sbml_export = b.exportArray[0];
let code = sbml_export.makeText(true)[0].content;
expect(code).xml.to.to.be.valid();
expect(code).xml.be.deep.equal(sbml_l2v4_correct);
});

it('Run #export {format: SBML}, check and compare.', () => {
it('Run export {format: SBML}, check and compare.', () => {
let sbml_export = b.exportArray[1];
let code = sbml_export.makeText(true)[0].content;
expect(code).xml.to.to.be.valid();
expect(code).xml.be.deep.equal(sbml_l3v1_correct);
});

it('Run #export {format: JSON}, check and compare.', () => {
it('Run export {format: JSON}, check and compare.', () => {
let json_export = b.exportArray[2];
let code = json_export.makeText(true)[0].content;
let obj = JSON.parse(code);
expect(obj).to.be.deep.equal(json_correct);
//console.log(obj);
});

it('Run #export {format: YAML}, check and compare.', () => {
it('Run export {format: YAML}, check and compare.', () => {
let yaml_export = b.exportArray[3];
let code = yaml_export.makeText(true)[0].content;
let obj = load(code);
expect(obj).to.be.deep.equal(yaml_correct);
//console.log(code);
});

it('Run #export {format: SLV}, check and compare.', () => {
it('Run export {format: SLV}, check and compare.', () => {
let slv_export = b.exportArray[4];
let code = slv_export.makeText(true)[0].content;
let obj = slvParse.parse(code);
expect(obj).to.be.deep.equal(slv_correct);
//console.log(obj);
});

it('Run #export {format: XLSX}, check and compare.', () => {
it('Run export {format: XLSX}, check and compare.', () => {
let xlsx_export = b.exportArray[5];
let code = xlsx_export.makeSheet(true); // check only sheet #0

Expand All @@ -121,7 +121,7 @@ describe('Testing "cases/0-hello-world"', () => {
//console.log(correctJSON_0);
});

it('Run #export {format: Mrgsolve}, check and compare.', () => {
it('Run export {format: Mrgsolve}, check and compare.', () => {
let mm_mrg = b.exportArray[6];
let code = mm_mrg.makeText(true);
// compare model.cpp text content
Expand All @@ -130,7 +130,7 @@ describe('Testing "cases/0-hello-world"', () => {
expect(code[0].content).to.be.equal(mrgsolve_correct);
});

it('Run #export {format: Julia}, check and compare.', () => {
it('Run export {format: Julia}, check and compare.', () => {
let mm_mrg = b.exportArray[7];
let code = mm_mrg.makeText(true);
// compare model.js text content
Expand Down
16 changes: 8 additions & 8 deletions test/export/export-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Create JSON Export with #export', () => {
it('Create JSON Export with export', () => {
let json_export = p.export({
format: 'JSON',
filepath: './_1.json'
Expand All @@ -36,7 +36,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: no "format"', () => {
it('Error in export: no "format"', () => {
let json_export = p.export({
filepath: './1.json'
});
Expand All @@ -45,7 +45,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: wrong "format"', () => {
it('Error in export: wrong "format"', () => {
let json_export = p.export({
format: 'XXX',
filepath: '1'
Expand All @@ -55,7 +55,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: no "filepath"', () => {
it('Error in export: no "filepath"', () => {
let json_export = p.export({
format: 'JSON'
});
Expand All @@ -65,7 +65,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: wrong "filepath"', () => {
it('Error in export: wrong "filepath"', () => {
let json_export = p.export({
format: 'JSON',
filepath: './@1.xxx'
Expand All @@ -75,7 +75,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: wrong "omit"', () => {
it('Error in export: wrong "omit"', () => {
let json_export = p.export({
format: 'JSON',
filepath: './1.txt',
Expand All @@ -87,7 +87,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: wrong "noUnitsExpr"', () => {
it('Error in export: wrong "noUnitsExpr"', () => {
let json_export = p.export({
format: 'JSON',
filepath: './1.txt',
Expand All @@ -98,7 +98,7 @@ describe('General argument checking', () => {
p.logger.resetErrors();
});

it('Error in #export: wrong "spaceFilter"', () => {
it('Error in export: wrong "spaceFilter"', () => {
let json_export = p.export({
format: 'JSON',
filepath: './1.txt',
Expand Down

0 comments on commit 550f157

Please sign in to comment.