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

Function convertExpectedBareItem

http/unstable_structured_fields_test.ts:735–766  ·  view source on GitHub ↗
(expected: any)

Source from the content-addressed store, hash-verified

733// Convert test suite expected value to our internal format
734// deno-lint-ignore no-explicit-any
735function convertExpectedBareItem(expected: any): BareItem {
736 if (expected === null || expected === undefined) {
737 throw new Error("Unexpected null/undefined bare item");
738 }
739 if (typeof expected === "boolean") {
740 return boolean(expected);
741 }
742 if (typeof expected === "number") {
743 if (Number.isInteger(expected)) {
744 return integer(expected);
745 }
746 return decimal(expected);
747 }
748 if (typeof expected === "string") {
749 return string(expected);
750 }
751 if (typeof expected === "object" && "__type" in expected) {
752 switch (expected.__type) {
753 case "token":
754 return token(expected.value);
755 case "binary":
756 return binary(decodeBase32(expected.value));
757 case "date":
758 return date(new Date(expected.value * 1000));
759 case "displaystring":
760 return displayString(expected.value);
761 default:
762 throw new Error(`Unknown __type: ${expected.__type}`);
763 }
764 }
765 throw new Error(`Cannot convert expected value: ${JSON.stringify(expected)}`);
766}
767
768// Convert test suite expected params array to Map
769// deno-lint-ignore no-explicit-any

Callers 2

convertExpectedParamsFunction · 0.85
convertExpectedItemFunction · 0.85

Calls 10

booleanFunction · 0.90
integerFunction · 0.90
decimalFunction · 0.90
stringFunction · 0.90
tokenFunction · 0.90
binaryFunction · 0.90
dateFunction · 0.90
displayStringFunction · 0.90
stringifyMethod · 0.80
decodeBase32Function · 0.70

Tested by

no test coverage detected