-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsdf-parser.test.ts
More file actions
102 lines (82 loc) · 3 KB
/
Copy pathsdf-parser.test.ts
File metadata and controls
102 lines (82 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { readFileSync } from 'fs';
import { join } from 'path';
import { describe, it, expect } from 'vitest';
import { parseSdf } from '../src/sdf-parser';
const SDF_PATH = join(__dirname, 'data', 'missing_names.sdf');
const sdfContent = readFileSync(SDF_PATH, 'utf-8');
const NO_NAME_PATH = join(__dirname, 'data', 'no_name_at_all.sdf');
const noNameContent = readFileSync(NO_NAME_PATH, 'utf-8');
describe('parseSdf – missing_names.sdf', () => {
const mols = parseSdf(sdfContent);
it('parses exactly 3 molecules', () => {
expect(mols).toHaveLength(3);
});
it('mol 1 – title "with_name" is on the first molblock line', () => {
const firstLine = mols[0].molblock.split('\n')[0];
expect(firstLine).toBe('with_name');
});
it('mol 2 – blank title line is preserved (molblock starts with \\n)', () => {
expect(mols[1].molblock.startsWith('\n')).toBe(true);
const firstLine = mols[1].molblock.split('\n')[0];
expect(firstLine).toBe('');
});
it('mol 3 – title "caffeine" is on the first molblock line', () => {
const firstLine = mols[2].molblock.split('\n')[0];
expect(firstLine).toBe('caffeine');
});
it('all 3 molecules have M END in their molblock', () => {
for (const mol of mols) {
expect(mol.molblock).toContain('M END');
}
});
it('all 3 molecules have PUBCHEM_COMPOUND_CID = "2519"', () => {
for (const mol of mols) {
expect(mol.properties['PUBCHEM_COMPOUND_CID']).toBe('2519');
}
});
});
describe('parseSdf – no_name_at_all.sdf', () => {
const mols = parseSdf(noNameContent);
it('parses exactly 2 molecules', () => {
expect(mols).toHaveLength(2);
});
it('mol 1 – blank title line is preserved (molblock starts with \\n)', () => {
expect(mols[0].molblock.startsWith('\n')).toBe(true);
const firstLine = mols[0].molblock.split('\n')[0];
expect(firstLine).toBe('');
});
it('mol 2 – blank title line is preserved (molblock starts with \\n)', () => {
expect(mols[1].molblock.startsWith('\n')).toBe(true);
const firstLine = mols[1].molblock.split('\n')[0];
expect(firstLine).toBe('');
});
it('both molecules have M END in their molblock', () => {
for (const mol of mols) {
expect(mol.molblock).toContain('M END');
}
});
it('neither molecule has properties', () => {
for (const mol of mols) {
expect(Object.keys(mol.properties)).toHaveLength(0);
}
});
});
const DUP_PATH = join(__dirname, 'data', 'dup_names.sdf');
const dupContent = readFileSync(DUP_PATH, 'utf-8');
describe('parseSdf – dup_names.sdf', () => {
const mols = parseSdf(dupContent);
it('parses exactly 2 molecules', () => {
expect(mols).toHaveLength(2);
});
it('both molecules have molblock title "compound"', () => {
for (const mol of mols) {
const firstLine = mol.molblock.split('\n')[0];
expect(firstLine).toBe('compound');
}
});
it('both molecules contain M END', () => {
for (const mol of mols) {
expect(mol.molblock).toContain('M END');
}
});
});