Skip to content

Commit

Permalink
added tests and fixing code style
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 9263f3e commit 56d4fc7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
10 changes: 7 additions & 3 deletions tools/src/prepare-for-vale/KeepDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export default class KeepDescriptions {
if (line.match(/^[\s]+((description|x-deprecation-message): \|)/)) {
inside_text = true
} else if (line.match(/^[\s]+((description|x-deprecation-message):)[\s]+/)) {
fs.writeSync(writer, this.prune_vars(this.prune(line, /(description|x-deprecation-message):/, ' ')))
var cleaned_line = this.prune(line, /(description|x-deprecation-message):/, ' ')
cleaned_line = this.remove_links(line)
cleaned_line = this.prune_vars(cleaned_line)
fs.writeSync(writer, cleaned_line)
} else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) {
inside_text = false
} else if (inside_text) {
const cleaned_line = this.remove_links(line)
fs.writeSync(writer, this.prune_vars(cleaned_line))
let cleaned_line = this.remove_links(line)
cleaned_line = this.prune_vars(cleaned_line)
fs.writeSync(writer, cleaned_line)
}
if (line.length > 0) {
fs.writeSync(writer, "\n")
Expand Down
6 changes: 3 additions & 3 deletions tools/tests/prepare-for-vale/fixtures/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@



For a successful response, this value is always true. On failure, an exception is returned instead.
For a successful response, this value is always true. On failure, an exception is returned instead Supported units.



The item level REST category class codes during indexing.
The item level REST category class codes during indexing link with a title.



Line one
Here is link one and link two.
Line two


Expand Down
6 changes: 3 additions & 3 deletions tools/tests/prepare-for-vale/fixtures/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ components:
type: object
properties:
acknowledged:
description: For a successful response, this value is always true. On failure, an exception is returned instead.
description: For a successful response, this value is always true. On failure, an exception is returned instead [Supported units](https://opensearch.org/docs/latest/api-reference/units/).
type: boolean
ObjectWithMultilineDescriptionOneLine:
description: |-
The item level REST category class codes during indexing.
The item level REST category class codes during indexing [link with a title](https://opensearch.org "title").
type: object
ObjectWithMultilineDescriptionTwoLines:
description: |-
Line one
Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).
Line two
ObjectWithAColonInDescription:
type: object
Expand Down
26 changes: 0 additions & 26 deletions tools/tests/prepare-for-vale/prepare-for-vale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,3 @@ 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).']
expect(spec(input).stdout).toContain('description: This is a link.\n')
})

test('process two links', () => {
const input = ['description: Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).']
const expected_output = 'description: Here is link one and link two.\n'
const result = spec(input).stdout
expect(result).toBe(expected_output)
})

test('process plain text without links', () => {
const input = ['description: This is plain text without any links.']
const expected_output = 'description: This is plain text without any links.\n'
const result = spec(input).stdout
expect(result).toBe(expected_output)
})

test('process complex link structures', () => {
const input = ['description: Check this [link with a title](https://opensearch.org "title").']
const expected_output = 'description: Check this link with a title.\n'
const result = spec(input).stdout
expect(result).toBe(expected_output)
})

0 comments on commit 56d4fc7

Please sign in to comment.