// 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/xml/utf8_encode.ts').utf8_encode const __locutus_source_module_url = new URL("../../../../src/php/xml/utf8_encode.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "utf8_encode" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.utf8_encode = utf8_encode;\nfunction utf8_encode(argString) {\n // discuss at: https://locutus.io/php/utf8_encode/\n // parity verified: PHP 8.3\n // original by: Webtoolkit.info (https://www.webtoolkit.info/)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: sowberry\n // improved by: Jack\n // improved by: Yves Sucaet\n // improved by: kirilloid\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // bugfixed by: Ulrich\n // bugfixed by: Rafał Kukawski (https://blog.kukawski.pl)\n // bugfixed by: kirilloid\n // example 1: utf8_encode('Kevin van Zonneveld')\n // returns 1: 'Kevin van Zonneveld'\n if (argString === null || typeof argString === 'undefined') {\n return '';\n }\n // .replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n const string = argString + '';\n let utftext = '';\n let start;\n let end;\n let stringl = 0;\n start = end = 0;\n stringl = string.length;\n for (let n = 0; n < stringl; n++) {\n let c1 = string.charCodeAt(n);\n let enc = null;\n if (c1 < 128) {\n end++;\n }\n else if (c1 > 127 && c1 < 2048) {\n enc = String.fromCharCode((c1 >> 6) | 192, (c1 & 63) | 128);\n }\n else if ((c1 & 0xf800) !== 0xd800) {\n enc = String.fromCharCode((c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);\n }\n else {\n // surrogate pairs\n if ((c1 & 0xfc00) !== 0xd800) {\n throw new RangeError('Unmatched trail surrogate at ' + n);\n }\n const c2 = string.charCodeAt(++n);\n if ((c2 & 0xfc00) !== 0xdc00) {\n throw new RangeError('Unmatched lead surrogate at ' + (n - 1));\n }\n c1 = ((c1 & 0x3ff) << 10) + (c2 & 0x3ff) + 0x10000;\n enc = String.fromCharCode((c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);\n }\n if (enc !== null) {\n if (end > start) {\n utftext += string.slice(start, end);\n }\n utftext += enc;\n start = end = n + 1;\n }\n }\n if (end > start) {\n utftext += string.slice(start, stringl);\n }\n return utftext;\n}" const __locutus_standalone_ts_code = "// php/xml/utf8_encode (target function module)\nfunction utf8_encode(argString) {\n // discuss at: https://locutus.io/php/utf8_encode/\n // parity verified: PHP 8.3\n // original by: Webtoolkit.info (https://www.webtoolkit.info/)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: sowberry\n // improved by: Jack\n // improved by: Yves Sucaet\n // improved by: kirilloid\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // bugfixed by: Ulrich\n // bugfixed by: Rafał Kukawski (https://blog.kukawski.pl)\n // bugfixed by: kirilloid\n // example 1: utf8_encode('Kevin van Zonneveld')\n // returns 1: 'Kevin van Zonneveld'\n if (argString === null || typeof argString === 'undefined') {\n return '';\n }\n // .replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n const string = argString + '';\n let utftext = '';\n let start;\n let end;\n let stringl = 0;\n start = end = 0;\n stringl = string.length;\n for (let n = 0; n < stringl; n++) {\n let c1 = string.charCodeAt(n);\n let enc = null;\n if (c1 < 128) {\n end++;\n }\n else if (c1 > 127 && c1 < 2048) {\n enc = String.fromCharCode((c1 >> 6) | 192, (c1 & 63) | 128);\n }\n else if ((c1 & 0xf800) !== 0xd800) {\n enc = String.fromCharCode((c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);\n }\n else {\n // surrogate pairs\n if ((c1 & 0xfc00) !== 0xd800) {\n throw new RangeError('Unmatched trail surrogate at ' + n);\n }\n const c2 = string.charCodeAt(++n);\n if ((c2 & 0xfc00) !== 0xdc00) {\n throw new RangeError('Unmatched lead surrogate at ' + (n - 1));\n }\n c1 = ((c1 & 0x3ff) << 10) + (c2 & 0x3ff) + 0x10000;\n enc = String.fromCharCode((c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);\n }\n if (enc !== null) {\n if (end > start) {\n utftext += string.slice(start, end);\n }\n utftext += enc;\n start = end = n + 1;\n }\n }\n if (end > start) {\n utftext += string.slice(start, stringl);\n }\n return utftext;\n}" const __locutus_standalone_js_code = "// php/xml/utf8_encode (target function module)\nfunction utf8_encode(argString) {\n // discuss at: https://locutus.io/php/utf8_encode/\n // parity verified: PHP 8.3\n // original by: Webtoolkit.info (https://www.webtoolkit.info/)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: sowberry\n // improved by: Jack\n // improved by: Yves Sucaet\n // improved by: kirilloid\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // bugfixed by: Ulrich\n // bugfixed by: Rafał Kukawski (https://blog.kukawski.pl)\n // bugfixed by: kirilloid\n // example 1: utf8_encode('Kevin van Zonneveld')\n // returns 1: 'Kevin van Zonneveld'\n if (argString === null || typeof argString === 'undefined') {\n return '';\n }\n // .replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n const string = argString + '';\n let utftext = '';\n let start;\n let end;\n let stringl = 0;\n start = end = 0;\n stringl = string.length;\n for (let n = 0; n < stringl; n++) {\n let c1 = string.charCodeAt(n);\n let enc = null;\n if (c1 < 128) {\n end++;\n }\n else if (c1 > 127 && c1 < 2048) {\n enc = String.fromCharCode((c1 >> 6) | 192, (c1 & 63) | 128);\n }\n else if ((c1 & 0xf800) !== 0xd800) {\n enc = String.fromCharCode((c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);\n }\n else {\n // surrogate pairs\n if ((c1 & 0xfc00) !== 0xd800) {\n throw new RangeError('Unmatched trail surrogate at ' + n);\n }\n const c2 = string.charCodeAt(++n);\n if ((c2 & 0xfc00) !== 0xdc00) {\n throw new RangeError('Unmatched lead surrogate at ' + (n - 1));\n }\n c1 = ((c1 & 0x3ff) << 10) + (c2 & 0x3ff) + 0x10000;\n enc = String.fromCharCode((c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128);\n }\n if (enc !== null) {\n if (end > start) {\n utftext += string.slice(start, end);\n }\n utftext += enc;\n start = end = n + 1;\n }\n }\n if (end > start) {\n utftext += string.slice(start, stringl);\n }\n return utftext;\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/xml/utf8_encode.ts (tested in test/generated/php/xml/utf8_encode.vitest.ts)', function () { it('should pass example 1', function () { const expected = 'Kevin van Zonneveld' 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 = (utf8_encode: typeof __locutus_source_fn) => { return utf8_encode('Kevin van Zonneveld') } 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) } }) })