spec/util_strbitop.lua
author Kim Alvefur <zash@zash.se>
Fri, 27 May 2022 14:45:35 +0200
branch0.12
changeset 12530 252ed01896dd
parent 11172 cde600e2fdf9
permissions -rw-r--r--
mod_smacks: Bounce unhandled stanzas from local origin (fix #1759) Sending stanzas with a remote session as origin when the stanzas have a local JID in the from attribute trips validation in core.stanza_router, leading to warnings: > Received a stanza claiming to be from remote.example, over a stream authed for localhost.example Using module:send() uses the local host as origin, which is fine here.

local strbitop = require "util.strbitop";
describe("util.strbitop", function ()
	describe("sand()", function ()
		it("works", function ()
			assert.equal(string.rep("Aa", 100), strbitop.sand(string.rep("a", 200), "Aa"));
		end);
		it("returns empty string if first argument is empty", function ()
			assert.equal("", strbitop.sand("", ""));
			assert.equal("", strbitop.sand("", "key"));
		end);
		it("returns initial string if key is empty", function ()
			assert.equal("hello", strbitop.sand("hello", ""));
		end);
	end);

	describe("sor()", function ()
		it("works", function ()
			assert.equal(string.rep("a", 200), strbitop.sor(string.rep("Aa", 100), "a"));
		end);
		it("returns empty string if first argument is empty", function ()
			assert.equal("", strbitop.sor("", ""));
			assert.equal("", strbitop.sor("", "key"));
		end);
		it("returns initial string if key is empty", function ()
			assert.equal("hello", strbitop.sor("hello", ""));
		end);
	end);

	describe("sxor()", function ()
		it("works", function ()
			assert.equal(string.rep("Aa", 100), strbitop.sxor(string.rep("a", 200), " \0"));
		end);
		it("returns empty string if first argument is empty", function ()
			assert.equal("", strbitop.sxor("", ""));
			assert.equal("", strbitop.sxor("", "key"));
		end);
		it("returns initial string if key is empty", function ()
			assert.equal("hello", strbitop.sxor("hello", ""));
		end);
	end);
end);