Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jul 30, 2016
1 parent 231e883 commit d36e81e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
language: go
go:
- 1.6
script:
- go get -t
- go test -v
9 changes: 4 additions & 5 deletions res_nobindata.go
Expand Up @@ -6,17 +6,16 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
)

func init() {
selfDir := filepath.Dir(os.Args[0])
resDir := filepath.Join(selfDir, "./res")
//selfDir := filepath.Dir(os.Args[0])
//resDir := filepath.Join(selfDir, "./res")
resDir := "./res"
http.Handle("/-/res/", http.StripPrefix("/-/res/", http.FileServer(http.Dir(resDir))))

for name, path := range templates {
content, err := ioutil.ReadFile(filepath.Join(selfDir, path))
content, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
Expand Down
26 changes: 26 additions & 0 deletions utils.go
Expand Up @@ -31,3 +31,29 @@ func getRealIP(req *http.Request) string {
}
return xip
}

func SublimeContains(s, substr string) bool {
rs, rsubstr := []rune(s), []rune(substr)
if len(rsubstr) > len(rs) {
return false
}
// abcdefg
// df
var ok = true
var i, j = 0, 0
for ; i < len(rsubstr); i++ {
found := -1
for ; j < len(rs); j++ {
if rsubstr[i] == rs[j] {
found = j
break
}
}
if found == -1 {
ok = false
break
}
j += 1
}
return ok
}
27 changes: 27 additions & 0 deletions utils_test.go
@@ -0,0 +1,27 @@
package main

import "testing"

func TestSublimeContains(t *testing.T) {
tests := []struct {
text string
substr string
pass bool
}{
{"hello", "lo", true},
{"abcdefg", "cf", true},
{"abcdefg", "a", true},
{"abcdefg", "b", true},
{"abcdefg", "cfa", false},
{"abcdefg", "aa", false},
{"世界", "a", false},
{"Hello 世界", "界", true},
{"Hello 世界", "elo", true},
}
for _, v := range tests {
res := SublimeContains(v.text, v.substr)
if res != v.pass {
t.Fatalf("Failed: %v - res:%v", v, res)
}
}
}
2 changes: 1 addition & 1 deletion zip_test.go
Expand Up @@ -7,7 +7,7 @@ import (

func TestExtractFromZip(t *testing.T) {
buf := bytes.NewBuffer(nil)
err := ExtractFromZip("testdata/test.zip", "*/foo.txt", buf)
err := ExtractFromZip("testdata/test.zip", "**/foo.txt", buf)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit d36e81e

Please sign in to comment.