瀏覽代碼

added _spec (not tested whether it works)

yakomaxa 2 年之前
父節點
當前提交
9fbf800639

+ 77 - 0
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"));

+ 76 - 0
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"));

+ 75 - 0
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)`);
+            }
+        });
+    });
+}

+ 75 - 0
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)`);
+            }
+        });
+    });
+}

+ 64 - 0
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"));

+ 64 - 0
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"));