yaml-ast-parser
Advanced tools
Comparing version 0.0.36 to 0.0.37
@@ -667,3 +667,5 @@ "use strict"; | ||
else { | ||
keyNode.parent = _result; | ||
if (keyNode) { | ||
keyNode.parent = _result; | ||
} | ||
_result.items.push(keyNode); | ||
@@ -841,4 +843,6 @@ } | ||
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true); | ||
state.result.parent = _result; | ||
_result.items.push(state.result); | ||
if (state.result) { | ||
state.result.parent = _result; | ||
_result.items.push(state.result); | ||
} | ||
skipSeparationSpace(state, true, -1); | ||
@@ -845,0 +849,0 @@ ch = state.input.charCodeAt(state.position); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chai = require("chai"); | ||
var assert = chai.assert; | ||
var index_1 = require("../src/index"); | ||
var util = require("./testUtil"); | ||
suite('YAML Syntax', function () { | ||
@@ -35,54 +33,4 @@ suite('Warnings for tab symbols', function () { | ||
function testErrors(input, expectedErrors) { | ||
var errorsMap = {}; | ||
for (var _i = 0, expectedErrors_1 = expectedErrors; _i < expectedErrors_1.length; _i++) { | ||
var e = expectedErrors_1[_i]; | ||
var key = e.message + " at line " + e.line + " column " + e.column; | ||
if (e.isWarning) { | ||
key += " (warning)"; | ||
} | ||
errorsMap[key] = true; | ||
} | ||
var ast = safeLoad(input); | ||
if (!ast) { | ||
assert.fail("The parser has failed to load YAML AST"); | ||
} | ||
var actualErrors = ast.errors; | ||
if (actualErrors.length == 0 && expectedErrors.length == 0) { | ||
assert(true); | ||
return; | ||
} | ||
var unexpectedErrorsMap = {}; | ||
for (var _a = 0, actualErrors_1 = actualErrors; _a < actualErrors_1.length; _a++) { | ||
var e = actualErrors_1[_a]; | ||
var key = e.reason + " at line " + e.mark.line + " column " + e.mark.column; | ||
if (e.isWarning) { | ||
key += " (warning)"; | ||
} | ||
if (!errorsMap[key]) { | ||
unexpectedErrorsMap[key] = e; | ||
} | ||
else { | ||
delete errorsMap[key]; | ||
} | ||
} | ||
var missingErrors = Object.keys(errorsMap); | ||
var unexpectedErrorKeys = Object.keys(unexpectedErrorsMap); | ||
if (missingErrors.length == 0 && unexpectedErrorKeys.length == 0) { | ||
assert(true); | ||
return; | ||
} | ||
var messageComponents = []; | ||
if (unexpectedErrorKeys.length > 0) { | ||
messageComponents.push("Unexpected errors:\n" + unexpectedErrorKeys.join('\n')); | ||
} | ||
if (missingErrors.length > 0) { | ||
messageComponents.push("Missing errors:\n" + missingErrors.join('\n')); | ||
} | ||
var testFailureMessage = "\n" + messageComponents.join("\n\n"); | ||
assert(false, testFailureMessage); | ||
util.testErrors(input, expectedErrors); | ||
} | ||
; | ||
function safeLoad(input) { | ||
return index_1.safeLoad(input, {}); | ||
} | ||
//# sourceMappingURL=yamlSyntax.test.js.map |
{ | ||
"name": "yaml-ast-parser", | ||
"version": "0.0.36", | ||
"version": "0.0.37", | ||
"main": "dist/src/index.js", | ||
@@ -34,3 +34,3 @@ "scripts": { | ||
"chai": "^4.0.2", | ||
"dev-env-installer": "0.0.5", | ||
"dev-env-installer": "^0.0.14", | ||
"mocha": "^3.4.2", | ||
@@ -37,0 +37,0 @@ "rimraf": "*", |
@@ -890,3 +890,5 @@ import ast=require("./yamlAST") | ||
} else { | ||
keyNode.parent=_result; | ||
if(keyNode) { | ||
keyNode.parent = _result; | ||
} | ||
(<ast.YAMLSequence>_result).items.push(keyNode); | ||
@@ -1112,4 +1114,6 @@ } | ||
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true); | ||
state.result.parent=_result; | ||
_result.items.push(state.result); | ||
if(state.result) { | ||
state.result.parent = _result; | ||
_result.items.push(state.result); | ||
} | ||
skipSeparationSpace(state, true, -1); | ||
@@ -1116,0 +1120,0 @@ |
@@ -1,8 +0,3 @@ | ||
import YAMLException = require("../src/exception"); | ||
import util = require("./testUtil"); | ||
import * as chai from 'chai' | ||
const assert = chai.assert | ||
import {safeLoad as loadYaml} from '../src/index' | ||
suite('YAML Syntax', () => { | ||
@@ -46,63 +41,4 @@ | ||
interface TestError{ | ||
message: string | ||
line: number | ||
column: number | ||
isWarning:boolean | ||
function testErrors(input:string,expectedErrors: util.TestError[]) { | ||
util.testErrors(input, expectedErrors); | ||
} | ||
function testErrors(input:string,expectedErrors: TestError[]) { | ||
let errorsMap: {[key:string]:boolean} = {}; | ||
for(let e of expectedErrors){ | ||
let key = `${e.message} at line ${e.line} column ${e.column}`; | ||
if(e.isWarning){ | ||
key += " (warning)"; | ||
} | ||
errorsMap[key] = true; | ||
} | ||
let ast = safeLoad(input); | ||
if(!ast){ | ||
assert.fail("The parser has failed to load YAML AST"); | ||
} | ||
let actualErrors = ast.errors; | ||
if(actualErrors.length==0 && expectedErrors.length==0){ | ||
assert(true); | ||
return; | ||
} | ||
let unexpectedErrorsMap: {[key:string]:YAMLException} = {}; | ||
for(let e of actualErrors){ | ||
let key = `${e.reason} at line ${e.mark.line} column ${e.mark.column}`; | ||
if(e.isWarning){ | ||
key += " (warning)"; | ||
} | ||
if(!errorsMap[key]){ | ||
unexpectedErrorsMap[key] = e; | ||
} | ||
else{ | ||
delete errorsMap[key]; | ||
} | ||
} | ||
let missingErrors = Object.keys(errorsMap); | ||
let unexpectedErrorKeys = Object.keys(unexpectedErrorsMap); | ||
if(missingErrors.length==0 && unexpectedErrorKeys.length==0){ | ||
assert(true); | ||
return; | ||
} | ||
let messageComponents:string[] = []; | ||
if(unexpectedErrorKeys.length>0) { | ||
messageComponents.push(`Unexpected errors:\n${unexpectedErrorKeys.join('\n')}`); | ||
} | ||
if(missingErrors.length>0){ | ||
messageComponents.push(`Missing errors:\n${missingErrors.join('\n')}`); | ||
} | ||
let testFailureMessage = `\n${messageComponents.join("\n\n")}`; | ||
assert(false,testFailureMessage); | ||
}; | ||
function safeLoad(input) { | ||
return loadYaml(input, {}) | ||
} |
@@ -17,5 +17,4 @@ { | ||
"exclude": [ | ||
"node_modules", | ||
"typings" | ||
"node_modules" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
417089
160
8206