// warning: This file is auto generated by `yarn build:tests` // Do not edit by hand! import { createRequire } from 'node:module' import { describe, it, expect } from 'vitest' process.env.TZ = 'UTC' const __locutus_source_fn = require('../../../../src/python/calendar/formatstring.ts').formatstring const __locutus_source_module_url = new URL("../../../../src/python/calendar/formatstring.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "formatstring" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.formatstring = formatstring;\nconst _calendar_ts_1 = require(\"../_helpers/_calendar.ts\");\nfunction formatstring(items, cols = 20, spacing = 6) {\n // discuss at: https://locutus.io/python/calendar/formatstring/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // example 1: formatstring(['a', 'bb', 'ccc'], 2, 0)\n // returns 1: 'a bbccc'\n if (arguments.length === 0) {\n throw new TypeError(\"formatstring() missing 1 required positional argument: 'cols'\");\n }\n return (0, _calendar_ts_1.formatString)(items, (0, _calendar_ts_1.toCalendarInteger)(cols, 'formatstring'), (0, _calendar_ts_1.toCalendarInteger)(spacing, 'formatstring'));\n}" const __locutus_standalone_ts_code = "// python/_helpers/_calendar (Locutus helper dependency)\nfunction toCalendarInteger(value, functionName) {\n if (typeof value === 'boolean') {\n return value ? 1 : 0;\n }\n if (typeof value === 'bigint') {\n const numericValue = Number(value);\n if (!Number.isSafeInteger(numericValue)) {\n throw new RangeError(`${functionName}() integer arguments must fit within JS safe integer precision`);\n }\n return numericValue;\n }\n if (typeof value === 'number' && Number.isFinite(value) && Number.isSafeInteger(value)) {\n return value;\n }\n throw new TypeError(`${functionName}() requires integer arguments`);\n}\nfunction formatString(items, cols = 20, spacing = 6) {\n if (!isIterable(items)) {\n throw new TypeError(\"'object' object is not iterable\");\n }\n const values = [...items];\n return values.map((value) => centerMethodString(value, cols)).join(' '.repeat(spacing));\n}\nfunction centerText(value, width) {\n if (width <= value.length) {\n return value;\n }\n const leftPadding = Math.floor((width - value.length) / 2);\n const rightPadding = width - value.length - leftPadding;\n return `${' '.repeat(leftPadding)}${value}${' '.repeat(rightPadding)}`;\n}\nfunction isIterable(value) {\n return (value !== null &&\n value !== undefined &&\n typeof value[Symbol.iterator] === 'function');\n}\nfunction centerMethodString(value, width) {\n if (typeof value !== 'string') {\n throw new AttributeError(`${value === null ? 'NoneType' : typeof value} object has no attribute 'center'`);\n }\n return centerText(value, width);\n}\nclass AttributeError extends Error {\n constructor(message) {\n super(message);\n this.name = 'AttributeError';\n }\n}\n// python/calendar/formatstring (target function module)\nfunction formatstring(items, cols = 20, spacing = 6) {\n // discuss at: https://locutus.io/python/calendar/formatstring/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // example 1: formatstring(['a', 'bb', 'ccc'], 2, 0)\n // returns 1: 'a bbccc'\n if (arguments.length === 0) {\n throw new TypeError(\"formatstring() missing 1 required positional argument: 'cols'\");\n }\n return formatString(items, toCalendarInteger(cols, 'formatstring'), toCalendarInteger(spacing, 'formatstring'));\n}" const __locutus_standalone_js_code = "// python/_helpers/_calendar (Locutus helper dependency)\nfunction toCalendarInteger(value, functionName) {\n if (typeof value === 'boolean') {\n return value ? 1 : 0;\n }\n if (typeof value === 'bigint') {\n const numericValue = Number(value);\n if (!Number.isSafeInteger(numericValue)) {\n throw new RangeError(`${functionName}() integer arguments must fit within JS safe integer precision`);\n }\n return numericValue;\n }\n if (typeof value === 'number' && Number.isFinite(value) && Number.isSafeInteger(value)) {\n return value;\n }\n throw new TypeError(`${functionName}() requires integer arguments`);\n}\nfunction formatString(items, cols = 20, spacing = 6) {\n if (!isIterable(items)) {\n throw new TypeError(\"'object' object is not iterable\");\n }\n const values = [...items];\n return values.map((value) => centerMethodString(value, cols)).join(' '.repeat(spacing));\n}\nfunction centerText(value, width) {\n if (width <= value.length) {\n return value;\n }\n const leftPadding = Math.floor((width - value.length) / 2);\n const rightPadding = width - value.length - leftPadding;\n return `${' '.repeat(leftPadding)}${value}${' '.repeat(rightPadding)}`;\n}\nfunction isIterable(value) {\n return value !== null && value !== undefined && typeof value[Symbol.iterator] === 'function';\n}\nfunction centerMethodString(value, width) {\n if (typeof value !== 'string') {\n throw new AttributeError(`${value === null ? 'NoneType' : typeof value} object has no attribute 'center'`);\n }\n return centerText(value, width);\n}\nclass AttributeError extends Error {\n constructor(message) {\n super(message);\n this.name = 'AttributeError';\n }\n}\n// python/calendar/formatstring (target function module)\nfunction formatstring(items, cols = 20, spacing = 6) {\n // discuss at: https://locutus.io/python/calendar/formatstring/\n // parity verified: Python 3.12\n // original by: Kevin van Zonneveld (https://kvz.io)\n // example 1: formatstring(['a', 'bb', 'ccc'], 2, 0)\n // returns 1: 'a bbccc'\n if (arguments.length === 0) {\n throw new TypeError(\"formatstring() missing 1 required positional argument: 'cols'\");\n }\n return formatString(items, toCalendarInteger(cols, 'formatstring'), toCalendarInteger(spacing, 'formatstring'));\n}" const __locutus_eval_function = (compiledCode: string): ((...args: unknown[]) => unknown) => { const evaluator = new Function('require', compiledCode + '\nreturn ' + __locutus_func_name + ';') return evaluator(__locutus_source_require) as (...args: unknown[]) => unknown } const __locutus_eval_module_export = (compiledCode: string, exportName: string): ((...args: unknown[]) => unknown) => { const module = { exports: {} as { [key: string]: unknown } } const exports = module.exports const evaluator = new Function('exports', 'module', 'require', compiledCode) evaluator(exports, module, __locutus_source_require) return module.exports[exportName] as (...args: unknown[]) => unknown } const __locutus_module_js_fn = __locutus_eval_module_export(__locutus_module_js_code, __locutus_func_name) const __locutus_standalone_ts_fn = __locutus_eval_function(__locutus_standalone_ts_code) const __locutus_standalone_js_fn = __locutus_eval_function(__locutus_standalone_js_code) describe('src/python/calendar/formatstring.ts (tested in test/generated/python/calendar/formatstring.vitest.ts)', function () { it('should pass example 1', function () { const expected = 'a bbccc' const __locutus_variants: Array<{ name: string; fn: (...args: unknown[]) => unknown }> = [ { name: "source", fn: __locutus_source_fn }, { name: "module-js", fn: __locutus_module_js_fn }, { name: "standalone-ts", fn: __locutus_standalone_ts_fn }, { name: "standalone-js", fn: __locutus_standalone_js_fn }, ] const __locutus_run_example = (formatstring: typeof __locutus_source_fn) => { return formatstring(['a', 'bb', 'ccc'], 2, 0) } for (const __locutus_variant of __locutus_variants) { const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) })