github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/stdlib/utf8/testdata/codepoint.lua (about)

     1  assert(utf8.codepoint("あい") == 12354)
     2  assert(utf8.codepoint("あい", 1) == 12354)
     3  assert(utf8.codepoint("あい", -3) == 12356)
     4  a, i = utf8.codepoint("あい", 1, 4); assert(a == 12354 and i == 12356)
     5  a, i = utf8.codepoint("あい", 1, -1); assert(a == 12354 and i == 12356)
     6  
     7  ok, err = pcall(utf8.codepoint, "あい", 2)
     8  assert(not ok)
     9  assert(err == "invalid UTF-8 code")
    10  assert(not pcall(utf8.codepoint, "あい", 0))
    11  
    12  assert(utf8.codepoint("", 1, -1) == nil)