Files
kryon/tests/mini_embed_behavior.zi
T

76 lines
2.5 KiB
Ziran

#import "mini_embed"
SameText :: (bytes: []u8, length: s64, expected: string) -> bool {
if length != expected.count {
return false
}
index: s64 = 0
while index < length {
if bytes[index] != expected[index] {
return false
}
index += 1
}
return bytes[length] == cast(u8)0
}
FullAppUrlIs :: (href: string, expected: string) -> bool {
output: [256]u8
length := MiniModeFullAppUrl(href, output[:])
return SameText(output[:], length, expected)
}
#program_export
Answer :: () -> s32 {
arguments: [3]string
arguments[0] = "inbe"
arguments[1] = "--break-now"
arguments[2] = "--mini"
if !MiniModeArgument(arguments[:]) { return 1 }
if MiniModeArgument(arguments[0:2]) { return 2 }
// The program name is not an option.
arguments[0] = "--mini"
if MiniModeArgument(arguments[0:1]) { return 3 }
if !MiniModeQuery("?mini") { return 4 }
if !MiniModeQuery("?mini=1") { return 5 }
if !MiniModeQuery("?lang=de&mini") { return 6 }
if !MiniModeQuery("mini") { return 7 }
if MiniModeQuery("") { return 8 }
if MiniModeQuery("?") { return 9 }
if MiniModeQuery("?minimal") { return 10 }
if MiniModeQuery("?theme=mini") { return 11 }
if MiniModeQuery("?xmini") { return 12 }
if !FullAppUrlIs("https://inbe.waozi.xyz/app/?mini#/start",
"https://inbe.waozi.xyz/app/#/start") { return 13 }
if !FullAppUrlIs("https://a.b/?lang=de&mini=1&theme=2#/session",
"https://a.b/?lang=de&theme=2#/session") { return 14 }
if !FullAppUrlIs("https://a.b/?mini&lang=de", "https://a.b/?lang=de") {
return 15
}
if !FullAppUrlIs("https://a.b/", "https://a.b/") { return 16 }
// A '?' inside the hash belongs to the hash.
if !FullAppUrlIs("https://a.b/#/start?mini", "https://a.b/#/start?mini") {
return 17
}
if !FullAppUrlIs("https://a.b/?&mini&&x#h", "https://a.b/?x#h") {
return 18
}
small: [8]u8
if MiniModeFullAppUrl("https://a.b/?mini", small[:]) != -1 { return 19 }
if !MiniModeThemeQuery("?mini&theme=waozi") { return 20 }
if !MiniModeThemeQuery("?theme=waozi&mini=1") { return 21 }
if MiniModeThemeQuery("?theme=waozi") ||
MiniModeThemeQuery("?mini&theme=waozix") ||
MiniModeThemeQuery("?mini&x-theme=waozi") {
return 22
}
if !FullAppUrlIs("https://a.b/?mini&theme=waozi&lang=de#/start",
"https://a.b/?lang=de#/start") {
return 23
}
return 42
}