|
| 1 | +import * as assert from 'assert'; |
| 2 | +import { |
| 3 | + extractProfilePath, |
| 4 | + PROFILE_TAG_END, |
| 5 | + PROFILE_TAG_START, |
| 6 | +} from '../../../../../features/terminal/shells/common/shellUtils'; |
| 7 | + |
| 8 | +suite('Shell Utils', () => { |
| 9 | + suite('extractProfilePath', () => { |
| 10 | + test('should return undefined when content is empty', () => { |
| 11 | + const content = ''; |
| 12 | + const result = extractProfilePath(content); |
| 13 | + assert.strictEqual(result, undefined); |
| 14 | + }); |
| 15 | + |
| 16 | + test('should return undefined when content does not have tags', () => { |
| 17 | + const content = 'sample content without tags'; |
| 18 | + const result = extractProfilePath(content); |
| 19 | + assert.strictEqual(result, undefined); |
| 20 | + }); |
| 21 | + |
| 22 | + test('should return undefined when only start tag exists', () => { |
| 23 | + const content = `content\n${PROFILE_TAG_START}\nsome path`; |
| 24 | + const result = extractProfilePath(content); |
| 25 | + assert.strictEqual(result, undefined); |
| 26 | + }); |
| 27 | + |
| 28 | + test('should return undefined when only end tag exists', () => { |
| 29 | + const content = `content\nsome path\n${PROFILE_TAG_END}`; |
| 30 | + const result = extractProfilePath(content); |
| 31 | + assert.strictEqual(result, undefined); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should return undefined when tags are in wrong order', () => { |
| 35 | + const content = `content\n${PROFILE_TAG_END}\nsome path\n${PROFILE_TAG_START}`; |
| 36 | + const result = extractProfilePath(content); |
| 37 | + assert.strictEqual(result, undefined); |
| 38 | + }); |
| 39 | + test('should return undefined when content between tags is empty', () => { |
| 40 | + const content = `content\n${PROFILE_TAG_START}\n\n${PROFILE_TAG_END}\nmore content`; |
| 41 | + const result = extractProfilePath(content); |
| 42 | + assert.strictEqual(result, undefined); |
| 43 | + }); |
| 44 | + |
| 45 | + test('should extract path when found between tags', () => { |
| 46 | + const expectedPath = '/usr/local/bin/python'; |
| 47 | + const content = `content\n${PROFILE_TAG_START}\n${expectedPath}\n${PROFILE_TAG_END}\nmore content`; |
| 48 | + const result = extractProfilePath(content); |
| 49 | + assert.strictEqual(result, expectedPath); |
| 50 | + }); |
| 51 | + |
| 52 | + test('should trim whitespace from extracted path', () => { |
| 53 | + const expectedPath = '/usr/local/bin/python'; |
| 54 | + const content = `content\n${PROFILE_TAG_START}\n ${expectedPath} \n${PROFILE_TAG_END}\nmore content`; |
| 55 | + const result = extractProfilePath(content); |
| 56 | + assert.strictEqual(result, expectedPath); |
| 57 | + }); |
| 58 | + |
| 59 | + test('should handle Windows-style line endings', () => { |
| 60 | + const expectedPath = 'C:\\Python\\python.exe'; |
| 61 | + const content = `content\r\n${PROFILE_TAG_START}\r\n${expectedPath}\r\n${PROFILE_TAG_END}\r\nmore content`; |
| 62 | + const result = extractProfilePath(content); |
| 63 | + assert.strictEqual(result, expectedPath); |
| 64 | + }); |
| 65 | + |
| 66 | + test('should extract path with special characters', () => { |
| 67 | + const expectedPath = '/path with spaces/and (parentheses)/python'; |
| 68 | + const content = `${PROFILE_TAG_START}\n${expectedPath}\n${PROFILE_TAG_END}`; |
| 69 | + const result = extractProfilePath(content); |
| 70 | + assert.strictEqual(result, expectedPath); |
| 71 | + }); |
| 72 | + |
| 73 | + test('should extract multiline content correctly', () => { |
| 74 | + const expectedPath = 'line1\nline2\nline3'; |
| 75 | + const content = `${PROFILE_TAG_START}\n${expectedPath}\n${PROFILE_TAG_END}`; |
| 76 | + const result = extractProfilePath(content); |
| 77 | + assert.strictEqual(result, expectedPath); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments