blob: 8c2ce1d2c82767f88a1e661d204f94e93d216b20 [file] [log] [blame]
Marc Kupietzb43a5182024-02-03 18:09:10 +01001const { execSync } = require('child_process');
2const exp = require('constants');
3
4describe('conllu2cmc', () => {
5 test('Test sparse mode', (done) => {
6 // Modify the command based on your script's location and options
7 const command = 'node src/index.js -s < test/data/ndy.conllu';
8 const stdout = execSync(command).toString();
9 expect(stdout).toContain('😂\t_\tEMOIMG\tEMOIMG');
10 var emoimg_count = (stdout.match(/EMOIMG/g) || []).length;
11 expect(emoimg_count).toBe(382);
12 var ascimg_count = (stdout.match(/EMOASC/g) || []).length;
13 expect(ascimg_count).toBe(60);
14 var ascimg_count = (stdout.match(/URL/g) || []).length;
15 expect(ascimg_count).toBe(8);
16 var adr_count = (stdout.match(/ADR/g) || []).length;
17 expect(adr_count).toBe(2);
Marc Kupietzfd92b1d2024-03-13 10:51:29 +010018 var eot_count = (stdout.match(/\n# eot/g) || []).length;
19 expect(eot_count).toBe(1);
20 var eof_count = (stdout.match(/\n# eof/g) || []).length;
21 expect(eof_count).toBe(1);
Marc Kupietzb43a5182024-02-03 18:09:10 +010022 var lines_count = (stdout.split("\n")).length;
Marc Kupietzfd92b1d2024-03-13 10:51:29 +010023 expect(lines_count).toBe(746);
Marc Kupietzb43a5182024-02-03 18:09:10 +010024 done();
25 });
26
27 test('Test full mode', (done) => {
28 const command = 'node src/index.js < test/data/ndy.conllu';
29 const stdout = execSync(command).toString();
30 expect(stdout).toContain('😂\t_\tEMOIMG\tEMOIMG');
31 var emoimg_count = (stdout.match(/EMOIMG/g) || []).length;
32 expect(emoimg_count).toBe(382);
33 var ascimg_count = (stdout.match(/EMOASC/g) || []).length;
34 expect(ascimg_count).toBe(60);
35 var ascimg_count = (stdout.match(/URL/g) || []).length;
36 expect(ascimg_count).toBe(8);
37 var adr_count = (stdout.match(/ADR/g) || []).length;
38 expect(adr_count).toBe(2);
39 var lines_count = (stdout.split("\n")).length;
Marc Kupietzfd92b1d2024-03-13 10:51:29 +010040 expect(lines_count).toBe(6202);
Marc Kupietzb43a5182024-02-03 18:09:10 +010041 done();
42 });
Marc Kupietzb5d80b32025-12-11 15:48:09 +010043
44 test('Regression test for issue #113: emoji modifiers and ZWJ', (done) => {
45 // Test that compound emojis with modifiers and ZWJ are recognized as single EMOIMG tokens
46 const testInput = `# foundry = base
47# text_id = test-113
48# text = ✊🏿 and 👨‍👨‍👦
491 ✊🏿 _ _ _ _ _ _ _ _
502 and _ CCONJ _ _ _ _ _ _
513 👨‍👨‍👦 _ _ _ _ _ _ _ _
52
53`;
54 const { execSync } = require('child_process');
55 const stdout = execSync('node src/index.js', { input: testInput }).toString();
56
57 // Check that compound emojis are tagged as EMOIMG
58 expect(stdout).toContain('✊🏿\t_\tEMOIMG\tEMOIMG');
59 expect(stdout).toContain('👨‍👨‍👦\t_\tEMOIMG\tEMOIMG');
60
61 // Count EMOIMG occurrences (should be 2 for each emoji - columns 3 and 4)
62 var emoimg_count = (stdout.match(/EMOIMG/g) || []).length;
63 expect(emoimg_count).toBe(4); // 2 emojis × 2 columns = 4
64 done();
65 });
66
Marc Kupietz7497fc42025-12-11 15:47:34 +010067 test('Regression test for issue #114: Wikipedia emoji templates', (done) => {
68 // Test that Wikipedia emoji templates are recognized as EMOWIKI tokens
69 const testInput = `# foundry = base
70# text_id = test-114
71# text = [_EMOJI:{{S|;)}}_] and [_EMOJI:{{cool}}_]
721 [_EMOJI:{{S|;)}}_] _ _ _ _ _ _ _ _
732 and _ CCONJ _ _ _ _ _ _
743 [_EMOJI:{{cool}}_] _ _ _ _ _ _ _ _
75
76`;
77 const { execSync } = require('child_process');
78 const stdout = execSync('node src/index.js', { input: testInput }).toString();
79
80 // Check that Wikipedia emoji templates are tagged as EMOWIKI
81 expect(stdout).toContain('[_EMOJI:{{S|;)}}_]\t_\tEMOWIKI\tEMOWIKI');
82 expect(stdout).toContain('[_EMOJI:{{cool}}_]\t_\tEMOWIKI\tEMOWIKI');
83
84 // Count EMOWIKI occurrences (should be 2 for each template - columns 3 and 4)
85 var emowiki_count = (stdout.match(/EMOWIKI/g) || []).length;
86 expect(emowiki_count).toBe(4); // 2 templates × 2 columns = 4
87 done();
88 });
Marc Kupietzb43a5182024-02-03 18:09:10 +010089});