Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddenisenko committed Oct 18, 2017
2 parents 7423f62 + 1b9ecb8 commit d67dc14
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 75 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/node_modules
/typings

/src/**/*.js
/src/**/*.js.map
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yaml-ast-parser",
"version": "0.0.36",
"version": "0.0.37",
"main": "dist/src/index.js",
"scripts": {
"build": "rimraf dist && tsc",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@types/mocha": "^2.2.41",
"@types/node": "4.2.20",
"chai": "^4.0.2",
"dev-env-installer": "0.0.5",
"dev-env-installer": "^0.0.14",
"mocha": "^3.4.2",
"rimraf": "*",
"typescript": "2.5.2"
Expand Down
10 changes: 7 additions & 3 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,9 @@ function readFlowCollection(state:State, nodeIndent) {
mp.parent=_result;
(<ast.YAMLSequence>_result).items.push(mp);
} else {
keyNode.parent=_result;
if(keyNode) {
keyNode.parent = _result;
}
(<ast.YAMLSequence>_result).items.push(keyNode);
}
_result.endPosition=state.position+1/*need to add one more char*/;
Expand Down Expand Up @@ -1108,8 +1110,10 @@ function readBlockSequence(state:State, nodeIndent) {

_line = state.line;
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);

ch = state.input.charCodeAt(state.position);
Expand Down
71 changes: 71 additions & 0 deletions test/stability.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import util = require("./testUtil");

suite('YAML Syntax', () => {

suite('Warnings for tab symbols', () => {

test('test 001', function () {
testErrors(
"schemas:\n" +
" - !i",
[
{
line: 1,
column: 4,
message: "unknown tag <!i>",
isWarning: false
}
]
);
});

test('test 002', function () {
testErrors(
"schemas:\n" +
" - !in",
[
{
line: 1,
column: 4,
message: "unknown tag <!in>",
isWarning: false
}
]
);
});

test('test 003', function () {
testErrors(
"schemas:\n" +
" - !inc",
[
{
line: 1,
column: 4,
message: "unknown tag <!inc>",
isWarning: false
}
]
);
});

test('test 004', function () {
testErrors(
"schemas:\n" +
" - !incl",
[
{
line: 1,
column: 4,
message: "unknown tag <!incl>",
isWarning: false
}
]
);
});
});
});

function testErrors(input:string,expectedErrors: util.TestError[]) {
util.testErrors(input, expectedErrors);
}
67 changes: 67 additions & 0 deletions test/testUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import YAMLException = require("../src/exception");

import * as chai from 'chai';
const assert = chai.assert;
import {safeLoad as loadYaml} from '../src/index';
import ast=require("../src/yamlAST");

export interface TestError{
message: string
line: number
column: number
isWarning:boolean
}

export 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);
};

export function safeLoad(input):ast.YAMLNode {
return loadYaml(input, {})
}
70 changes: 3 additions & 67 deletions test/yamlSyntax.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import YAMLException = require("../src/exception");

import * as chai from 'chai'
const assert = chai.assert

import {safeLoad as loadYaml} from '../src/index'
import util = require("./testUtil");

suite('YAML Syntax', () => {

Expand Down Expand Up @@ -43,65 +38,6 @@ suite('YAML Syntax', () => {
});
});


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, {})
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"test/**/*.ts"
],
"exclude": [
"node_modules",
"typings"
"node_modules"
]
}

0 comments on commit d67dc14

Please sign in to comment.