tartrazine/utils_test.go

59 lines
1.5 KiB
Go
Raw Normal View History

2016-07-13 17:05:09 +00:00
package slinguist
import (
"bytes"
. "gopkg.in/check.v1"
)
2016-07-13 20:21:18 +00:00
func (s *TSuite) TestIsVendor(c *C) {
2016-07-13 17:05:09 +00:00
c.Assert(IsVendor("foo/bar"), Equals, false)
c.Assert(IsVendor("foo/vendor/foo"), Equals, true)
2017-04-06 16:04:47 +00:00
c.Assert(IsVendor(".sublime-project"), Equals, true)
c.Assert(IsVendor("leaflet.draw-src.js"), Equals, true)
c.Assert(IsVendor("foo/bar/MochiKit.js"), Equals, true)
c.Assert(IsVendor("foo/bar/dojo.js"), Equals, true)
c.Assert(IsVendor("foo/env/whatever"), Equals, true)
c.Assert(IsVendor("foo/.imageset/bar"), Equals, true)
c.Assert(IsVendor("Vagrantfile"), Equals, true)
2016-07-13 17:05:09 +00:00
}
2016-07-13 20:21:18 +00:00
func (s *TSuite) TestIsDocumentation(c *C) {
2016-07-13 17:05:09 +00:00
c.Assert(IsDocumentation("foo"), Equals, false)
c.Assert(IsDocumentation("README"), Equals, true)
}
2016-07-13 20:21:18 +00:00
func (s *TSuite) TestIsConfiguration(c *C) {
2016-07-13 17:05:09 +00:00
c.Assert(IsConfiguration("foo"), Equals, false)
c.Assert(IsConfiguration("foo.ini"), Equals, true)
c.Assert(IsConfiguration("foo.json"), Equals, true)
}
2016-07-13 20:21:18 +00:00
func (s *TSuite) TestIsBinary(c *C) {
2016-07-13 17:05:09 +00:00
c.Assert(IsBinary([]byte("foo")), Equals, false)
binary := []byte{0}
c.Assert(IsBinary(binary), Equals, true)
binary = bytes.Repeat([]byte{'o'}, 8000)
binary = append(binary, byte(0))
c.Assert(IsBinary(binary), Equals, false)
}
const (
htmlPath = "some/random/dir/file.html"
jsPath = "some/random/dir/file.js"
)
2016-07-13 20:21:18 +00:00
func (s *TSuite) BenchmarkVendor(c *C) {
2016-07-13 17:05:09 +00:00
for i := 0; i < c.N; i++ {
_ = IsVendor(htmlPath)
}
}
2016-07-13 20:21:18 +00:00
func (s *TSuite) BenchmarkVendorJS(c *C) {
2016-07-13 17:05:09 +00:00
for i := 0; i < c.N; i++ {
_ = IsVendor(jsPath)
}
}