1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(std/encoding/yaml): support document separator in parseAll (#3535)

This commit is contained in:
Yoshiya Hinosawa 2019-12-21 17:57:51 +09:00 committed by Ry Dahl
parent b7b0668c78
commit 80da2ac8de
4 changed files with 44 additions and 17 deletions

View file

@ -192,7 +192,6 @@ name: Eve
`);
console.log(data);
// => [ { id: 1, name: "Alice" }, { id: 2, name: "Bob" }, { id: 3, name: "Eve" } ]
// TODO(kt3k): This doesn't work now
```
### API

View file

@ -577,7 +577,7 @@ function readPlainScalar(
captureSegment(state, captureStart, captureEnd, false);
if (!common.isNullOrUndefined(state.result)) {
if (state.result) {
return true;
}

View file

@ -3,14 +3,14 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { parse } from "./parse.ts";
import { parse, parseAll } from "./parse.ts";
import { test } from "../../testing/mod.ts";
import { assertEquals } from "../../testing/asserts.ts";
test({
name: "parsed correctly",
name: "`parse` parses single document yaml string",
fn(): void {
const FIXTURE = `
const yaml = `
test: toto
foo:
bar: True
@ -18,8 +18,40 @@ test({
qux: ~
`;
const ASSERTS = { test: "toto", foo: { bar: true, baz: 1, qux: null } };
const expected = { test: "toto", foo: { bar: true, baz: 1, qux: null } };
assertEquals(parse(FIXTURE), ASSERTS);
assertEquals(parse(yaml), expected);
}
});
test({
name: "`parseAll` parses the yaml string with multiple documents",
fn(): void {
const yaml = `
---
id: 1
name: Alice
---
id: 2
name: Bob
---
id: 3
name: Eve
`;
const expected = [
{
id: 1,
name: "Alice"
},
{
id: 2,
name: "Bob"
},
{
id: 3,
name: "Eve"
}
];
assertEquals(parseAll(yaml), expected);
}
});

View file

@ -22,10 +22,6 @@ export function isNull(value: unknown): value is null {
return value === null;
}
export function isNullOrUndefined(value: unknown): value is null | undefined {
return value === null || value === undefined;
}
export function isNumber(value: unknown): value is number {
return typeof value === "number" || value instanceof Number;
}