Skip to content

Commit

Permalink
attempt to resolve bug
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Mar 20, 2023
1 parent 18ef509 commit bf6ef47
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
59 changes: 59 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

if [ -t 1 ]
then
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
fi

yellow() { printf "${YELLOW}%s${NC}" "$*"; }
green() { printf "${GREEN}%s${NC}" "$*"; }
red() { printf "${RED}%s${NC}" "$*"; }

good() {
echo "$(green "● success:")" "$@"
}

bad() {
ret=$1
shift
echo "$(red "● failed:")" "$@"
exit $ret
}

try() {
"$@" || bad $? "$@" && good "$@"
}


echo "Running go fmt..."
gofmt -s -w ./..

echo "Running unit tests..."
go test -cover -race ./... || exit

{
{
opt='shopt -s extglob nullglob'
gofmt='gofmt -s -w -l !(vendor)/ *.go'
notice=" running: ( $opt; $gofmt; )"
prefix=" $(yellow modified)"
trap 'echo "$notice"; $opt; $gofmt | sed -e "s#^#$prefix #g"' EXIT
}

# comma separate linters (e.g. "gofmt,stylecheck")
additional_linters="gofmt"
try golangci-lint run --enable $additional_linters ./...
trap '' EXIT
}

echo "Running fuzz test..."
go test -fuzz=FuzzIndexAllIgnoreCase -fuzztime 30s

echo -e "${GREEN}================================================="
echo -e "ALL CHECKS PASSED"
echo -e "=================================================${NC}"
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func RemoveStringDuplicates(elements []string) []string {
var result []string

for v := range elements {
if !encountered[elements[v]] == true {
if !encountered[elements[v]] {
encountered[elements[v]] = true
result = append(result, elements[v])
}
Expand Down
9 changes: 8 additions & 1 deletion index.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,15 @@ func IndexAllIgnoreCase(haystack string, needle string, limit int) [][]int {
}

// Cut off the number at the end to the number we need which is the length of the needle runes
toMatch := []rune(haystack[match[0] : match[0]+e])[:len(needleRune)]
var toMatch []rune
if match[0]+e > len(haystack) {
toMatch = []rune(haystack[match[0] : len(haystack)-1])[:len(needleRune)]
} else {
toMatch = []rune(haystack[match[0] : match[0]+e])[:len(needleRune)]
}

// old logic here
//toMatch = []rune(haystack[match[0] : match[0]+e])[:len(needleRune)]

// what we need to do is iterate the runes of the haystack portion we are trying to
// match and confirm that the same rune position is a actual match or case fold match
Expand Down
3 changes: 1 addition & 2 deletions index_bug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ print(i)#这里输出的结果虽然与print(str3)相同,但是性质是不同
print('转换成二进制:',bin(i),'转换成八进制:',oct(i), '转换成十六进制:',hex(i))
#二进制、八进制、十六进制这几个进制相互转换的时候,都要先转换为十进制int()`


func TestIndexAllUnicodeOffset(t *testing.T) {
lines := strings.Split(strings.Replace(broken, "\r\n", "\n", -1), "\n")

// this has an exception
for _, l := range lines {
IndexAllIgnoreCase(l, "list1=[0,1,2,3,4,5,6,7,8,9]#制作一个0", -1)
}
}
}

0 comments on commit bf6ef47

Please sign in to comment.