2023-06-16 17:16:20 +00:00
|
|
|
|
import gleam/string
|
2023-02-12 19:25:09 +00:00
|
|
|
|
import gleeunit
|
|
|
|
|
import gleeunit/should
|
|
|
|
|
import glentities
|
2023-04-15 17:48:41 +00:00
|
|
|
|
import glentities/internal/string_utils
|
2023-02-12 19:25:09 +00:00
|
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
|
gleeunit.main()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn decode_test() {
|
|
|
|
|
let input =
|
|
|
|
|
"This & 'string' contains 👀 many ꙮ "encoded" characters. ☃"
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
glentities.decode(input),
|
|
|
|
|
"This & 'string' contains 👀 many ꙮ \"encoded\" characters. ☃",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn encode_named_test() {
|
|
|
|
|
let input =
|
|
|
|
|
"This & 'string' contains many Θ \"encoded\" characters. ☃"
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
glentities.encode(input, glentities.Named),
|
|
|
|
|
"This &amp 'string' contains    many Θ "encoded" characters. ☃",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn encode_hex_test() {
|
|
|
|
|
let input =
|
|
|
|
|
"This & 'string' contains many Θ \"encoded\" characters. ☃"
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
glentities.encode(input, glentities.Hex),
|
|
|
|
|
"This &amp 'string' contains    many Θ "encoded" characters. ☃",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-28 14:19:30 +00:00
|
|
|
|
pub fn encode_html_body_test() {
|
|
|
|
|
let input =
|
|
|
|
|
"This & 'string' contains many Θ \"encoded\" <characters>. ☃"
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
glentities.encode(input, glentities.HTMLBody),
|
|
|
|
|
"This &amp 'string' contains many Θ "encoded" <characters>. ☃",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 19:25:09 +00:00
|
|
|
|
pub fn roundtrip_named_test() {
|
|
|
|
|
let input =
|
2023-04-15 17:48:41 +00:00
|
|
|
|
string_utils.normalise(
|
2023-02-12 19:25:09 +00:00
|
|
|
|
"Ἰοὺ ἰού· τὰ πάντʼ ἂν ἐξήκοι σαφῆ. ஸ்றீனிவாஸ ராமானுஜன் ஐயங்கார் A ∩ B = { c : c ∈ A, c ∈ B }",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
input
|
2024-05-10 09:10:22 +00:00
|
|
|
|
|> glentities.encode(glentities.Named)
|
|
|
|
|
|> glentities.decode(),
|
2023-02-12 19:25:09 +00:00
|
|
|
|
input,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn roundtrip_hex_test() {
|
|
|
|
|
let input =
|
2023-04-15 17:48:41 +00:00
|
|
|
|
string_utils.normalise(
|
2023-02-12 19:25:09 +00:00
|
|
|
|
"Ἰοὺ ἰού· τὰ πάντʼ ἂν ἐξήκοι σαφῆ. ஸ்றீனிவாஸ ராமானுஜன் ஐயங்கார் A ∩ B = { c : c ∈ A, c ∈ B }",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
input
|
2024-05-10 09:10:22 +00:00
|
|
|
|
|> glentities.encode(glentities.Hex)
|
|
|
|
|
|> glentities.decode(),
|
2023-02-12 19:25:09 +00:00
|
|
|
|
input,
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-06-16 17:16:20 +00:00
|
|
|
|
|
|
|
|
|
pub fn tco_test() {
|
|
|
|
|
let input =
|
|
|
|
|
string.repeat(
|
|
|
|
|
"I will never try to be clever in tail call recursive languages again",
|
|
|
|
|
100,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
input
|
2024-05-10 09:10:22 +00:00
|
|
|
|
|> glentities.encode(glentities.Hex)
|
|
|
|
|
|> glentities.decode(),
|
2023-06-16 17:16:20 +00:00
|
|
|
|
input,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
input
|
2024-05-10 09:10:22 +00:00
|
|
|
|
|> glentities.encode(glentities.Named)
|
|
|
|
|
|> glentities.decode(),
|
2023-06-16 17:16:20 +00:00
|
|
|
|
input,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
should.equal(
|
|
|
|
|
input
|
2024-05-10 09:10:22 +00:00
|
|
|
|
|> glentities.encode(glentities.HTMLBody)
|
|
|
|
|
|> glentities.decode(),
|
2023-06-16 17:16:20 +00:00
|
|
|
|
input,
|
|
|
|
|
)
|
|
|
|
|
}
|