<commit_before>"use strict";

const fengari = require("fengari");
const lua = fengari.lua;
const lauxlib = fengari.lauxlib;
const lualib = fengari.lualib;
const to_luastring = fengari.to_luastring;
const assert = require("assert");

describe("fengari-interop", function() {
	it("loads successfully", function() {
		const jslib = require("../src/jslib.js");
		assert(typeof jslib.luaopen_js === "function");
	});

	const new_state = function() {
		const jslib = require("../src/jslib.js");

		const L = fengari.lauxlib.luaL_newstate();
		lualib.luaL_openlibs(L);
		lauxlib.luaL_requiref(L, to_luastring("js"), jslib.luaopen_js, 0);
		return L;
	};

	it("can be required from lua", function() {
		const L = new_state();
		if (lauxlib.luaL_dostring(L, to_luastring('require("js")')) !== lua.LUA_OK) {
			throw lua.lua_tojsstring(L, -1);
		}
	});

	it("pushes same null every time", function() {
		const jslib = require("../src/jslib.js");
		const L = new_state();
		if (lauxlib.luaL_loadstring(L, to_luastring(`
		local null = ...
		local js = require "js"
		assert(null == js.null)
		assert(rawequal(null, js.null))
		`)) !== lua.LUA_OK) {
			throw lua.lua_tojsstring(L, -1);
		}
		jslib.push(L, null);
		if (lua.lua_pcall(L, 1, 0, 0) !== lua.LUA_OK) {
			throw jslib.tojs(L, -1);
		}
	});

	it("allows calls with no 'this' or arguments", function() {
		const jslib = require("../src/jslib.js");
		const L = new_state();
		if (lauxlib.luaL_loadstring(L, to_luastring(`
		local js = require "js"
		js.global.Date.now()
		`)) !== lua.LUA_OK) {
			throw lua.lua_tojsstring(L, -1);
		}
		if (lua.lua_pcall(L, 0, 0, 0) !== lua.LUA_OK) {
			throw jslib.tojs(L, -1);
		}
	});
});
<commit_msg>test/jslib.js: Destructured require<commit_after>"use strict";

const {
	lua,
	lauxlib,
	lualib,
	to_luastring
} = require("fengari");
const assert = require("assert");

describe("fengari-interop", function() {
	it("loads successfully", function() {
		const jslib = require("../src/jslib.js");
		assert(typeof jslib.luaopen_js === "function");
	});

	const new_state = function() {
		const jslib = require("../src/jslib.js");

		const L = lauxlib.luaL_newstate();
		lualib.luaL_openlibs(L);
		lauxlib.luaL_requiref(L, to_luastring("js"), jslib.luaopen_js, 0);
		return L;
	};

	it("can be required from lua", function() {
		const L = new_state();
		if (lauxlib.luaL_dostring(L, to_luastring('require("js")')) !== lua.LUA_OK) {
			throw lua.lua_tojsstring(L, -1);
		}
	});

	it("pushes same null every time", function() {
		const jslib = require("../src/jslib.js");
		const L = new_state();
		if (lauxlib.luaL_loadstring(L, to_luastring(`
		local null = ...
		local js = require "js"
		assert(null == js.null)
		assert(rawequal(null, js.null))
		`)) !== lua.LUA_OK) {
			throw lua.lua_tojsstring(L, -1);
		}
		jslib.push(L, null);
		if (lua.lua_pcall(L, 1, 0, 0) !== lua.LUA_OK) {
			throw jslib.tojs(L, -1);
		}
	});

	it("allows calls with no 'this' or arguments", function() {
		const jslib = require("../src/jslib.js");
		const L = new_state();
		if (lauxlib.luaL_loadstring(L, to_luastring(`
		local js = require "js"
		js.global.Date.now()
		`)) !== lua.LUA_OK) {
			throw lua.lua_tojsstring(L, -1);
		}
		if (lua.lua_pcall(L, 0, 0, 0) !== lua.LUA_OK) {
			throw jslib.tojs(L, -1);
		}
	});
});

{'fraction_non_alphanumeric': 0.19220225403594274, 'fraction_numerical': 0.007310386841303686, 'mean_word_length': 3.8508124076809453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '565710', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1370, 'n_words': 269}