import gleeunit/should import string_width fn sw(str: String) { let options = string_width.new() |> string_width.mode_2027_ext string_width.line_with(str, options) } @target(erlang) pub fn despair1_test() { // 2 grapheme clusters in Unicode 15 sw("র্য") |> should.equal(2) } @target(javascript) pub fn despair1_test() { // 1 grapheme cluster in unicode 15.1 // We return 2 because of our custom extension. sw("র্য") |> should.equal(2) } @target(erlang) pub fn despair2_test() { // 2 grapheme clusters in Unicde 15. // NOTE: this string is different from the one above in that it includes // an additional ZWJ between the letters! sw("র‍্য") |> should.equal(2) } @target(javascript) pub fn despair2_test() { // 1 grapheme cluster in Unicde 15.1 // NOTE: this string is different from the one above in that it includes // an additional ZWJ between the letters! // // VSCode treats it as 2 separate characters though, and everyone renders it wide. // // We return 2 because of our custom extension. sw("র‍্য") |> should.equal(2) } @target(erlang) pub fn despair3_test() { // 5 grapheme clusters un Unicode 15 // in particular, "च्छे" is split into 2 clusters sw("अनुच्छेद") |> should.equal(5) } @target(javascript) pub fn despair3_test() { // 4 grapheme clusters un Unicode 15.1 // in particular, "च्छे" is a single grapheme cluster, but every terminal and editor // I ever tried renders it as a wide character, even though there is nothing // in the database that I know of that would tell it to. // // We return 5 instead of 4 because of our custom extension. sw("अनुच्छेद") |> should.equal(5) } @target(erlang) pub fn despair4_test() { // 2 grapheme clusters in Unicode 15 sw("क्षि") |> should.equal(2) } @target(javascript) pub fn despair4_test() { // 1 grapheme cluster in Unicode 15.1 // We return 2 because of our custom extension. sw("क्षि") |> should.equal(2) } pub fn despair5_test() { // this is always segmented into a single grapheme cluster, but most apps // still render it wide. // Our "2 codepoints with width force it wide rule" makes it wide, but other // implementations disagree. sw("バ") |> should.equal(2) }