Skip to content

Commit

Permalink
Change test data
Browse files Browse the repository at this point in the history
  • Loading branch information
otiai10 committed Mar 8, 2018
1 parent 8dd6ca8 commit 5fe9c4f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
31 changes: 16 additions & 15 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ func TestClient_SetImage(t *testing.T) {
defer client.Close()

client.Trim = true
client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")

client.SetPageSegMode(PSM_SINGLE_BLOCK)

text, err := client.Text()
Expect(t, err).ToBe(nil)
Expect(t, text).ToBe("otiai10 / gosseract")
Expect(t, text).ToBe("Hello, World!")

}

func TestClient_SetImageFromBytes(t *testing.T) {
client := NewClient()
defer client.Close()

content, err := ioutil.ReadFile("./test/data/001-gosseract.png")
content, err := ioutil.ReadFile("./test/data/001-helloworld.png")
if err != nil {
t.Fatalf("could not read test file")
}
Expand All @@ -54,7 +54,7 @@ func TestClient_SetImageFromBytes(t *testing.T) {

text, err := client.Text()
Expect(t, err).ToBe(nil)
Expect(t, text).ToBe("otiai10 / gosseract")
Expect(t, text).ToBe("Hello, World!")
}

func TestClient_SetWhitelist(t *testing.T) {
Expand All @@ -67,19 +67,19 @@ func TestClient_SetWhitelist(t *testing.T) {
defer client.Close()

client.Trim = true
client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")
client.Languages = []string{"eng"}
client.SetWhitelist("aegitosr10/")
client.SetWhitelist("HeloWrd,")
text, err := client.Text()
Expect(t, err).ToBe(nil)
Expect(t, text).ToBe("otiai10 / gosseraet")
Expect(t, text).ToBe("Hello, Worldl")
}

func TestClient_SetLanguage(t *testing.T) {
client := NewClient()
defer client.Close()
client.SetLanguage("deu")
client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")
_, err := client.Text()
Expect(t, err).Not().ToBe(nil)
}
Expand All @@ -95,10 +95,11 @@ func TestClient_ConfigFilePath(t *testing.T) {

err := client.SetConfigFile("./test/config/01.config")
Expect(t, err).ToBe(nil)
client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")
text, err := client.Text()
Expect(t, err).ToBe(nil)
Expect(t, text).ToBe("otiai10 l gosseract")

Expect(t, text).ToBe("H W ")

When(t, "the config file is not found", func(t *testing.T) {
err := client.SetConfigFile("./test/config/not-existing")
Expand All @@ -115,8 +116,8 @@ func TestClient_ConfigFilePath(t *testing.T) {
func TestClient_HTML(t *testing.T) {
client := NewClient()
defer client.Close()
client.SetImage("./test/data/001-gosseract.png")
client.SetWhitelist("otiai10/gosseract")
client.SetImage("./test/data/001-helloworld.png")
client.SetWhitelist("Hello,World!")
out, err := client.HOCRText()
Expect(t, err).ToBe(nil)

Expand All @@ -129,21 +130,21 @@ func TestClient_HTML(t *testing.T) {
texts = append(texts, strings.Trim(token.Data, "\n"))
}
}
Expect(t, texts).ToBe([]string{"otiai10", "/", "gosseract"})
Expect(t, texts).ToBe([]string{"Hello,", "World!"})

When(t, "only invalid languages are given", func(t *testing.T) {
client := NewClient()
defer client.Close()
client.SetLanguage("foo")
client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")
_, err := client.HOCRText()
Expect(t, err).Not().ToBe(nil)
})
When(t, "undefined key-value is tried to be set", func(t *testing.T) {
client := NewClient()
defer client.Close()
client.SetVariable("foobar", "hoge")
client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")
_, err := client.HOCRText()
Expect(t, err).Not().ToBe(nil)
})
Expand Down
6 changes: 3 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func ExampleClient_SetImage() {
client := NewClient()
defer client.Close()

client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")
// See "ExampleClient_Text" for more practical usecase ;)
}

Expand All @@ -21,12 +21,12 @@ func ExampleClient_Text() {
client := NewClient()
defer client.Close()

client.SetImage("./test/data/001-gosseract.png")
client.SetImage("./test/data/001-helloworld.png")

text, err := client.Text()
fmt.Println(text, err)
// OUTPUT:
// otiai10 / gosseract <nil>
// Hello, World! <nil>

}

Expand Down
2 changes: 1 addition & 1 deletion test/config/01.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tessedit_char_whitelist otiai10 l gosseract
tessedit_char_whitelist HW
Binary file removed test/data/001-gosseract.png
Binary file not shown.
Binary file added test/data/001-helloworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5fe9c4f

Please sign in to comment.