|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | + |
| 4 | +import { |
| 5 | + isBuildableSection, |
| 6 | + normalizeSectionName, |
| 7 | + generateSectionFolderName, |
| 8 | +} from '../section.mjs'; |
| 9 | + |
| 10 | +describe('isBuildableSection', () => { |
| 11 | + it('should return true when both .cc and .js files are present', () => { |
| 12 | + const codeBlocks = [ |
| 13 | + { name: 'addon.cc', content: 'C++ code' }, |
| 14 | + { name: 'test.js', content: 'JS code' }, |
| 15 | + ]; |
| 16 | + |
| 17 | + assert.equal(isBuildableSection(codeBlocks), true); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should return false when only .cc file is present', () => { |
| 21 | + const codeBlocks = [{ name: 'addon.cc', content: 'C++ code' }]; |
| 22 | + |
| 23 | + assert.equal(isBuildableSection(codeBlocks), false); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should return false when only .js file is present', () => { |
| 27 | + const codeBlocks = [{ name: 'test.js', content: 'JS code' }]; |
| 28 | + |
| 29 | + assert.equal(isBuildableSection(codeBlocks), false); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should return false for empty array', () => { |
| 33 | + assert.equal(isBuildableSection([]), false); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('normalizeSectionName', () => { |
| 38 | + it('should convert to lowercase and replace spaces with underscores', () => { |
| 39 | + assert.equal(normalizeSectionName('Hello World'), 'hello_world'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should remove non-word characters', () => { |
| 43 | + assert.equal(normalizeSectionName('Test-Section!@#'), 'testsection'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should handle empty string', () => { |
| 47 | + assert.equal(normalizeSectionName(''), ''); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should handle mixed cases and special characters', () => { |
| 51 | + assert.equal( |
| 52 | + normalizeSectionName('My Test & Example #1'), |
| 53 | + 'my_test__example_1' |
| 54 | + ); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe('generateSectionFolderName', () => { |
| 59 | + it('should generate folder name with padded index', () => { |
| 60 | + assert.equal(generateSectionFolderName('hello_world', 0), '01_hello_world'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should pad single digit indices', () => { |
| 64 | + assert.equal(generateSectionFolderName('test', 5), '06_test'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should not pad double digit indices', () => { |
| 68 | + assert.equal(generateSectionFolderName('example', 15), '16_example'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should handle empty section name', () => { |
| 72 | + assert.equal(generateSectionFolderName('', 0), '01_'); |
| 73 | + }); |
| 74 | +}); |
0 commit comments