From 56d4fc74913f5d6b92e1d337d83eae86195d7c74 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Mon, 23 Dec 2024 22:18:18 +0500 Subject: [PATCH] added tests and fixing code style Signed-off-by: Tokesh --- .../src/prepare-for-vale/KeepDescriptions.ts | 10 ++++--- .../tests/prepare-for-vale/fixtures/spec.txt | 6 ++--- .../tests/prepare-for-vale/fixtures/spec.yaml | 6 ++--- .../prepare-for-vale/prepare-for-vale.test.ts | 26 ------------------- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 82c692252..4982ee6b3 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -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") diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index f9ada2c25..3f29f1c05 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.txt +++ b/tools/tests/prepare-for-vale/fixtures/spec.txt @@ -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 diff --git a/tools/tests/prepare-for-vale/fixtures/spec.yaml b/tools/tests/prepare-for-vale/fixtures/spec.yaml index 6ca62c5de..f4688d63f 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.yaml +++ b/tools/tests/prepare-for-vale/fixtures/spec.yaml @@ -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 diff --git a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts index 215a11f98..c46fc7340 100644 --- a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts +++ b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts @@ -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) -})