github.com/puellanivis/breton@v0.2.16/lib/display/width/width_test.go (about)

     1  package width
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestZeroWidth(t *testing.T) {
     8  	if l := Rune('\n'); l != -1 {
     9  		t.Error("Expected that Cc characters are width == -1, but width of NEWLINE gave instead ", l)
    10  	}
    11  
    12  	if l := Rune('\u200B'); l != 0 {
    13  		t.Error("Expected that Cf characters are width == 0, but width of ZERO WIDTH SPACE gave instead ", l)
    14  	}
    15  
    16  	if l := Rune('\u0304'); l != 0 {
    17  		t.Error("Expected that Mn characters are width == 0, but width of COMBINING MACRON gave instead ", l)
    18  
    19  	}
    20  
    21  	if l := Rune('\x00'); l != 0 {
    22  		t.Error("Expected that NUL is width == 0, but gave instead ", l)
    23  	}
    24  }
    25  
    26  func TestSingleWidth(t *testing.T) {
    27  	if l := Rune('a'); l != 1 {
    28  		t.Error("Expected that standard ASCII characters are width == 1, but width of 'a' gave instead ", l)
    29  	}
    30  
    31  	if l := Rune('á'); l != 1 {
    32  		t.Error("Expected that extended ASCII characters are width == 1, but width of 'á' gave instead ", l)
    33  	}
    34  
    35  	if l := Rune('\u27E6'); l != 1 {
    36  		t.Error("Expected that East_Asian_Narrow characters are width == 1, but width of MATHEMATICAL LEFT WHITE SQUARE BRACKET gave instead ", l)
    37  	}
    38  
    39  	if l := Rune('\u20A9'); l != 1 {
    40  		t.Error("Expected that East_Asian_Halfwidth characters are width == 1, but width of WON SIGN gave instead ", l)
    41  	}
    42  
    43  	if l := Rune('\u0298'); l != 1 {
    44  		t.Error("Expected that East_Asian_Neutral characters are width == 1, but width of LATIN LETTER BILABIAL CLICK  gave instead ", l)
    45  	}
    46  
    47  	if l := Rune('\u00AD'); l != 1 {
    48  		t.Error("Expected that SOFT HYPHEN is width == 1, but gave instead ", l)
    49  	}
    50  }
    51  
    52  func TestDoubleWidth(t *testing.T) {
    53  	if l := Rune('\uFF01'); l != 2 {
    54  		t.Error("Expected that East_Asian_Fullwidth characters are width == 2, but width of FULLWIDTH EXCLAMATION MARK gave instead ", l)
    55  	}
    56  
    57  	if l := Rune('\u30A2'); l != 2 {
    58  		t.Error("Expected that East_Asian_Wide characters are width == 2, but width of KATAKANA LETTER A gave instead ", l)
    59  	}
    60  }
    61  
    62  func TestAmbiguousWidth(t *testing.T) {
    63  	if l := Rune('\u0398'); l != 1 {
    64  		t.Error("Expected that GREEK CAPITAL LETTER THETA should default width == 1, but gave instead ", l)
    65  	}
    66  
    67  	AmbiguousIsWide = true
    68  
    69  	if l := Rune('\u2227'); l != 2 {
    70  		t.Error("Expected that East_Asian_Ambiguous characters are width == 2 when AmibiguousIsWidth == true, but width of LOGICAL AND gave instead ", l)
    71  	}
    72  
    73  	AmbiguousIsWide = false
    74  
    75  	if l := Rune('\u2227'); l != 1 {
    76  		t.Error("Expected that East_Asian_Ambiguous characters are width == 1 when AmibiguousIsWidth == false, but width of LOGICAL OR gave instead ", l)
    77  	}
    78  }
    79  
    80  func TestString(t *testing.T) {
    81  	testString := "þ\u0300á\u0398"
    82  
    83  	if l := String(testString); l != 3 {
    84  		t.Error("Test string had wrong length, expected 3, got ", l)
    85  	}
    86  
    87  	if l := String(testString + "\b"); l != -1 {
    88  		t.Error("Test string with control code should return width -1, got ", l)
    89  	}
    90  }