Commit c54418c3 authored by Dmitry Mozzherin's avatar Dmitry Mozzherin
Browse files

Fix #42 tests for command line app

parent 1c59bd68
Pipeline #45903661 failed with stages
in 4 minutes and 3 seconds
......@@ -3,6 +3,7 @@
## Unreleased
- Add [#44]: documentation for canonicalName fields
- Add [#42]: tests for command line app
## [v0.7.2]
- Add [#41]: parse/clean multiple names from standard input.
......@@ -56,6 +57,9 @@ This document follows [changelog guidelines]
[v0.6.0]: https://gitlab.com/gogna/gnparser/compare/v0.5.1...v0.6.0
[v0.5.1]: https://gitlab.com/gogna/gnparser/tree/v0.5.1
[#44]: https://gitlab.com/gogna/gnparser/issues/44
[#43]: https://gitlab.com/gogna/gnparser/issues/43
[#42]: https://gitlab.com/gogna/gnparser/issues/42
[#41]: https://gitlab.com/gogna/gnparser/issues/41
[#40]: https://gitlab.com/gogna/gnparser/issues/40
[#39]: https://gitlab.com/gogna/gnparser/issues/39
......
......@@ -257,7 +257,8 @@ gnparser -j 200 names.txt > names_parsed.txt
# to parse files using pipes
cat names.txt | gnparser -f simple -j 200 > names_parsed.txt
# to clean names from html tags and entities first, then parse
# to clean names from html tags and entities first (no parsing
# or other changes), then parse
cat names.txt | gnparser -c | sed "s/.*|//" | gnparser > names_parsed.txt
```
......@@ -276,7 +277,11 @@ reach maximum speed of parsing (``--jobs 200`` flag). It is practical because
additional threads are very cheap in Go and they try to fill out every idle
gap in the CPU usage.
To cleanup a name
To cleanup a name (no parsing here, it just removes HTML tags and entities,
and makes no other modifications):
The output contains the original name-string, and "HTML-normalized" one
separated by a pipe ("|") character.
```bash
gnparser -c "<i>Abacopteris glandulosa</i> (Bl.) F&eacute;e &amp; Chin"
......
package main_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestGnparser(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Gnparser Suite")
}
package main
import (
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/rendon/testcli"
)
// Run make install before these tests to get meaningful
// results.
var _ = Describe("Main", func() {
Describe("--version flag", func() {
It("returns version", func() {
c := testcli.Command("gnparser", "-v")
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).To(ContainSubstring("version:"))
})
It("ignores other flags returning version", func() {
c := testcli.Command("gnparser", "-v", "-f", "simple",
"-j", "200", "-w", "8000")
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).To(ContainSubstring("version:"))
})
})
Describe("-format flag", func() {
It("formats output", func() {
c := testcli.Command("gnparser", "Homo sapiens", "-f", "simple")
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).To(ContainSubstring("|Homo sapiens|"))
})
It("is ignored with --version", func() {
c := testcli.Command("gnparser", "Homo sapiens", "-f", "simple", "--version")
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).ToNot(ContainSubstring("|Homo sapiens|"))
Expect(c.Stdout()).To(ContainSubstring("version:"))
})
It("is set to default format if -f value is unknown",
func() {
c := testcli.Command("gnparser", "Homo sapiens", "-f", ":)")
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).
To(HavePrefix(`{"parsed":true,"quality":1,`))
})
})
Describe("Stdin", func() {
It("takes data from Stdin", func() {
c := testcli.Command("gnparser", "-f", "simple")
c.SetStdin(strings.NewReader("Homo sapiens"))
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).To(ContainSubstring("|Homo sapiens|"))
})
It("takes multiple names from Stdin", func() {
c := testcli.Command("gnparser", "-f", "simple")
c.SetStdin(strings.NewReader("Plantago\nBubo L.\n"))
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).To(ContainSubstring("|Plantago|"))
Expect(c.Stdout()).To(ContainSubstring("|Bubo|"))
})
})
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment