# test unicode support functions

if (!IsLower("a") || !IsLower("ā") || IsLower("A") || IsLower("Ā"))
  Error("IsLower was wrong")
endif

if (!IsUpper("A") || !IsUpper("Ā") || IsUpper("a") || IsUpper("ā"))
  Error("IsUpper was wrong")
endif

if (ToLower("A") != "a" || ToLower("Ā") != "ā" || ToLower("a") != "a" || ToLower("ā") != "ā")
  Error("ToLower was wrong")
endif

if (ToUpper("a") != "A" || ToUpper("ā") != "Ā" || ToUpper("A") != "A" || ToUpper("Ā") != "Ā")
  Error("ToUpper was wrong")
endif

if (ToMirror("(") != ")" || ToMirror(")") != "(" || ToMirror("｟") != "｠")
  Error("ToMirror was wrong")
endif

if (!IsAlNum("A") || !IsAlNum("a") || !IsAlNum("Ā") || !IsAlNum("ā") || !IsAlNum("1") || IsAlNum("$") || IsAlNum(" "))
  Error("IsAlNum was wrong")
endif

if (!IsAlpha("A") || !IsAlpha("a") || !IsAlpha("Ā") || !IsAlpha("ā") || IsAlpha("1") || IsAlpha("$") || IsAlNum(" "))
  Error("IsAlpha was wrong")
endif

if (!IsDigit("0") || !IsDigit("1") || IsDigit("a") || IsDigit("A"))
  Error("IsDigit was wrong")
endif

if (!IsHexDigit("a") || !IsHexDigit("A") || !IsHexDigit("F") || !IsHexDigit("f") || !IsHexDigit("0") || !IsHexDigit("9") || IsHexDigit("G"))
  Error("IsHexDigit was wrong")
endif

ver = UnicodeNamesListVersion()
Print("nameslist version is: ",ver)
if (Strlen(ver) <= 0)
  Error("Bad nameslist version")
endif

if (UnicodeNameFromLib(0x1FBA9) != "BOX DRAWINGS LIGHT DIAGONAL UPPER CENTRE TO MIDDLE RIGHT AND MIDDLE LEFT TO LOWER CENTRE")
  Error("Unexpected name for U+1FBA9")
endif

annot = UnicodeAnnotationFromLib(0x27)
ind = Strstr(annot, "= apostrophe-quote (1.0)")
if (ind < 0)
  Error("Unexpected annotation for U+0027")
endif
if (Strlen(annot) < 480)
  Error("Unexpected annotation length for U+0027")
endif
Print("Strlen for U+0027:", Strlen(annot))
Print("Annotation for U+0027:\n", annot)

cnt = UnicodeBlockCountFromLib()
if (cnt <= 0)
  Error("Unexpected unicode block count")
endif

i = 0
while ( i<cnt )
  start = UnicodeBlockStartFromLib(i)
  end = UnicodeBlockEndFromLib(i)
  name = UnicodeBlockNameFromLib(i)

  if (start < 0 || start > end)
    Error("Bad unicode block at index ", i)
  endif

  if (Strlen(name) <= 0)
    Error("Bad unicode block name at index", i)
  endif
  ++i;
endloop

s1 = UnicodeNames2FromLib(65)
s2 = UnicodeNames2FromLib(0x709)
Print("There should be no Names2 for character 65, the value returned is=",s1)
Print("There should be a Names2 for character 0x709, the value returned is=",s2)
if ( Strlen(s1)>0 || Strlen(s2)<3 )
  Error("Expected to return a valid Names2 string.")
endif

Print("All Tests done and valid.")

