// 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 ini_set = require('../../../../src/php/info/ini_set.ts').ini_set const ini_get = require('../../../../src/php/info/ini_get.ts').ini_get const __locutus_source_fn = require('../../../../src/php/strings/sprintf.ts').sprintf const __locutus_source_module_url = new URL("../../../../src/php/strings/sprintf.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "sprintf" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.sprintf = sprintf;\nfunction sprintf(format, ...args) {\n // discuss at: https://locutus.io/php/sprintf/\n // parity verified: PHP 8.3\n // original by: Ash Searle (https://hexmen.com/blog/)\n // improved by: Michael White (https://getsprink.com)\n // improved by: Jack\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Dj\n // improved by: Allidylls\n // input by: Paulo Freitas\n // input by: Brett Zamir (https://brett-zamir.me)\n // improved by: Rafał Kukawski (https://kukawski.pl)\n // example 1: sprintf(\"%01.2f\", 123.1)\n // returns 1: '123.10'\n // example 2: sprintf(\"[%10s]\", 'monkey')\n // returns 2: '[ monkey]'\n // example 3: sprintf(\"[%'#10s]\", 'monkey')\n // returns 3: '[####monkey]'\n // example 4: sprintf(\"%d\", 123456789012345)\n // returns 4: '123456789012345'\n // example 5: sprintf('%-03s', 'E')\n // returns 5: 'E00'\n // example 6: sprintf('%+010d', 9)\n // returns 6: '+000000009'\n // example 7: sprintf('%+0\\'@10d', 9)\n // returns 7: '@@@@@@@@+9'\n // example 8: sprintf('%.f', 3.14)\n // returns 8: '3.140000'\n // example 9: sprintf('%% %2$d', 1, 2)\n // returns 9: '% 2'\n const regex = /%%|%(?:(\\d+)\\$)?((?:[-+#0 ]|'[\\s\\S])*)(\\d+)?(?:\\.(\\d*))?([\\s\\S])/g;\n const callArgs = [format, ...args];\n let i = 1;\n const _pad = function (str, len, chr, leftJustify) {\n if (!chr) {\n chr = ' ';\n }\n const padding = str.length >= len ? '' : new Array((1 + len - str.length) >>> 0).join(chr);\n return leftJustify ? str + padding : padding + str;\n };\n const justify = function (value, prefix, leftJustify, minWidth, padChar) {\n const diff = minWidth - value.length;\n if (diff > 0) {\n // when padding with zeros\n // on the left side\n // keep sign (+ or -) in front\n if (!leftJustify && padChar === '0') {\n value = [value.slice(0, prefix.length), _pad('', diff, '0', true), value.slice(prefix.length)].join('');\n }\n else {\n value = _pad(value, minWidth, padChar, leftJustify);\n }\n }\n return value;\n };\n const _formatBaseX = function (value, base, leftJustify, minWidth, precision, padChar) {\n // Note: casts negative numbers to positive ones\n const number = Number(value) >>> 0;\n const padded = _pad(number.toString(base), precision || 0, '0', false);\n return justify(padded, '', leftJustify, minWidth, padChar);\n };\n // _formatString()\n const _formatString = function (value, leftJustify, minWidth, precision, customPadChar) {\n if (precision !== null && precision !== undefined) {\n value = value.slice(0, precision);\n }\n return justify(value, '', leftJustify, minWidth, customPadChar);\n };\n // doFormat()\n const doFormat = function (substring, argIndex, modifiers, minWidthRaw, precisionRaw, specifier) {\n let number = 0;\n let prefix = '';\n let value;\n if (substring === '%%') {\n return '%';\n }\n // parse modifiers\n let padChar = ' '; // pad with spaces by default\n let leftJustify = false;\n let positiveNumberPrefix = '';\n let j = 0;\n let l = 0;\n for (j = 0, l = modifiers.length; j < l; j++) {\n switch (modifiers.charAt(j)) {\n case ' ':\n case '0':\n padChar = modifiers.charAt(j);\n break;\n case '+':\n positiveNumberPrefix = '+';\n break;\n case '-':\n leftJustify = true;\n break;\n case \"'\":\n if (j + 1 < l) {\n padChar = modifiers.charAt(j + 1);\n j++;\n }\n break;\n }\n }\n let minWidthNum = 0;\n if (!minWidthRaw) {\n minWidthNum = 0;\n }\n else {\n minWidthNum = +minWidthRaw;\n }\n if (!isFinite(minWidthNum)) {\n throw new Error('Width must be finite');\n }\n let precisionNum;\n if (!precisionRaw) {\n precisionNum = specifier === 'd' ? 0 : 'fFeE'.includes(specifier) ? 6 : undefined;\n }\n else {\n precisionNum = +precisionRaw;\n }\n if (argIndex && +argIndex === 0) {\n throw new Error('Argument number must be greater than zero');\n }\n if (argIndex && +argIndex >= callArgs.length) {\n throw new Error('Too few arguments');\n }\n value = argIndex ? callArgs[+argIndex] : callArgs[i++];\n switch (specifier) {\n case '%':\n return '%';\n case 's':\n return _formatString(String(value), leftJustify, minWidthNum, precisionNum, padChar);\n case 'c':\n return _formatString(String.fromCharCode(+String(value)), leftJustify, minWidthNum, precisionNum, padChar);\n case 'b':\n return _formatBaseX(value, 2, leftJustify, minWidthNum, precisionNum, padChar);\n case 'o':\n return _formatBaseX(value, 8, leftJustify, minWidthNum, precisionNum, padChar);\n case 'x':\n return _formatBaseX(value, 16, leftJustify, minWidthNum, precisionNum, padChar);\n case 'X':\n return _formatBaseX(value, 16, leftJustify, minWidthNum, precisionNum, padChar).toUpperCase();\n case 'u':\n return _formatBaseX(value, 10, leftJustify, minWidthNum, precisionNum, padChar);\n case 'i':\n case 'd':\n number = +String(value) || 0;\n // Plain Math.round doesn't just truncate\n number = Math.round(number - (number % 1));\n prefix = number < 0 ? '-' : positiveNumberPrefix;\n value = prefix + _pad(String(Math.abs(number)), precisionNum ?? 0, '0', false);\n if (leftJustify && padChar === '0') {\n // can't right-pad 0s on integers\n padChar = ' ';\n }\n return justify(String(value), prefix, leftJustify, minWidthNum, padChar);\n case 'e':\n case 'E':\n case 'f': // @todo: Should handle locales (as per setlocale)\n case 'F':\n case 'g':\n case 'G': {\n number = +String(value);\n prefix = number < 0 ? '-' : positiveNumberPrefix;\n const methodIndex = 'efg'.indexOf(specifier.toLowerCase());\n const absNumber = Math.abs(number);\n let floatResult = '';\n if (methodIndex === 0) {\n floatResult = absNumber.toExponential(precisionNum);\n }\n else if (methodIndex === 1) {\n floatResult = absNumber.toFixed(precisionNum);\n }\n else {\n floatResult = absNumber.toPrecision(precisionNum);\n }\n const justified = justify(prefix + floatResult, prefix, leftJustify, minWidthNum, padChar);\n return 'eEfFgG'.indexOf(specifier) % 2 === 0 ? justified : justified.toUpperCase();\n }\n default:\n // unsupported specifier, consume that char and return empty\n return '';\n }\n };\n try {\n return format.replace(regex, doFormat);\n }\n catch (_err) {\n return false;\n }\n}" const __locutus_standalone_ts_code = "function sprintf(format, ...args) {\n // discuss at: https://locutus.io/php/sprintf/\n // parity verified: PHP 8.3\n // original by: Ash Searle (https://hexmen.com/blog/)\n // improved by: Michael White (https://getsprink.com)\n // improved by: Jack\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Dj\n // improved by: Allidylls\n // input by: Paulo Freitas\n // input by: Brett Zamir (https://brett-zamir.me)\n // improved by: Rafał Kukawski (https://kukawski.pl)\n // example 1: sprintf(\"%01.2f\", 123.1)\n // returns 1: '123.10'\n // example 2: sprintf(\"[%10s]\", 'monkey')\n // returns 2: '[ monkey]'\n // example 3: sprintf(\"[%'#10s]\", 'monkey')\n // returns 3: '[####monkey]'\n // example 4: sprintf(\"%d\", 123456789012345)\n // returns 4: '123456789012345'\n // example 5: sprintf('%-03s', 'E')\n // returns 5: 'E00'\n // example 6: sprintf('%+010d', 9)\n // returns 6: '+000000009'\n // example 7: sprintf('%+0\\'@10d', 9)\n // returns 7: '@@@@@@@@+9'\n // example 8: sprintf('%.f', 3.14)\n // returns 8: '3.140000'\n // example 9: sprintf('%% %2$d', 1, 2)\n // returns 9: '% 2'\n const regex = /%%|%(?:(\\d+)\\$)?((?:[-+#0 ]|'[\\s\\S])*)(\\d+)?(?:\\.(\\d*))?([\\s\\S])/g;\n const callArgs = [format, ...args];\n let i = 1;\n const _pad = function (str, len, chr, leftJustify) {\n if (!chr) {\n chr = ' ';\n }\n const padding = str.length >= len ? '' : new Array((1 + len - str.length) >>> 0).join(chr);\n return leftJustify ? str + padding : padding + str;\n };\n const justify = function (value, prefix, leftJustify, minWidth, padChar) {\n const diff = minWidth - value.length;\n if (diff > 0) {\n // when padding with zeros\n // on the left side\n // keep sign (+ or -) in front\n if (!leftJustify && padChar === '0') {\n value = [value.slice(0, prefix.length), _pad('', diff, '0', true), value.slice(prefix.length)].join('');\n }\n else {\n value = _pad(value, minWidth, padChar, leftJustify);\n }\n }\n return value;\n };\n const _formatBaseX = function (value, base, leftJustify, minWidth, precision, padChar) {\n // Note: casts negative numbers to positive ones\n const number = Number(value) >>> 0;\n const padded = _pad(number.toString(base), precision || 0, '0', false);\n return justify(padded, '', leftJustify, minWidth, padChar);\n };\n // _formatString()\n const _formatString = function (value, leftJustify, minWidth, precision, customPadChar) {\n if (precision !== null && precision !== undefined) {\n value = value.slice(0, precision);\n }\n return justify(value, '', leftJustify, minWidth, customPadChar);\n };\n // doFormat()\n const doFormat = function (substring, argIndex, modifiers, minWidthRaw, precisionRaw, specifier) {\n let number = 0;\n let prefix = '';\n let value;\n if (substring === '%%') {\n return '%';\n }\n // parse modifiers\n let padChar = ' '; // pad with spaces by default\n let leftJustify = false;\n let positiveNumberPrefix = '';\n let j = 0;\n let l = 0;\n for (j = 0, l = modifiers.length; j < l; j++) {\n switch (modifiers.charAt(j)) {\n case ' ':\n case '0':\n padChar = modifiers.charAt(j);\n break;\n case '+':\n positiveNumberPrefix = '+';\n break;\n case '-':\n leftJustify = true;\n break;\n case \"'\":\n if (j + 1 < l) {\n padChar = modifiers.charAt(j + 1);\n j++;\n }\n break;\n }\n }\n let minWidthNum = 0;\n if (!minWidthRaw) {\n minWidthNum = 0;\n }\n else {\n minWidthNum = +minWidthRaw;\n }\n if (!isFinite(minWidthNum)) {\n throw new Error('Width must be finite');\n }\n let precisionNum;\n if (!precisionRaw) {\n precisionNum = specifier === 'd' ? 0 : 'fFeE'.includes(specifier) ? 6 : undefined;\n }\n else {\n precisionNum = +precisionRaw;\n }\n if (argIndex && +argIndex === 0) {\n throw new Error('Argument number must be greater than zero');\n }\n if (argIndex && +argIndex >= callArgs.length) {\n throw new Error('Too few arguments');\n }\n value = argIndex ? callArgs[+argIndex] : callArgs[i++];\n switch (specifier) {\n case '%':\n return '%';\n case 's':\n return _formatString(String(value), leftJustify, minWidthNum, precisionNum, padChar);\n case 'c':\n return _formatString(String.fromCharCode(+String(value)), leftJustify, minWidthNum, precisionNum, padChar);\n case 'b':\n return _formatBaseX(value, 2, leftJustify, minWidthNum, precisionNum, padChar);\n case 'o':\n return _formatBaseX(value, 8, leftJustify, minWidthNum, precisionNum, padChar);\n case 'x':\n return _formatBaseX(value, 16, leftJustify, minWidthNum, precisionNum, padChar);\n case 'X':\n return _formatBaseX(value, 16, leftJustify, minWidthNum, precisionNum, padChar).toUpperCase();\n case 'u':\n return _formatBaseX(value, 10, leftJustify, minWidthNum, precisionNum, padChar);\n case 'i':\n case 'd':\n number = +String(value) || 0;\n // Plain Math.round doesn't just truncate\n number = Math.round(number - (number % 1));\n prefix = number < 0 ? '-' : positiveNumberPrefix;\n value = prefix + _pad(String(Math.abs(number)), precisionNum ?? 0, '0', false);\n if (leftJustify && padChar === '0') {\n // can't right-pad 0s on integers\n padChar = ' ';\n }\n return justify(String(value), prefix, leftJustify, minWidthNum, padChar);\n case 'e':\n case 'E':\n case 'f': // @todo: Should handle locales (as per setlocale)\n case 'F':\n case 'g':\n case 'G': {\n number = +String(value);\n prefix = number < 0 ? '-' : positiveNumberPrefix;\n const methodIndex = 'efg'.indexOf(specifier.toLowerCase());\n const absNumber = Math.abs(number);\n let floatResult = '';\n if (methodIndex === 0) {\n floatResult = absNumber.toExponential(precisionNum);\n }\n else if (methodIndex === 1) {\n floatResult = absNumber.toFixed(precisionNum);\n }\n else {\n floatResult = absNumber.toPrecision(precisionNum);\n }\n const justified = justify(prefix + floatResult, prefix, leftJustify, minWidthNum, padChar);\n return 'eEfFgG'.indexOf(specifier) % 2 === 0 ? justified : justified.toUpperCase();\n }\n default:\n // unsupported specifier, consume that char and return empty\n return '';\n }\n };\n try {\n return format.replace(regex, doFormat);\n }\n catch (_err) {\n return false;\n }\n}" const __locutus_standalone_js_code = "// php/strings/sprintf (target function module)\nfunction sprintf(format, ...args) {\n // discuss at: https://locutus.io/php/sprintf/\n // parity verified: PHP 8.3\n // original by: Ash Searle (https://hexmen.com/blog/)\n // improved by: Michael White (https://getsprink.com)\n // improved by: Jack\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Dj\n // improved by: Allidylls\n // input by: Paulo Freitas\n // input by: Brett Zamir (https://brett-zamir.me)\n // improved by: Rafał Kukawski (https://kukawski.pl)\n // example 1: sprintf(\"%01.2f\", 123.1)\n // returns 1: '123.10'\n // example 2: sprintf(\"[%10s]\", 'monkey')\n // returns 2: '[ monkey]'\n // example 3: sprintf(\"[%'#10s]\", 'monkey')\n // returns 3: '[####monkey]'\n // example 4: sprintf(\"%d\", 123456789012345)\n // returns 4: '123456789012345'\n // example 5: sprintf('%-03s', 'E')\n // returns 5: 'E00'\n // example 6: sprintf('%+010d', 9)\n // returns 6: '+000000009'\n // example 7: sprintf('%+0\\'@10d', 9)\n // returns 7: '@@@@@@@@+9'\n // example 8: sprintf('%.f', 3.14)\n // returns 8: '3.140000'\n // example 9: sprintf('%% %2$d', 1, 2)\n // returns 9: '% 2'\n const regex = /%%|%(?:(\\d+)\\$)?((?:[-+#0 ]|'[\\s\\S])*)(\\d+)?(?:\\.(\\d*))?([\\s\\S])/g;\n const callArgs = [format, ...args];\n let i = 1;\n const _pad = function (str, len, chr, leftJustify) {\n if (!chr) {\n chr = ' ';\n }\n const padding = str.length >= len ? '' : new Array((1 + len - str.length) >>> 0).join(chr);\n return leftJustify ? str + padding : padding + str;\n };\n const justify = function (value, prefix, leftJustify, minWidth, padChar) {\n const diff = minWidth - value.length;\n if (diff > 0) {\n // when padding with zeros\n // on the left side\n // keep sign (+ or -) in front\n if (!leftJustify && padChar === '0') {\n value = [value.slice(0, prefix.length), _pad('', diff, '0', true), value.slice(prefix.length)].join('');\n }\n else {\n value = _pad(value, minWidth, padChar, leftJustify);\n }\n }\n return value;\n };\n const _formatBaseX = function (value, base, leftJustify, minWidth, precision, padChar) {\n // Note: casts negative numbers to positive ones\n const number = Number(value) >>> 0;\n const padded = _pad(number.toString(base), precision || 0, '0', false);\n return justify(padded, '', leftJustify, minWidth, padChar);\n };\n // _formatString()\n const _formatString = function (value, leftJustify, minWidth, precision, customPadChar) {\n if (precision !== null && precision !== undefined) {\n value = value.slice(0, precision);\n }\n return justify(value, '', leftJustify, minWidth, customPadChar);\n };\n // doFormat()\n const doFormat = function (substring, argIndex, modifiers, minWidthRaw, precisionRaw, specifier) {\n let number = 0;\n let prefix = '';\n let value;\n if (substring === '%%') {\n return '%';\n }\n // parse modifiers\n let padChar = ' '; // pad with spaces by default\n let leftJustify = false;\n let positiveNumberPrefix = '';\n let j = 0;\n let l = 0;\n for (j = 0, l = modifiers.length; j < l; j++) {\n switch (modifiers.charAt(j)) {\n case ' ':\n case '0':\n padChar = modifiers.charAt(j);\n break;\n case '+':\n positiveNumberPrefix = '+';\n break;\n case '-':\n leftJustify = true;\n break;\n case \"'\":\n if (j + 1 < l) {\n padChar = modifiers.charAt(j + 1);\n j++;\n }\n break;\n }\n }\n let minWidthNum = 0;\n if (!minWidthRaw) {\n minWidthNum = 0;\n }\n else {\n minWidthNum = +minWidthRaw;\n }\n if (!isFinite(minWidthNum)) {\n throw new Error('Width must be finite');\n }\n let precisionNum;\n if (!precisionRaw) {\n precisionNum = specifier === 'd' ? 0 : 'fFeE'.includes(specifier) ? 6 : undefined;\n }\n else {\n precisionNum = +precisionRaw;\n }\n if (argIndex && +argIndex === 0) {\n throw new Error('Argument number must be greater than zero');\n }\n if (argIndex && +argIndex >= callArgs.length) {\n throw new Error('Too few arguments');\n }\n value = argIndex ? callArgs[+argIndex] : callArgs[i++];\n switch (specifier) {\n case '%':\n return '%';\n case 's':\n return _formatString(String(value), leftJustify, minWidthNum, precisionNum, padChar);\n case 'c':\n return _formatString(String.fromCharCode(+String(value)), leftJustify, minWidthNum, precisionNum, padChar);\n case 'b':\n return _formatBaseX(value, 2, leftJustify, minWidthNum, precisionNum, padChar);\n case 'o':\n return _formatBaseX(value, 8, leftJustify, minWidthNum, precisionNum, padChar);\n case 'x':\n return _formatBaseX(value, 16, leftJustify, minWidthNum, precisionNum, padChar);\n case 'X':\n return _formatBaseX(value, 16, leftJustify, minWidthNum, precisionNum, padChar).toUpperCase();\n case 'u':\n return _formatBaseX(value, 10, leftJustify, minWidthNum, precisionNum, padChar);\n case 'i':\n case 'd':\n number = +String(value) || 0;\n // Plain Math.round doesn't just truncate\n number = Math.round(number - (number % 1));\n prefix = number < 0 ? '-' : positiveNumberPrefix;\n value = prefix + _pad(String(Math.abs(number)), precisionNum ?? 0, '0', false);\n if (leftJustify && padChar === '0') {\n // can't right-pad 0s on integers\n padChar = ' ';\n }\n return justify(String(value), prefix, leftJustify, minWidthNum, padChar);\n case 'e':\n case 'E':\n case 'f': // @todo: Should handle locales (as per setlocale)\n case 'F':\n case 'g':\n case 'G': {\n number = +String(value);\n prefix = number < 0 ? '-' : positiveNumberPrefix;\n const methodIndex = 'efg'.indexOf(specifier.toLowerCase());\n const absNumber = Math.abs(number);\n let floatResult = '';\n if (methodIndex === 0) {\n floatResult = absNumber.toExponential(precisionNum);\n }\n else if (methodIndex === 1) {\n floatResult = absNumber.toFixed(precisionNum);\n }\n else {\n floatResult = absNumber.toPrecision(precisionNum);\n }\n const justified = justify(prefix + floatResult, prefix, leftJustify, minWidthNum, padChar);\n return 'eEfFgG'.indexOf(specifier) % 2 === 0 ? justified : justified.toUpperCase();\n }\n default:\n // unsupported specifier, consume that char and return empty\n return '';\n }\n };\n try {\n return format.replace(regex, doFormat);\n }\n catch (_err) {\n return false;\n }\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/php/strings/sprintf.ts (tested in test/generated/php/strings/sprintf.vitest.ts)', function () { it('should pass example 1', function () { const expected = '123.10' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf("%01.2f", 123.1) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 2', function () { const expected = '[ monkey]' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf("[%10s]", 'monkey') } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 3', function () { const expected = '[####monkey]' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf("[%'#10s]", 'monkey') } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 4', function () { const expected = '123456789012345' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf("%d", 123456789012345) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 5', function () { const expected = 'E00' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf('%-03s', 'E') } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 6', function () { const expected = '+000000009' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf('%+010d', 9) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 7', function () { const expected = '@@@@@@@@+9' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf('%+0\'@10d', 9) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 8', function () { const expected = '3.140000' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf('%.f', 3.14) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) it('should pass example 9', function () { const expected = '% 2' 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 = (sprintf: typeof __locutus_source_fn) => { return sprintf('%% %2$d', 1, 2) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) })