1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-16 10:42:27 +08:00

Compare commits

...

2 Commits

Author SHA1 Message Date
dudaodong
4888909208 fix: fix IsPingConnected failed in windows 2023-04-26 19:53:53 +08:00
dudaodong
33c8875d14 test: update TestWordCount 2023-04-26 19:35:28 +08:00
4 changed files with 19 additions and 18 deletions

View File

@@ -11,6 +11,7 @@ import (
"net/url"
"os"
"os/exec"
"runtime"
"strings"
"time"
@@ -251,7 +252,12 @@ func DownloadFile(filepath string, url string) error {
// IsPingConnected checks if can ping specified host or not.
// Play: todo
func IsPingConnected(host string) bool {
cmd := exec.Command("ping", host, "-c", "1", "-W", "6")
cmd := exec.Command("ping", host, "-c", "4", "-W", "6")
if runtime.GOOS == "windows" {
cmd = exec.Command("ping", host, "-n", "4", "-w", "6")
}
err := cmd.Run()
if err != nil {
return false

View File

@@ -121,7 +121,7 @@ func TestIsPingConnected(t *testing.T) {
assert := internal.NewAssert(t, "TestIsPingConnected")
// in github action env, this will fail
// result1 := IsPingConnected("bing.com")
// result1 := IsPingConnected("www.baidu.com")
// assert.Equal(true, result1)
result2 := IsPingConnected("www.!@#&&&.com")

View File

@@ -394,22 +394,19 @@ func ExampleSplitWords() {
result1 := SplitWords("a word")
result2 := SplitWords("I'am a programmer")
result3 := SplitWords("Bonjour, je suis programmeur")
result4 := SplitWords("a -b-c' 'd'e")
result5 := SplitWords("你好,我是一名码农")
result6 := SplitWords("こんにちは,私はプログラマーです")
result3 := SplitWords("a -b-c' 'd'e")
result4 := SplitWords("你好,我是一名码农")
result5 := SplitWords("こんにちは,私はプログラマーです")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
fmt.Println(result6)
// Output:
// [a word]
// [I'am a programmer]
// [Bonjour je suis programmeur]
// [a b-c' d'e]
// []
// []

View File

@@ -314,11 +314,10 @@ func TestSplitWords(t *testing.T) {
assert := internal.NewAssert(t, "TestSplitWords")
cases := map[string][]string{
"a word": {"a", "word"},
"I'am a programmer": {"I'am", "a", "programmer"},
"Bonjour, je suis programmeur": {"Bonjour", "je", "suis", "programmeur"},
"a -b-c' 'd'e": {"a", "b-c'", "d'e"},
"你好,我是一名码农": nil,
"a word": {"a", "word"},
"I'am a programmer": {"I'am", "a", "programmer"},
"a -b-c' 'd'e": {"a", "b-c'", "d'e"},
"你好,我是一名码农": nil,
"こんにちは,私はプログラマーです": nil,
}
@@ -331,11 +330,10 @@ func TestWordCount(t *testing.T) {
assert := internal.NewAssert(t, "TestSplitWords")
cases := map[string]int{
"a word": 2, // {"a", "word"},
"I'am a programmer": 3, // {"I'am", "a", "programmer"},
"Bonjour, je suis programmeur": 4, // {"Bonjour", "je", "suis", "programmeur"},
"a -b-c' 'd'e": 3, // {"a", "b-c'", "d'e"},
"你好,我是一名码农": 0, // nil,
"a word": 2, // {"a", "word"},
"I'am a programmer": 3, // {"I'am", "a", "programmer"},
"a -b-c' 'd'e": 3, // {"a", "b-c'", "d'e"},
"你好,我是一名码农": 0, // nil,
"こんにちは,私はプログラマーです": 0, // nil,
}