// 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/array/array_pop.ts').array_pop const __locutus_source_module_url = new URL("../../../../src/php/array/array_pop.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "array_pop" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.array_pop = array_pop;\nfunction array_pop(inputArr) {\n // discuss at: https://locutus.io/php/array_pop/\n // original by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // input by: Brett Zamir (https://brett-zamir.me)\n // input by: Theriault (https://github.com/Theriault)\n // bugfixed by: Kevin van Zonneveld (https://kvz.io)\n // bugfixed by: Brett Zamir (https://brett-zamir.me)\n // note 1: While IE (and other browsers) support iterating an object's\n // note 1: own properties in order, if one attempts to add back properties\n // note 1: in IE, they may end up in their former position due to their position\n // note 1: being retained. So use of this function with \"associative arrays\"\n // note 1: (objects) may lead to unexpected behavior in an IE environment if\n // note 1: you add back properties with the same keys that you removed\n // example 1: array_pop([0,1,2])\n // returns 1: 2\n // example 2: var $data = {firstName: 'Kevin', surName: 'van Zonneveld'}\n // example 2: var $lastElem = array_pop($data)\n // example 2: var $result = $data\n // returns 2: {firstName: 'Kevin'}\n let key = '';\n let lastKey = '';\n if (Array.isArray(inputArr)) {\n // Indexed\n if (!inputArr.length) {\n // Done popping, are we?\n return null;\n }\n return inputArr.pop() ?? null;\n }\n else {\n // Associative\n for (key in inputArr) {\n if (inputArr.hasOwnProperty(key)) {\n lastKey = key;\n }\n }\n if (lastKey) {\n const tmp = inputArr[lastKey];\n if (tmp === undefined) {\n return null;\n }\n delete inputArr[lastKey];\n return tmp;\n }\n else {\n return null;\n }\n }\n}" const __locutus_standalone_ts_code = "// php/array/array_pop (target function module)\nfunction array_pop(inputArr) {\n // discuss at: https://locutus.io/php/array_pop/\n // original by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // input by: Brett Zamir (https://brett-zamir.me)\n // input by: Theriault (https://github.com/Theriault)\n // bugfixed by: Kevin van Zonneveld (https://kvz.io)\n // bugfixed by: Brett Zamir (https://brett-zamir.me)\n // note 1: While IE (and other browsers) support iterating an object's\n // note 1: own properties in order, if one attempts to add back properties\n // note 1: in IE, they may end up in their former position due to their position\n // note 1: being retained. So use of this function with \"associative arrays\"\n // note 1: (objects) may lead to unexpected behavior in an IE environment if\n // note 1: you add back properties with the same keys that you removed\n // example 1: array_pop([0,1,2])\n // returns 1: 2\n // example 2: var $data = {firstName: 'Kevin', surName: 'van Zonneveld'}\n // example 2: var $lastElem = array_pop($data)\n // example 2: var $result = $data\n // returns 2: {firstName: 'Kevin'}\n let key = '';\n let lastKey = '';\n if (Array.isArray(inputArr)) {\n // Indexed\n if (!inputArr.length) {\n // Done popping, are we?\n return null;\n }\n return inputArr.pop() ?? null;\n }\n else {\n // Associative\n for (key in inputArr) {\n if (inputArr.hasOwnProperty(key)) {\n lastKey = key;\n }\n }\n if (lastKey) {\n const tmp = inputArr[lastKey];\n if (tmp === undefined) {\n return null;\n }\n delete inputArr[lastKey];\n return tmp;\n }\n else {\n return null;\n }\n }\n}" const __locutus_standalone_js_code = "// php/array/array_pop (target function module)\nfunction array_pop(inputArr) {\n // discuss at: https://locutus.io/php/array_pop/\n // original by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // input by: Brett Zamir (https://brett-zamir.me)\n // input by: Theriault (https://github.com/Theriault)\n // bugfixed by: Kevin van Zonneveld (https://kvz.io)\n // bugfixed by: Brett Zamir (https://brett-zamir.me)\n // note 1: While IE (and other browsers) support iterating an object's\n // note 1: own properties in order, if one attempts to add back properties\n // note 1: in IE, they may end up in their former position due to their position\n // note 1: being retained. So use of this function with \"associative arrays\"\n // note 1: (objects) may lead to unexpected behavior in an IE environment if\n // note 1: you add back properties with the same keys that you removed\n // example 1: array_pop([0,1,2])\n // returns 1: 2\n // example 2: var $data = {firstName: 'Kevin', surName: 'van Zonneveld'}\n // example 2: var $lastElem = array_pop($data)\n // example 2: var $result = $data\n // returns 2: {firstName: 'Kevin'}\n let key = '';\n let lastKey = '';\n if (Array.isArray(inputArr)) {\n // Indexed\n if (!inputArr.length) {\n // Done popping, are we?\n return null;\n }\n return inputArr.pop() ?? null;\n }\n else {\n // Associative\n for (key in inputArr) {\n if (inputArr.hasOwnProperty(key)) {\n lastKey = key;\n }\n }\n if (lastKey) {\n const tmp = inputArr[lastKey];\n if (tmp === undefined) {\n return null;\n }\n delete inputArr[lastKey];\n return tmp;\n }\n else {\n return null;\n }\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/array/array_pop.ts (tested in test/generated/php/array/array_pop.vitest.ts)', function () { it('should pass example 1', 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 = (array_pop: typeof __locutus_source_fn) => { return array_pop([0,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) } }) it('should pass example 2', function () { const expected = {firstName: 'Kevin'} 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 = (array_pop: typeof __locutus_source_fn) => { var $data = {firstName: 'Kevin', surName: 'van Zonneveld'} var $lastElem = array_pop($data) return $data } 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) } }) })