@adeu/core 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +1,66 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { readFileSync } from 'node:fs';
3
- import { resolve, dirname } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { DocumentObject } from './docx/bridge.js';
6
- import { DocumentMapper } from './mapper.js';
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = dirname(__filename);
10
-
11
- describe('Virtual DOM Mapper (Node.js Port)', () => {
12
- it('should construct a full virtual map from the DOCX', async () => {
13
- const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
14
- const buf = readFileSync(fixturePath);
15
- const doc = await DocumentObject.load(buf);
16
-
17
- const mapper = new DocumentMapper(doc);
18
-
19
- // Verify full_text was structurally mapped identically to what `ingest.ts` would produce
20
- // for the body.
21
- expect(mapper.full_text).toContain('golden');
22
- expect(mapper.full_text).toContain('document');
23
- expect(mapper.spans.length).toBeGreaterThan(0);
24
- });
25
-
26
- it('should locate target string matches via find_match_index', async () => {
27
- const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
28
- const buf = readFileSync(fixturePath);
29
- const doc = await DocumentObject.load(buf);
30
- const mapper = new DocumentMapper(doc);
31
-
32
- // Search for a word we know exists in golden.docx
33
- const [startIdx, len] = mapper.find_match_index('golden');
34
-
35
- expect(startIdx).toBeGreaterThan(0);
36
- expect(len).toBe(6); // 'golden'.length
37
- });
38
-
39
- it('should resolve strings back to physical Run elements', async () => {
40
- const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
41
- const buf = readFileSync(fixturePath);
42
- const doc = await DocumentObject.load(buf);
43
- const mapper = new DocumentMapper(doc);
44
-
45
- // Find the backing physical Run elements for the target string
46
- const runs = mapper.find_target_runs('golden');
47
-
48
- // Ensure we successfully crossed the Virtual DOM boundary
49
- expect(runs.length).toBeGreaterThan(0);
50
- expect(runs[0].constructor.name).toBe('Run');
51
-
52
- // Underneath, the Run must contain the real xmldom Element reference
53
- expect(runs[0]._element).toBeDefined();
54
- expect(runs[0]._element.tagName).toBe('w:r');
55
- });
56
-
57
- it('should safely return empty arrays for non-existent text', async () => {
58
- const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
59
- const buf = readFileSync(fixturePath);
60
- const doc = await DocumentObject.load(buf);
61
- const mapper = new DocumentMapper(doc);
62
-
63
- const runs = mapper.find_target_runs('NON_EXISTENT_TEXT_12345');
64
- expect(runs.length).toBe(0);
65
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readFileSync } from 'node:fs';
3
+ import { resolve, dirname } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { DocumentObject } from './docx/bridge.js';
6
+ import { DocumentMapper } from './mapper.js';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ describe('Virtual DOM Mapper (Node.js Port)', () => {
12
+ it('should construct a full virtual map from the DOCX', async () => {
13
+ const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
14
+ const buf = readFileSync(fixturePath);
15
+ const doc = await DocumentObject.load(buf);
16
+
17
+ const mapper = new DocumentMapper(doc);
18
+
19
+ // Verify full_text was structurally mapped identically to what `ingest.ts` would produce
20
+ // for the body.
21
+ expect(mapper.full_text).toContain('golden');
22
+ expect(mapper.full_text).toContain('document');
23
+ expect(mapper.spans.length).toBeGreaterThan(0);
24
+ });
25
+
26
+ it('should locate target string matches via find_match_index', async () => {
27
+ const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
28
+ const buf = readFileSync(fixturePath);
29
+ const doc = await DocumentObject.load(buf);
30
+ const mapper = new DocumentMapper(doc);
31
+
32
+ // Search for a word we know exists in golden.docx
33
+ const [startIdx, len] = mapper.find_match_index('golden');
34
+
35
+ expect(startIdx).toBeGreaterThan(0);
36
+ expect(len).toBe(6); // 'golden'.length
37
+ });
38
+
39
+ it('should resolve strings back to physical Run elements', async () => {
40
+ const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
41
+ const buf = readFileSync(fixturePath);
42
+ const doc = await DocumentObject.load(buf);
43
+ const mapper = new DocumentMapper(doc);
44
+
45
+ // Find the backing physical Run elements for the target string
46
+ const runs = mapper.find_target_runs('golden');
47
+
48
+ // Ensure we successfully crossed the Virtual DOM boundary
49
+ expect(runs.length).toBeGreaterThan(0);
50
+ expect(runs[0].constructor.name).toBe('Run');
51
+
52
+ // Underneath, the Run must contain the real xmldom Element reference
53
+ expect(runs[0]._element).toBeDefined();
54
+ expect(runs[0]._element.tagName).toBe('w:r');
55
+ });
56
+
57
+ it('should safely return empty arrays for non-existent text', async () => {
58
+ const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
59
+ const buf = readFileSync(fixturePath);
60
+ const doc = await DocumentObject.load(buf);
61
+ const mapper = new DocumentMapper(doc);
62
+
63
+ const runs = mapper.find_target_runs('NON_EXISTENT_TEXT_12345');
64
+ expect(runs.length).toBe(0);
65
+ });
66
66
  });