1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/utils/core_tests.lua
2021-01-30 16:20:13 +00:00

25 lines
1.1 KiB
Lua

local Declare = require 'utils.test.declare'
local Assert = require 'utils.test.assert'
local Core = require 'utils.core'
local non_breaking_space = '' -- This is \u200B an invisible space charcater.
Declare.module({'utils', 'Core'}, function()
Declare.module('sanitise_string_for_discord', function()
Declare.test('escapes markdown', function()
local actual = Core.sanitise_string_for_discord('**a**_b_~c~`d`|e|>f')
Assert.equal('\\*\\*a\\*\\*\\_b\\_\\~c\\~\\`d\\`\\|e\\|\\>f', actual)
end)
-- This test is making sure backslash '\' is escaped first, else there would be a different number of backslashes.
Declare.test('escapes backslash', function()
local actual = Core.sanitise_string_for_discord('\\*abc\\*')
Assert.equal('\\\\\\*abc\\\\\\*', actual)
end)
Declare.test('escapes mention', function()
local actual = Core.sanitise_string_for_discord('@grilledham')
Assert.equal('@' .. non_breaking_space .. 'grilledham', actual)
end)
end)
end)