Skip to content

Commit

Permalink
fix(parser-adapter-yaml-1-2): fix canonical formatting of quoted scal…
Browse files Browse the repository at this point in the history
…ars (#3792)

Refs #3788
  • Loading branch information
glowcloud committed Feb 6, 2024
1 parent 8c3c20d commit 3d9ff9f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/apidom-ast/src/yaml/schemas/canonical-format.ts
Expand Up @@ -128,11 +128,11 @@ export const formatFlowPlain = pipe(
export const formatFlowSingleQuoted = pipe(
normalizeLineBreaks,
trim,
removeQuotes("'"),
collapseLineBreakToSpace,
split('\n'),
map(trimStart),
join('\n'),
removeQuotes("'"),
);

/**
Expand All @@ -142,13 +142,13 @@ export const formatFlowSingleQuoted = pipe(
export const formatFlowDoubleQuoted = pipe(
normalizeLineBreaks,
trim,
removeQuotes('"'),
preventLineBreakCollapseToSpace,
collapseLineBreakToSpace,
unraw,
split('\n'),
map(trimStart),
join('\n'),
removeQuotes('"'),
);

/**
Expand Down
Expand Up @@ -531,7 +531,7 @@ exports[`refractor plugins normalize-operation-ids given Operation Object with o
},
"originalOperationId": {
"element": "string",
"content": ""
"content": " "
}
},
"content": [
Expand Down Expand Up @@ -568,7 +568,7 @@ exports[`refractor plugins normalize-operation-ids given Operation Object with o
},
"value": {
"element": "string",
"content": ""
"content": " "
}
}
}
Expand Down
29 changes: 28 additions & 1 deletion packages/apidom-parser-adapter-yaml-1-2/test/adapter-browser.ts
@@ -1,7 +1,13 @@
import fs from 'node:fs';
import path from 'node:path';
import { assert, expect } from 'chai';
import { toValue, isObjectElement, isParseResultElement, sexprs } from '@swagger-api/apidom-core';
import {
toValue,
isObjectElement,
isParseResultElement,
sexprs,
isStringElement,
} from '@swagger-api/apidom-core';

import * as adapter from '../src/adapter-browser';

Expand Down Expand Up @@ -126,4 +132,25 @@ describe('adapter-browser', function () {
assert.strictEqual(toValue(parseResult.errors.get(0)), '(Error YAML syntax error)');
});
});

context('given an alias', function () {
specify('should analyze alias as string', async function () {
const result = await adapter.parse('*alias');
assert.isTrue(isStringElement(result.result));
});
});

context('given single-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse("' '");
assert.strictEqual(result.toValue()[0], ' ');
});
});

context('given double-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse('" "');
assert.strictEqual(result.toValue()[0], ' ');
});
});
});
Expand Up @@ -2,7 +2,13 @@ import fs from 'node:fs';
import path from 'node:path';
import { assert, expect } from 'chai';
import { YamlTagError } from '@swagger-api/apidom-ast';
import { toValue, isObjectElement, isParseResultElement, sexprs } from '@swagger-api/apidom-core';
import {
toValue,
isObjectElement,
isParseResultElement,
sexprs,
isStringElement,
} from '@swagger-api/apidom-core';

import * as adapter from '../../src/adapter-node';

Expand Down Expand Up @@ -155,4 +161,25 @@ describe('adapter-node', function () {
}
});
});

context('given an alias', function () {
specify('should analyze alias as string', async function () {
const result = await adapter.parse('*alias');
assert.isTrue(isStringElement(result.result));
});
});

context('given single-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse("' '");
assert.strictEqual(result.toValue()[0], ' ');
});
});

context('given double-quote scalar containing only space characters', function () {
specify('should parse all space characters', async function () {
const result = await adapter.parse('" "');
assert.strictEqual(result.toValue()[0], ' ');
});
});
});

This file was deleted.

0 comments on commit 3d9ff9f

Please sign in to comment.