|
| 1 | +/** |
| 2 | + * Copyright 2026 Arm Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import path from 'path'; |
| 18 | +import { TestDataHandler } from '../__test__/test-data'; |
| 19 | +import { writeTextFile } from './fs-utils'; |
| 20 | +import { configWizardAnnotationChecker } from './config-wizard-annotation-checker'; |
| 21 | + |
| 22 | +describe('configWizardAnnotationChecker', () => { |
| 23 | + const testDataHandler = new TestDataHandler(); |
| 24 | + let testFolder: string; |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + testFolder = testDataHandler.tmpDir; |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(() => { |
| 31 | + testDataHandler.rmTmpDir(); |
| 32 | + }); |
| 33 | + |
| 34 | + afterAll(() => { |
| 35 | + testDataHandler.dispose(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('returns true when start marker is within first 100 lines', async () => { |
| 39 | + const filePath = path.join(testFolder, 'within-100.h'); |
| 40 | + const lines = Array.from({ length: 99 }, () => 'int x = 0;'); |
| 41 | + lines.push('// <<< Use Configuration Wizard in Context Menu >>>'); |
| 42 | + writeTextFile(filePath, lines.join('\n')); |
| 43 | + |
| 44 | + await expect(configWizardAnnotationChecker.hasAnnotations(filePath)).resolves.toBe(true); |
| 45 | + }); |
| 46 | + |
| 47 | + it('returns false when start marker appears after first 100 lines', async () => { |
| 48 | + const filePath = path.join(testFolder, 'after-100.h'); |
| 49 | + const lines = Array.from({ length: 100 }, () => 'int y = 1;'); |
| 50 | + lines.push('// <<< Use Configuration Wizard in Context Menu >>>'); |
| 51 | + writeTextFile(filePath, lines.join('\n')); |
| 52 | + |
| 53 | + await expect(configWizardAnnotationChecker.hasAnnotations(filePath)).resolves.toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it('returns true when start marker is within first 100 lines and end marker is after 100 lines', async () => { |
| 57 | + const filePath = path.join(testFolder, 'end-after-100.h'); |
| 58 | + const lines = Array.from({ length: 39 }, () => 'int cfg = 3;'); |
| 59 | + lines.push('// <<< Use Configuration Wizard in Context Menu >>>'); |
| 60 | + lines.push(...Array.from({ length: 90 }, () => 'int body = 4;')); |
| 61 | + lines.push('// <<< end of configuration section >>>'); |
| 62 | + writeTextFile(filePath, lines.join('\n')); |
| 63 | + |
| 64 | + await expect(configWizardAnnotationChecker.hasAnnotations(filePath)).resolves.toBe(true); |
| 65 | + }); |
| 66 | + |
| 67 | + it('returns false when only end marker is present', async () => { |
| 68 | + const filePath = path.join(testFolder, 'end-only.h'); |
| 69 | + writeTextFile(filePath, '// <<< end of configuration section >>>\nint z = 2;\n'); |
| 70 | + |
| 71 | + await expect(configWizardAnnotationChecker.hasAnnotations(filePath)).resolves.toBe(false); |
| 72 | + }); |
| 73 | + |
| 74 | + it('returns true for decorated marker lines used in template headers', async () => { |
| 75 | + const filePath = path.join(testFolder, 'decorated-marker.h'); |
| 76 | + const lines = [ |
| 77 | + '/* header */', |
| 78 | + '//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------', |
| 79 | + 'int cfg = 0;' |
| 80 | + ]; |
| 81 | + writeTextFile(filePath, lines.join('\n')); |
| 82 | + |
| 83 | + await expect(configWizardAnnotationChecker.hasAnnotations(filePath)).resolves.toBe(true); |
| 84 | + }); |
| 85 | +}); |
0 commit comments