MCPcopy Create free account
hub / github.com/denoland/std / buildMessage

Function buildMessage

internal/build_message.ts:109–147  ·  view source on GitHub ↗
(
  diffResult: ReadonlyArray<DiffResult<string>>,
  options: BuildMessageOptions = {},
  truncateDiff?: (
    diffResult: ReadonlyArray<DiffResult<string>>,
    stringDiff: boolean,
    contextLength?: number | null,
  ) => ReadonlyArray<DiffResult<string>>,
)

Source from the content-addressed store, hash-verified

107 * ```
108 */
109export function buildMessage(
110 diffResult: ReadonlyArray<DiffResult<string>>,
111 options: BuildMessageOptions = {},
112 truncateDiff?: (
113 diffResult: ReadonlyArray<DiffResult<string>>,
114 stringDiff: boolean,
115 contextLength?: number | null,
116 ) => ReadonlyArray<DiffResult<string>>,
117): string[] {
118 if (truncateDiff != null) {
119 diffResult = truncateDiff(diffResult, options.stringDiff ?? false);
120 }
121
122 const { stringDiff = false } = options;
123 const messages = [
124 "",
125 "",
126 ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${
127 green(bold("Expected"))
128 }`,
129 "",
130 "",
131 ];
132 const diffMessages = diffResult.map((result) => {
133 const color = createColor(result.type);
134
135 const line = result.type === "added" || result.type === "removed"
136 ? result.details?.map((detail) =>
137 detail.type !== "common"
138 ? createColor(detail.type, true)(detail.value)
139 : detail.value
140 ).join("") ?? result.value
141 : result.value;
142
143 return color(`${createSign(result.type)}${line}`);
144 });
145 messages.push(...(stringDiff ? [diffMessages.join("")] : diffMessages), "");
146 return messages;
147}

Callers 6

throwSnapshotMismatchFunction · 0.85
buildEqualErrorMessageFunction · 0.85
assertEqualsFunction · 0.85
assertStrictEqualsFunction · 0.85

Calls 8

grayFunction · 0.90
boldFunction · 0.90
redFunction · 0.90
greenFunction · 0.90
truncateDiffFunction · 0.85
createColorFunction · 0.85
createSignFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected