This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
/node_modules | ||
/typings | ||
|
||
/src/**/*.js | ||
/src/**/*.js.map | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
"test/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"typings" | ||
"node_modules" | ||
] | ||
} |