Skip to content

Commit

Permalink
added separate method and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tokesh <[email protected]>
  • Loading branch information
Tokesh committed Dec 23, 2024
1 parent cf93ff2 commit 365c94b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/src/prepare-for-vale/KeepDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class KeepDescriptions {
} else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) {
inside_text = false
} else if (inside_text) {
const cleaned_line = line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
const cleaned_line = this.remove_links(line)
fs.writeSync(writer, this.prune_vars(cleaned_line))
}
if (line.length > 0) {
Expand All @@ -63,4 +63,8 @@ export default class KeepDescriptions {
return Array(match.length + 1).join(char)
})
}

remove_links(line: string): string {
return line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
}
}
28 changes: 28 additions & 0 deletions tools/tests/prepare-for-vale/prepare-for-vale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ const spec = (args: string[]): any => {
test('--help', () => {
expect(spec(['--help']).stdout).toContain('Usage: prepare-for-vale [options]')
})

test('process single link', () => {
const input = ['description: This is a [link](https://opensearch.org).']
const expectedOutput = 'description: This is a link.\n'

Check failure on line 26 in tools/tests/prepare-for-vale/prepare-for-vale.test.ts

View workflow job for this annotation

GitHub Actions / lint

Variable name `expectedOutput` must match one of the following formats: snake_case, UPPER_CASE
const result = spec(input).stdout
expect(result).toBe(expectedOutput)
})

test('process two links', () => {
const input = ['description: Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).']
const expectedOutput = 'description: Here is link one and link two.\n'

Check failure on line 33 in tools/tests/prepare-for-vale/prepare-for-vale.test.ts

View workflow job for this annotation

GitHub Actions / lint

Variable name `expectedOutput` must match one of the following formats: snake_case, UPPER_CASE
const result = spec(input).stdout
expect(result).toBe(expectedOutput)
})

test('process plain text without links', () => {
const input = ['description: This is plain text without any links.']
const expectedOutput = 'description: This is plain text without any links.\n'

Check failure on line 40 in tools/tests/prepare-for-vale/prepare-for-vale.test.ts

View workflow job for this annotation

GitHub Actions / lint

Variable name `expectedOutput` must match one of the following formats: snake_case, UPPER_CASE
const result = spec(input).stdout
expect(result).toBe(expectedOutput)
})

test('process complex link structures', () => {
const input = ['description: Check this [link with a title](https://opensearch.org "title").']
const expectedOutput = 'description: Check this link with a title.\n'

Check failure on line 47 in tools/tests/prepare-for-vale/prepare-for-vale.test.ts

View workflow job for this annotation

GitHub Actions / lint

Variable name `expectedOutput` must match one of the following formats: snake_case, UPPER_CASE
const result = spec(input).stdout
expect(result).toBe(expectedOutput)
})

0 comments on commit 365c94b

Please sign in to comment.