Skip to content
Snippets Groups Projects
Commit 2ccfdb12 authored by yakomaxa's avatar yakomaxa
Browse files

added _spec (not tested whether it works)

parent 9fbf8006
Branches
No related tags found
No related merge requests found
/**
* Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Panagiotis Tourlas <panagiot_tourlov@hotmail.com>
*/
import * as u from './utils';
import { parse } from '../../transpile';
//import { transpiler } from '../pymol/parser';
import { keywords } from '../pymol/keywords';
import { properties } from '../pymol/properties';
import { operators } from '../pymol/operators';
/* FAULTY IMPORTS */
import compile from '../../compiler';
const general = {
supported: [
// macros
'10/cb',
'a/10-12/ca',
'lig/b/6+8/c+o',
// trimming
' name CA ',
'name CA ',
' name CA',
],
unsupported: [
// macros
'pept/enz/c/3/n',
'pept/enz///n',
'/pept/lig/',
'/pept/lig/a',
'/pept/lig/a/10',
'/pept/lig/a/10/ca',
'/pept//a/10',
// object
'foobar',
'protein and bazbar',
]
};
describe('pymol general', () => {
general.supported.forEach(str => {
it(str, () => {
const expr = parse("pymol",str);
compile(expr);
});
});
general.unsupported.forEach(str => {
it(str, () => {
const transpileStr = () => parse("pymol",str);
expect(transpileStr).toThrow();
expect(transpileStr).not.toThrowError(RangeError);
});
});
});
// check against builder output
// 'not (resi 42 or chain A)'
// '!resi 42 or chain A'
// 'b >= 0.3',
// 'b != 0.3',
// 'b>0.3',
// 'b <0.3',
// 'b <= 0.3',
// 'b = 1',
// 'fc.=.1',
describe('pymol keywords', () => u.testKeywords(keywords, "pymol"));
describe('pymol operators', () => u.testOperators(operators, "pymol"));
describe('pymol properties', () => u.testProperties(properties, "pymol"));
/**
* Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Panagiotis Tourlas <panangiot_tourlov@hotmail.com>
*/
import { parse } from '../../transpile';
import { KeywordDict, PropertyDict, OperatorList } from '../types';
/* FAULTY IMPORTS */
//import compile from '../../compiler';
export function testKeywords(keywords: KeywordDict,language: string) {
for (const name in keywords) {
it(name, () => {
const k = keywords[name];
if (k.map) {
const expr = parse(language,name);
// compile(expr);
expect(expr).toEqual(k.map());
} else {
const transpile = () => parse(language,name);
expect(transpile).toThrow();
expect(transpile).not.toThrowError(RangeError);
}
});
}
}
export function testProperties(properties: PropertyDict, language : string) {
for (const name in properties) {
const p = properties[name];
p['@examples'].forEach(example => {
it(name, () => {
if (!p.isUnsupported) {
const expr = parse(language,example);
expect(expr).toThrow();
// compile(expr);
} else {
const transpile = () => parse(language,example);
expect(transpile).toThrow();
expect(transpile).not.toThrowError(RangeError);
}
});
});
it(name, () => {
if (!p['@examples'].length) {
throw Error(`'${name}' property has no example(s)`);
}
});
}
}
export function testOperators(operators: OperatorList,language: string) {
operators.forEach(o => {
o['@examples'].forEach(example => {
it(o.name, () => {
if (!o.isUnsupported) {
const expr = parse(language,example);
expect(expr).toThrow();
} else {
const transpile = () => parse(language,example);
expect(transpile).toThrow();
expect(transpile).not.toThrowError(RangeError);
}
});
});
it(o.name, () => {
if (!o['@examples'].length) {
throw Error(`'${o.name}' operator has no example(s)`);
}
});
});
}
/**
* Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Panagiotis Tourlas <panagiot_tourlov@hotmail.com>
*/
import * as u from './utils';
//import { transpiler } from '../vmd/parser';
import { parse } from '../../transpile';
import { keywords } from '../vmd/keywords';
import { properties } from '../vmd/properties';
import { operators } from '../vmd/operators';
/* FAULTY IMPORTS */
import compile from '../../compiler';
const general = {
supported: [
// trimming
' name CA ',
'name CA ',
' name CA',
],
unsupported: [
// variables
'name $atomname',
'protein and @myselection',
// values outside of comparisons
'foobar',
'34',
'name',
'abs(-42)',
'abs(21+21)',
'sqr(3)',
'sqr(x)',
'sqr(x+33)',
'protein or foobar',
'34 and protein',
'name or protein',
]
};
describe('vmd general', () => {
general.supported.forEach(str => {
it(str, () => {
const expr = parse("vmd",str);
compile(expr);
});
});
general.unsupported.forEach(str => {
it(str, () => {
const transpileStr = () => parse("vmd",str);
expect(transpileStr).toThrow();
expect(transpileStr).not.toThrowError(RangeError);
});
});
});
describe('vmd keywords', () => u.testKeywords(keywords, "vmd"));
describe('vmd operators', () => u.testOperators(operators, "vmd"));
describe('vmd properties', () => u.testProperties(properties, "vmd"));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment