| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 1 | const { execSync } = require('child_process'); |
| 2 | const exp = require('constants'); |
| Marc Kupietz | 20f33d9 | 2026-04-12 14:27:57 +0200 | [diff] [blame] | 3 | const packageVersion = require('../package.json').version; |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 4 | |
| 5 | describe('conllu2cmc', () => { |
| 6 | test('Test sparse mode', (done) => { |
| 7 | // Modify the command based on your script's location and options |
| 8 | const command = 'node src/index.js -s < test/data/ndy.conllu'; |
| 9 | const stdout = execSync(command).toString(); |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 10 | expect(stdout).toContain('😂\t😂\t_\tEMOIMG'); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 11 | var emoimg_count = (stdout.match(/EMOIMG/g) || []).length; |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 12 | expect(emoimg_count).toBe(191); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 13 | var ascimg_count = (stdout.match(/EMOASC/g) || []).length; |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 14 | expect(ascimg_count).toBe(30); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 15 | var hst_count = (stdout.match(/\tHST\t/g) || []).length; |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 16 | expect(hst_count).toBe(12); |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 17 | var url_count = (stdout.match(/\tURL\t/g) || []).length; |
| 18 | expect(url_count).toBe(4); |
| 19 | var adr_count = (stdout.match(/\tADR\t/g) || []).length; |
| 20 | expect(adr_count).toBe(1); |
| Marc Kupietz | fd92b1d | 2024-03-13 10:51:29 +0100 | [diff] [blame] | 21 | var eot_count = (stdout.match(/\n# eot/g) || []).length; |
| 22 | expect(eot_count).toBe(1); |
| 23 | var eof_count = (stdout.match(/\n# eof/g) || []).length; |
| 24 | expect(eof_count).toBe(1); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 25 | var lines_count = (stdout.split("\n")).length; |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 26 | expect(lines_count).toBe(803); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 27 | done(); |
| 28 | }); |
| 29 | |
| 30 | test('Test full mode', (done) => { |
| 31 | const command = 'node src/index.js < test/data/ndy.conllu'; |
| 32 | const stdout = execSync(command).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 33 | expect(stdout).toContain('😂\t😂\t_\tEMOIMG'); |
| 34 | var emoimg_count = (stdout.match(/EMOIMG/g) || []).length; |
| 35 | expect(emoimg_count).toBe(191); |
| 36 | var ascimg_count = (stdout.match(/EMOASC/g) || []).length; |
| 37 | expect(ascimg_count).toBe(30); |
| 38 | var hst_count = (stdout.match(/\tHST\t/g) || []).length; |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 39 | expect(hst_count).toBe(12); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 40 | var url_count = (stdout.match(/\tURL\t/g) || []).length; |
| 41 | expect(url_count).toBe(4); |
| 42 | var adr_count = (stdout.match(/\tADR\t/g) || []).length; |
| 43 | expect(adr_count).toBe(1); |
| 44 | var lines_count = (stdout.split("\n")).length; |
| 45 | expect(lines_count).toBe(6202); |
| 46 | done(); |
| 47 | }); |
| 48 | |
| Marc Kupietz | 20f33d9 | 2026-04-12 14:27:57 +0200 | [diff] [blame] | 49 | test('Test version flag', (done) => { |
| 50 | const stdout = execSync('node src/index.js -V').toString().trim(); |
| 51 | |
| 52 | expect(stdout).toBe(packageVersion); |
| 53 | done(); |
| 54 | }); |
| 55 | |
| Marc Kupietz | 202a36d | 2026-04-12 14:58:13 +0200 | [diff] [blame^] | 56 | test('Test cmc-tagger alias', (done) => { |
| 57 | const stdout = execSync('npm exec --yes --package=. cmc-tagger -- -V').toString().trim(); |
| 58 | const versionLine = stdout.split('\n').pop().trim(); |
| 59 | |
| 60 | expect(versionLine).toBe(packageVersion); |
| 61 | done(); |
| 62 | }); |
| 63 | |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 64 | test('Regression test for hashtags: emit HST', (done) => { |
| 65 | const testInput = [ |
| 66 | '# foundry = base', |
| 67 | '# text_id = test-hashtag', |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 68 | '# text = #KorAP #3D #10', |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 69 | ['1', '#KorAP', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 70 | ['2', '#3D', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 71 | ['3', '#10', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 72 | '' |
| 73 | ].join('\n'); |
| 74 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 75 | |
| 76 | expect(stdout).toContain('#KorAP\t_\t_\tHST'); |
| Marc Kupietz | e8e40ec | 2026-04-10 15:15:59 +0200 | [diff] [blame] | 77 | expect(stdout).toContain('#3D\t_\t_\tHST'); |
| 78 | expect(stdout).not.toContain('#10\t_\t_\tHST'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 79 | |
| 80 | var hst_count = (stdout.match(/\tHST\t/g) || []).length; |
| 81 | expect(hst_count).toBe(2); |
| 82 | done(); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 83 | }); |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 84 | |
| Marc Kupietz | 3d52509 | 2026-04-11 20:44:32 +0200 | [diff] [blame] | 85 | test('Regression test for hashtags with Unicode letters: emit HST', (done) => { |
| 86 | const testInput = [ |
| 87 | '# foundry = base', |
| 88 | '# text_id = test-hashtag-unicode', |
| 89 | '# text = #okeichhörejetztauf #schön #10', |
| 90 | ['1', '#okeichhörejetztauf', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 91 | ['2', '#schön', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 92 | ['3', '#10', '_', '_', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 93 | '' |
| 94 | ].join('\n'); |
| 95 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 96 | |
| 97 | expect(stdout).toContain('#okeichhörejetztauf\t_\t_\tHST'); |
| 98 | expect(stdout).toContain('#schön\t_\t_\tHST'); |
| 99 | expect(stdout).not.toContain('#10\t_\t_\tHST'); |
| 100 | |
| 101 | var hst_count = (stdout.match(/\tHST\t/g) || []).length; |
| 102 | expect(hst_count).toBe(2); |
| 103 | done(); |
| 104 | }); |
| 105 | |
| Marc Kupietz | 804750d | 2026-04-10 14:44:13 +0200 | [diff] [blame] | 106 | test('Regression test for addresses: emit ADR regardless of existing POS values', (done) => { |
| 107 | const testInput = [ |
| 108 | '# foundry = base', |
| 109 | '# text_id = test-address', |
| 110 | '# text = @handle @markup', |
| 111 | ['1', '@handle', '_', 'PROPN', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 112 | ['2', '@markup', '_', 'NE', '_', '_', '_', '_', '_', '_'].join('\t'), |
| 113 | '' |
| 114 | ].join('\n'); |
| 115 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 116 | |
| 117 | expect(stdout).toContain('@handle\t_\tPROPN\tADR'); |
| 118 | expect(stdout).toContain('@markup\t_\tNE\tADR'); |
| 119 | |
| 120 | var adr_count = (stdout.match(/\tADR\t/g) || []).length; |
| 121 | expect(adr_count).toBe(2); |
| 122 | done(); |
| 123 | }); |
| 124 | |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 125 | test('Regression test for issue #113: emoji modifiers and ZWJ', (done) => { |
| 126 | // Test that compound emojis with modifiers and ZWJ are recognized as single EMOIMG tokens |
| 127 | const testInput = `# foundry = base |
| 128 | # text_id = test-113 |
| 129 | # text = ✊🏿 and 👨👨👦 |
| 130 | 1 ✊🏿 _ _ _ _ _ _ _ _ |
| 131 | 2 and _ CCONJ _ _ _ _ _ _ |
| 132 | 3 👨👨👦 _ _ _ _ _ _ _ _ |
| 133 | |
| 134 | `; |
| 135 | const { execSync } = require('child_process'); |
| 136 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 137 | |
| Marc Kupietz | a7934e0 | 2025-12-18 07:25:53 +0100 | [diff] [blame] | 138 | // Check that compound emojis are tagged as EMOIMG and lemma has base emoji |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 139 | expect(stdout).toContain('✊🏿\t✊\t_\tEMOIMG'); |
| 140 | expect(stdout).toContain('👨👨👦\t👨\t_\tEMOIMG'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 141 | |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 142 | // Count EMOIMG occurrences (should be 1 per emoji - only in XPOS column) |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 143 | var emoimg_count = (stdout.match(/EMOIMG/g) || []).length; |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 144 | expect(emoimg_count).toBe(2); // 2 emojis × 1 column = 2 |
| Marc Kupietz | b5d80b3 | 2025-12-11 15:48:09 +0100 | [diff] [blame] | 145 | done(); |
| 146 | }); |
| 147 | |
| Marc Kupietz | 7497fc4 | 2025-12-11 15:47:34 +0100 | [diff] [blame] | 148 | test('Regression test for issue #114: Wikipedia emoji templates', (done) => { |
| 149 | // Test that Wikipedia emoji templates are recognized as EMOWIKI tokens |
| 150 | const testInput = `# foundry = base |
| 151 | # text_id = test-114 |
| 152 | # text = [_EMOJI:{{S|;)}}_] and [_EMOJI:{{cool}}_] |
| 153 | 1 [_EMOJI:{{S|;)}}_] _ _ _ _ _ _ _ _ |
| 154 | 2 and _ CCONJ _ _ _ _ _ _ |
| 155 | 3 [_EMOJI:{{cool}}_] _ _ _ _ _ _ _ _ |
| 156 | |
| 157 | `; |
| 158 | const { execSync } = require('child_process'); |
| 159 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 160 | |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 161 | // Check that Wikipedia emoji templates are tagged as EMOWIKI in XPOS column only |
| 162 | expect(stdout).toContain('[_EMOJI:{{S|;)}}_]\t_\t_\tEMOWIKI'); |
| 163 | expect(stdout).toContain('[_EMOJI:{{cool}}_]\t_\t_\tEMOWIKI'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 164 | |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 165 | // Count EMOWIKI occurrences (should be 1 per template - only in XPOS column) |
| Marc Kupietz | 7497fc4 | 2025-12-11 15:47:34 +0100 | [diff] [blame] | 166 | var emowiki_count = (stdout.match(/EMOWIKI/g) || []).length; |
| Marc Kupietz | 76007d6 | 2025-12-11 17:13:05 +0100 | [diff] [blame] | 167 | expect(emowiki_count).toBe(2); // 2 templates × 1 column = 2 |
| Marc Kupietz | 7497fc4 | 2025-12-11 15:47:34 +0100 | [diff] [blame] | 168 | done(); |
| 169 | }); |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 170 | |
| 171 | test('Test emoji metadata in FEATS column', (done) => { |
| 172 | // Test that EMOIMG tokens have populated FEATS column |
| 173 | const testInput = `# foundry = base |
| 174 | # text_id = test-feats |
| 175 | # text = 😇 |
| 176 | 1 😇 _ _ _ _ _ _ _ _ |
| 177 | |
| 178 | `; |
| 179 | const { execSync } = require('child_process'); |
| 180 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 181 | |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 182 | // Check that 😇 has correct metadata |
| 183 | // g=smileys_and_emotion|s=face_smiling|q=fully_qualified|v=E1.0|n=smiling_face_with_halo |
| 184 | // Note: spaces in data are replaced by _ in our script |
| 185 | expect(stdout).toContain('g=smileys_&_emotion|s=face_smiling|q=fully_qualified|v=E1.0|n=smiling_face_with_halo'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 186 | |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 187 | // Also check for the base emoji lemma and tags |
| Marc Kupietz | 187bcdc | 2025-12-18 11:43:26 +0100 | [diff] [blame] | 188 | expect(stdout).toContain('😇\t😇\t_\tEMOIMG'); |
| Marc Kupietz | c287533 | 2026-04-10 14:21:06 +0200 | [diff] [blame] | 189 | |
| Marc Kupietz | 30634ff | 2025-12-18 11:39:03 +0100 | [diff] [blame] | 190 | done(); |
| 191 | }); |
| Marc Kupietz | 2de30e2 | 2026-04-11 12:49:52 +0200 | [diff] [blame] | 192 | |
| 193 | test('Test normalized emoji-name separators in FEATS', (done) => { |
| 194 | const testInput = `# foundry = base |
| 195 | # text_id = test-name-normalization |
| 196 | # text = 👍🏻 👨👨👦 |
| 197 | 1 👍🏻 _ _ _ _ _ _ _ _ |
| 198 | 2 👨👨👦 _ _ _ _ _ _ _ _ |
| 199 | |
| 200 | `; |
| 201 | const stdout = execSync('node src/index.js', { input: testInput }).toString(); |
| 202 | |
| 203 | expect(stdout).toContain('n=thumbs_up:light_skin_tone'); |
| 204 | expect(stdout).toContain('n=family:man,man,boy'); |
| 205 | expect(stdout).not.toContain('n=thumbs_up:_light_skin_tone'); |
| 206 | expect(stdout).not.toContain('n=family:_man,_man,_boy'); |
| 207 | |
| 208 | done(); |
| 209 | }); |
| Marc Kupietz | b43a518 | 2024-02-03 18:09:10 +0100 | [diff] [blame] | 210 | }); |