// Automatic tagging rules (lib/autotag.js). const test = require('node:test'); const assert = require('node:assert/strict'); const { tokenize, matchTags } = require('../lib/autotag'); test('names split into words at punctuation, camelCase and numbers', () => { assert.deepEqual(tokenize('PETGWallHook_v2.stl'), ['petg', 'wall', 'hook', 'v', '2', 'stl']); assert.deepEqual(tokenize('Gridfinity-6x4 baseplate'), ['gridfinity', '6', 'x', '4', 'baseplate']); }); test('rules match whole words only, plurals included', () => { assert.deepEqual(matchTags(['Wall Hooks.stl']), ['hook']); assert.deepEqual(matchTags(['facebook_logo.stl', 'blocked-path.3mf', 'planter.stl', 'absolute.obj']), []); assert.deepEqual(matchTags(['gears_and_threads.3mf']).sort(), ['gear', 'threaded']); }); test('phrases match across separators but not across different names', () => { assert.deepEqual(matchTags(['Print-In-Place_Dragon.3mf']), ['print-in-place']); assert.deepEqual(matchTags(['Dragon Print', 'in place']), []); assert.deepEqual(matchTags(['Spiral Vase Mode lamp']), ['vase mode']); }); test('materials and techniques are picked up', () => { assert.deepEqual(matchTags(['benchy_PLA.3mf', 'TPU tyre']).sort(), ['pla', 'tpu']); assert.deepEqual(matchTags(['MultiColour Keyring']).sort(), ['keychain', 'multicolor']); }); test('your own rules add tags the same strict way', () => { const rules = [{ phrase: 'benchy', tag: 'Calibration' }, { phrase: 'cable tie', tag: 'cable management' }]; assert.deepEqual(matchTags(['3DBenchy.stl'], rules), ['calibration']); assert.deepEqual(matchTags(['cable_ties_holder.stl'], rules).sort(), ['cable management', 'holder']); assert.deepEqual(matchTags(['benchymark.stl'], rules), []); });