|
| 1 | +//go:build !js && !appengine |
1 | 2 | // +build !js,!appengine
|
2 | 3 |
|
3 | 4 | package runewidth
|
@@ -87,7 +88,56 @@ func TestRuneWidthChecksums(t *testing.T) {
|
87 | 88 | t.Errorf("TestRuneWidthChecksums = %s,\n\tsha256 = %s want %s",
|
88 | 89 | testcase.name, gotSHA, testcase.wantSHA)
|
89 | 90 | }
|
| 91 | + |
| 92 | + // Test with LUT |
| 93 | + c.CreateLUT() |
| 94 | + for r := rune(0); r <= utf8.MaxRune; r++ { |
| 95 | + buf[r] = byte(c.RuneWidth(r)) |
| 96 | + } |
| 97 | + gotSHA = fmt.Sprintf("%x", sha256.Sum256(buf)) |
| 98 | + if gotSHA != testcase.wantSHA { |
| 99 | + t.Errorf("TestRuneWidthChecksums = %s,\n\tsha256 = %s want %s", |
| 100 | + testcase.name, gotSHA, testcase.wantSHA) |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +func TestDefaultLUT(t *testing.T) { |
| 106 | + var testcases = []struct { |
| 107 | + name string |
| 108 | + eastAsianWidth bool |
| 109 | + wantSHA string |
| 110 | + }{ |
| 111 | + {"ea-no", false, "4eb632b105d3b2c800dda9141381d0b8a95250a3a5c7f1a5ca2c4d4daaa85234"}, |
| 112 | + {"ea-yes", true, "c2ddc3bdf42d81d4c23050e21eda46eb639b38b15322d35e8eb6c26f3b83ce92"}, |
| 113 | + } |
| 114 | + |
| 115 | + old := os.Getenv("RUNEWIDTH_EASTASIAN") |
| 116 | + defer os.Setenv("RUNEWIDTH_EASTASIAN", old) |
| 117 | + |
| 118 | + CreateLUT() |
| 119 | + for _, testcase := range testcases { |
| 120 | + c := DefaultCondition |
| 121 | + |
| 122 | + if testcase.eastAsianWidth { |
| 123 | + os.Setenv("RUNEWIDTH_EASTASIAN", "1") |
| 124 | + } else { |
| 125 | + os.Setenv("RUNEWIDTH_EASTASIAN", "0") |
| 126 | + } |
| 127 | + handleEnv() |
| 128 | + |
| 129 | + buf := make([]byte, utf8.MaxRune+1) |
| 130 | + for r := rune(0); r <= utf8.MaxRune; r++ { |
| 131 | + buf[r] = byte(c.RuneWidth(r)) |
| 132 | + } |
| 133 | + gotSHA := fmt.Sprintf("%x", sha256.Sum256(buf)) |
| 134 | + if gotSHA != testcase.wantSHA { |
| 135 | + t.Errorf("TestRuneWidthChecksums = %s,\n\tsha256 = %s want %s", |
| 136 | + testcase.name, gotSHA, testcase.wantSHA) |
| 137 | + } |
90 | 138 | }
|
| 139 | + // Remove for other tests. |
| 140 | + DefaultCondition.combinedLut = nil |
91 | 141 | }
|
92 | 142 |
|
93 | 143 | func checkInterval(first, last rune) bool {
|
|
0 commit comments