diff --git a/src/mol-script/transpilers/_spec/pymol.spec.ts b/src/mol-script/transpilers/_spec/pymol.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..8e85d1281b899c2e64bc446cdf6cc9f9dfe821b6 --- /dev/null +++ b/src/mol-script/transpilers/_spec/pymol.spec.ts @@ -0,0 +1,77 @@ +/** + * 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); + expect(expr).toThrow(); + // 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")); diff --git a/src/mol-script/transpilers/_spec/pymol.spec.ts~ b/src/mol-script/transpilers/_spec/pymol.spec.ts~ new file mode 100644 index 0000000000000000000000000000000000000000..aa7a812eb2a0e4a964f82e61b26e2f289c86230d --- /dev/null +++ b/src/mol-script/transpilers/_spec/pymol.spec.ts~ @@ -0,0 +1,76 @@ +/** + * 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")); diff --git a/src/mol-script/transpilers/_spec/utils.ts b/src/mol-script/transpilers/_spec/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b6be58a3c9cdcbced77d50330830d6cba4cb7cb --- /dev/null +++ b/src/mol-script/transpilers/_spec/utils.ts @@ -0,0 +1,75 @@ +/** + * 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).toBe(p); +// 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).toBe(o); + } 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)`); + } + }); + }); +} diff --git a/src/mol-script/transpilers/_spec/utils.ts~ b/src/mol-script/transpilers/_spec/utils.ts~ new file mode 100644 index 0000000000000000000000000000000000000000..056d8b53640478c4e2dae0dcae2a214fbcaa19cb --- /dev/null +++ b/src/mol-script/transpilers/_spec/utils.ts~ @@ -0,0 +1,75 @@ +/** + * 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)`); + } + }); + }); +} diff --git a/src/mol-script/transpilers/_spec/vmd.spec.ts b/src/mol-script/transpilers/_spec/vmd.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..9b9d8557a28aea1bc55d28229d12ce250cf6d78c --- /dev/null +++ b/src/mol-script/transpilers/_spec/vmd.spec.ts @@ -0,0 +1,64 @@ + +/** + * 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); + expect(expr).toThrow(); + }); + }); + 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")); diff --git a/src/mol-script/transpilers/_spec/vmd.spec.ts~ b/src/mol-script/transpilers/_spec/vmd.spec.ts~ new file mode 100644 index 0000000000000000000000000000000000000000..30e46e2a4e0437eba88955d9e09528fbdb54e839 --- /dev/null +++ b/src/mol-script/transpilers/_spec/vmd.spec.ts~ @@ -0,0 +1,64 @@ + +/** + * 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"));