Skip to content

Commit

Permalink
dict: change KeepWordsPattern and add test cases
Browse files Browse the repository at this point in the history
Changed KeepWordsPattern and add golang test cases. We also fixed t0031
and t0036 test suites and fixed smudge table for vi.

Signed-off-by: Jiang Xin <[email protected]>
  • Loading branch information
jiangxin committed Feb 13, 2024
1 parent 254081f commit d872873
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dict/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var KeepWordsPattern = regexp.MustCompile(`(` +
`|` +
`\b[a-z-]+--[a-z-]+` + // match helper commands: bisect--helper, ...
`|` +
`--[a-zA-Z0-9-=]+` + // match git options: --option, --option=value, ...
// match git options: --option, --option=param1,param2 ..., --[no-]signed
`--(\[[a-z-]+\])?[a-zA-Z0-9-]+(=[a-zA-Z0-9,<\.>*]+)?` +
`|` +
`%%\(.*?\)` + // match %(fieldname) in format argument of git-for-each-ref, ...
`|` +
Expand Down
107 changes: 107 additions & 0 deletions dict/global_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dict

import (
"sort"
"testing"
)

type keepWordsTest struct {
Input string
Matches []string
}

var keepWordsTests = []keepWordsTest{
{
Input: "Cannot $action: You have unstaged changes.",
Matches: []string{"$action"},
},
{
Input: "usage: $dashless $USAGE",
Matches: []string{"$USAGE", "$dashless"},
},
{
Input: "fetch normally indicates which branches had a forced update,\n" +
"but that check has been disabled; to re-enable, use '--show-forced-updates'\n" +
"flag or run 'git config fetch.showForcedUpdates true'",
Matches: []string{"--show-forced-updates", "fetch.showForcedUpdates"},
},
{
Input: "unable to create lazy_name thread: %s",
Matches: []string{"lazy_name"},
},
{
Input: "do not run git-update-server-info",
Matches: []string{"git-update-server-info"},
},
{
Input: "git cat-file (-t | -s) [--allow-unknown-type] <object>",
Matches: []string{"--allow-unknown-type", "git cat-file"},
},
{
Input: "also apply the patch (use with --stat/--summary/--check)",
Matches: []string{"--check", "--stat", "--summary"},
},
{
Input: "--negotiate-only needs one or more --negotiation-tip=*",
Matches: []string{"--negotiate-only", "--negotiation-tip=*"},
},
{
Input: "git maintenance run [--auto] [--[no-]quiet] [--task=<task>] [--schedule]",
Matches: []string{"--[no-]quiet", "--auto", "--schedule", "--task=<task>"},
},
{
Input: "synonym for --dirstat=files,param1,param2...",
Matches: []string{"--dirstat=files,param1,param2..."},
},
{
Input: "synonym for --dirstat=files,<...>,<...>...",
Matches: []string{"--dirstat=files,<...>,<...>..."},
},
{
Input: "expected format: %%(color:<color>)",
Matches: []string{"%%(color:<color>)"},
},
{
Input: "expected format: %%(align:<width>,<position>)",
Matches: []string{"%%(align:<width>,<position>)"},
},
{
Input: "starting with \"refs/\".",
Matches: []string{"refs/"},
},
{
Input: "delete refs/remotes/<name>/HEAD",
Matches: []string{"refs/remotes/<name>/HEAD"},
},
{
Input: "is a ref in \"refs/{heads,tags}/\"",
Matches: []string{"refs/{heads,tags}/"},
},
}

func TestKeepWordsPattern(t *testing.T) {
for _, tc := range keepWordsTests {
m := KeepWordsPattern.FindAllStringSubmatch(tc.Input, -1)
matches := []string{}
for i := range m {
matches = append(matches, m[i][0])
}
sort.Strings(matches)
if len(tc.Matches) != len(matches) {
t.Errorf("Failed to match: different length: %d != %d, expect: %v, actual: %v",
len(tc.Matches),
len(matches),
tc.Matches,
matches)
} else {
for i := range tc.Matches {
if tc.Matches[i] != matches[i] {
t.Errorf("Failed to match. expect: %v, actual: %v",
tc.Matches,
matches)
break
}
}
}
}
}
4 changes: 4 additions & 0 deletions dict/smudge-vi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ func init() {
Pattern: "bạn@ví_dụ.com",
Replace: "[email protected]",
},
{
Pattern: "…",
Replace: "...",
},
}
}
2 changes: 1 addition & 1 deletion test/t0031-check-typos-in-po.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ test_expect_success "check typos of mismatched options" '
level=warning msg="[po/zh_CN.po] >> msgid: --reject and --3way cannot be used together."
level=warning msg="[po/zh_CN.po] >> msgstr: --reject 和 -3way 不能同时使用。"
level=warning msg="[po/zh_CN.po]"
level=warning msg="[po/zh_CN.po] mismatched patterns: --word-diff-regex="
level=warning msg="[po/zh_CN.po] mismatched patterns: --word-diff-regex, --word-diff-regex=<...>"
level=warning msg="[po/zh_CN.po] >> msgid: equivalent to --word-diff=color --word-diff-regex=<regex>"
level=warning msg="[po/zh_CN.po] >> msgstr: 相当于 --word-diff=color --word-diff-regex=正则"
level=warning msg="[po/zh_CN.po]"
Expand Down
2 changes: 1 addition & 1 deletion test/t0036-typos-in-sv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ level=warning msg="[po/sv.po] mismatched patterns: --branch, --brand"
level=warning msg="[po/sv.po] >> msgid: git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>"
level=warning msg="[po/sv.po] >> msgstr: git submodule--helper set-branch [-q|--quiet] (-b|--brand) <gren> <sökväg>"
level=warning msg="[po/sv.po]"
level=warning msg="[po/sv.po] mismatched patterns: --format="
level=warning msg="[po/sv.po] mismatched patterns: --format=<...>..."
level=warning msg="[po/sv.po] >> msgid: git verify-tag [-v | --verbose] [--format=<format>] <tag>..."
level=warning msg="[po/sv.po] >> msgstr: git verify-tag [-v | --verbose] [--format=<format] <tagg>..."
level=warning msg="[po/sv.po]"
Expand Down

0 comments on commit d872873

Please sign in to comment.