Files
breeze/tests/lumi_message_text_behavior.zi

53 lines
2.4 KiB
Ziran

#import, file "../apps/lumi/message_text.zi";
#import "byte_text_linux"
#program_export
Answer :: () -> s32 {
value := LumiFormatMessage("Try **breathing slowly** and __rest__.", true)
if TextFromBytes(value.bytes[:value.count]) != "Try breathing slowly and rest." ||
value.strong_count != 2 || value.strong[0].start != 4 || value.strong[0].end != 20 ||
value.strong[1].start != 25 || value.strong[1].end != 29 {
return 1
}
value = LumiFormatMessage("**水を飲む**\n**té**", true)
if TextFromBytes(value.bytes[:value.count]) != "水を飲む\nté" || value.strong_count != 2 ||
value.strong[0].end != 12 || value.strong[1].start != 13 || value.strong[1].end != 16 {
return 2
}
value = LumiFormatMessage("unclosed **bold, ***literal***, ** spaces **", true)
if TextFromBytes(value.bytes[:value.count]) != "unclosed **bold, ***literal***, ** spaces **" || value.strong_count != 0 {
return 3
}
value = LumiFormatMessage("`**code**` and \\**literal**", true)
if TextFromBytes(value.bytes[:value.count]) != "`**code**` and **literal**" || value.strong_count != 0 {
return 4
}
value = LumiFormatMessage("**user input**", false)
if TextFromBytes(value.bytes[:value.count]) != "**user input**" || value.strong_count != 0 {
return 5
}
// Web links open from the words, without the punctuation that ends the
// sentence around them.
notes := "Read the notes at https://github.com/waozixyz/breeze/blob/master/CHANGELOG.md."
links := LumiMessageLinks(notes)
if links.count != 1 || notes[links.items[0].start:links.items[0].end] !=
"https://github.com/waozixyz/breeze/blob/master/CHANGELOG.md" {
return 6
}
several := "(see http://a.example/x), https://b.example and https://c.example/?q=1 or https://d.example"
links = LumiMessageLinks(several)
if links.count != 4 || several[links.items[0].start:links.items[0].end] != "http://a.example/x" ||
several[links.items[2].start:links.items[2].end] != "https://c.example/?q=1" ||
several[links.items[3].start:links.items[3].end] != "https://d.example" {
return 7
}
if LumiMessageLinks("nohttps://x.example https:// ftp://y.example").count != 0 {
return 8
}
if !LumiLinkValid("https://waozi.xyz/inbe") || LumiLinkValid("https://waozi.xyz two") ||
LumiLinkValid("javascript:alert(1)") || LumiLinkValid("see https://waozi.xyz") {
return 9
}
return 42
}