Skip to content

Commit 1e189a0

Browse files
committed
Add example test
1 parent bbc42f1 commit 1e189a0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

example_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package chardet
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
var (
8+
zh_gb18030_text = []byte{
9+
71, 111, 202, 199, 71, 111, 111, 103, 108, 101, 233, 95, 176, 108, 181, 196, 210, 187, 214, 214, 190, 142, 215, 103, 208, 205, 163, 172, 129, 75, 176, 108,
10+
208, 205, 163, 172, 178, 162, 190, 223, 211, 208, 192, 172, 187, 248, 187, 216, 202, 213, 185, 166, 196, 220, 181, 196, 177, 224, 179, 204, 211, 239, 209, 212,
11+
161, 163, 10,
12+
}
13+
)
14+
15+
func ExampleTextDetector() {
16+
detector := NewTextDetector()
17+
result, err := detector.DetectBest(zh_gb18030_text)
18+
if err == nil {
19+
fmt.Printf(
20+
"Detected charset is %s, language is %s",
21+
result.Charset,
22+
result.Language)
23+
}
24+
// Output:
25+
// Detected charset is GB-18030, language is zh
26+
}

0 commit comments

Comments
 (0)