mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 23:15:58 +00:00
fix(cli): preserve explicit null output (#13342)
This commit is contained in:
3 files changed
+21
-5
No files matched your search
@@ -157,7 +157,7 @@ const formatDocument = (
|
||||
value: unknown,
|
||||
format: "toon" | "json" | "yaml" | "jsonl",
|
||||
): string => {
|
||||
if (value === null || value === undefined) return "";
|
||||
if (value === undefined) return "";
|
||||
switch (format) {
|
||||
case "json":
|
||||
return formatJson(value);
|
||||
@@ -486,7 +486,7 @@ const formatMarkdown = (
|
||||
value: unknown,
|
||||
path: readonly string[] = [],
|
||||
): string => {
|
||||
if (value == null && path.length === 0) return "";
|
||||
if (value === undefined) return "";
|
||||
if (isScalar(value)) {
|
||||
if (path.length === 0) return escapeMarkdownText(String(value));
|
||||
return `${markdownHeading(path)}${escapeMarkdownText(String(value))}`;
|
||||
|
||||
@@ -26,10 +26,11 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each<[string, unknown, "toon" | "json" | "yaml" | "jsonl", string]>([
|
||||
["no value as TOON", null, "toon", ""],
|
||||
it.each<[string, unknown, "toon" | "json" | "yaml" | "jsonl" | "md", string]>([
|
||||
["no value as TOON", undefined, "toon", ""],
|
||||
["no value as JSON", undefined, "json", ""],
|
||||
["no value as YAML", null, "yaml", ""],
|
||||
["no value as YAML", undefined, "yaml", ""],
|
||||
["no value as Markdown", undefined, "md", ""],
|
||||
["a scalar as TOON", 12, "toon", "12"],
|
||||
["text as TOON", "text", "toon", "text"],
|
||||
[
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Writable } from "node:stream";
|
||||
|
||||
import { estimateTokenCount } from "tokenx";
|
||||
import { expect, it } from "vitest";
|
||||
import { parseAllDocuments } from "yaml";
|
||||
|
||||
import { formatCliOutput } from "../../../src/cli/cliOutputFormatter.js";
|
||||
import {
|
||||
@@ -63,6 +64,20 @@ const runFilteredCli = async (
|
||||
return Buffer.concat(chunks).toString("utf8");
|
||||
};
|
||||
|
||||
it.each(["yaml", "toon", "md"] as const)(
|
||||
"emits a selected null as %s",
|
||||
async (format) => {
|
||||
const stdout = await runFilteredCli({ binding: null }, format, "binding");
|
||||
if (format === "yaml") {
|
||||
const documents = parseAllDocuments(stdout);
|
||||
expect(documents).toHaveLength(1);
|
||||
expect(documents[0]?.toJSON()).toBeNull();
|
||||
} else {
|
||||
expect(stdout).toBe("null\n");
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["csv", "tsv"] as const)(
|
||||
"exports only explicitly selected %s fields and retains page metadata",
|
||||
async (format) => {
|
||||
|
||||
Reference in new issue
Block a user