Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Dec 12, 2022
1 parent 75a373d commit 5d12968
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/internal/test_runner/yaml_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const {
const AssertionError = require('internal/assert/assertion_error');
const {
ArrayPrototypeJoin,
ArrayPrototypePush,
Error,
Number,
NumberIsNaN,
ObjectCreate,
RegExpPrototypeExec,
StringPrototypeEndsWith,
StringPrototypeRepeat,
Expand All @@ -29,9 +31,7 @@ function reConstructError(parsedYaml) {
'actual' in parsedYaml || 'expected' in parsedYaml || 'operator' in parsedYaml;
const isTestFailure = parsedYaml.code === 'ERR_TEST_FAILURE' || 'failureType' in parsedYaml;
const stack = parsedYaml.stack ? kStackDelimiter + ArrayPrototypeJoin(parsedYaml.stack, `\n${kStackDelimiter}`) : '';

let cause;
let error;
let error, cause;

if (isAssertionError) {
cause = new AssertionError({
Expand Down Expand Up @@ -63,7 +63,7 @@ function reConstructError(parsedYaml) {
return parsedYaml;
}

function getYamlValue(value, key) {
function getYamlValue(value) {
if (StringPrototypeStartsWith(value, "'") && StringPrototypeEndsWith(value, "'")) {
return StringPrototypeSlice(value, 1, -1);
}
Expand All @@ -73,7 +73,7 @@ function getYamlValue(value, key) {
if (value === 'false') {
return false;
}
if (value && !NumberIsNaN(value)) {
if (value && !NumberIsNaN(Number(value))) {
return Number(value);
}
return value;
Expand All @@ -83,17 +83,18 @@ function getYamlValue(value, key) {
// the yaml is a subset of the full yaml spec, so we there might be some
// YAML features that won't be parsed here
function YAMLToJs(lines) {
const result = {};
const result = ObjectCreate(null);
let isInYamlBlock = false;
for (const line of lines) {
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (isInYamlBlock && !StringPrototypeStartsWith(line, StringPrototypeRepeat(' ', isInYamlBlock.indent))) {
result[isInYamlBlock.key] = isInYamlBlock.key === 'stack' ?
result[isInYamlBlock.key] : ArrayPrototypeJoin(result[isInYamlBlock.key], '\n');
isInYamlBlock = false;
}
if (isInYamlBlock) {
const blockLine = StringPrototypeSubstring(line, isInYamlBlock.indent);
result[isInYamlBlock.key].push(blockLine);
ArrayPrototypePush(result[isInYamlBlock.key], blockLine);
continue;
}
const match = RegExpPrototypeExec(kYamlKeyRegex, line);
Expand All @@ -103,7 +104,7 @@ function YAMLToJs(lines) {
isInYamlBlock = { key, indent: (leadingSpaces?.length ?? 0) + 2 };
result[key] = [];
} else {
result[key] = getYamlValue(value, key);
result[key] = getYamlValue(value);
}
}
}
Expand Down

0 comments on commit 5d12968

Please sign in to comment.