glentities/test/glentities_test.gleam

107 lines
2.6 KiB
Gleam
Raw Permalink Normal View History

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 &amp 'string' contains 👀 many ꙮ "encoded" characters. ☃"
should.equal(
glentities.decode(input),
"This &amp 'string' contains 👀 many ꙮ \"encoded\" characters. ☃",
)
}
pub fn encode_named_test() {
let input =
"This &amp '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 &amp 'string' contains many Θ \"encoded\" characters. ☃"
should.equal(
glentities.encode(input, glentities.Hex),
"This &amp 'string' contains    many Θ "encoded" characters. ☃",
)
}
pub fn encode_html_body_test() {
let input =
"This &amp 'string' contains many Θ \"encoded\" <characters>. ☃"
should.equal(
glentities.encode(input, glentities.HTMLBody),
"This &amp;amp &#39;string&#39; contains many Θ &quot;encoded&quot; &lt;characters&gt;. ☃",
)
}
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
|> 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
|> 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
|> glentities.encode(glentities.Hex)
|> glentities.decode(),
2023-06-16 17:16:20 +00:00
input,
)
should.equal(
input
|> glentities.encode(glentities.Named)
|> glentities.decode(),
2023-06-16 17:16:20 +00:00
input,
)
should.equal(
input
|> glentities.encode(glentities.HTMLBody)
|> glentities.decode(),
2023-06-16 17:16:20 +00:00
input,
)
}