diff --git a/dict/global.go b/dict/global.go index f223ae4..c1589d0 100644 --- a/dict/global.go +++ b/dict/global.go @@ -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, ... `|` + diff --git a/dict/global_test.go b/dict/global_test.go new file mode 100644 index 0000000..23b07fa --- /dev/null +++ b/dict/global_test.go @@ -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] ", + 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=] [--schedule]", + Matches: []string{"--[no-]quiet", "--auto", "--schedule", "--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:)", + Matches: []string{"%%(color:)"}, + }, + { + Input: "expected format: %%(align:,)", + Matches: []string{"%%(align:,)"}, + }, + { + Input: "starting with \"refs/\".", + Matches: []string{"refs/"}, + }, + { + Input: "delete refs/remotes//HEAD", + Matches: []string{"refs/remotes//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 + } + } + } + } +} diff --git a/dict/smudge-vi.go b/dict/smudge-vi.go index 5796db9..2443799 100644 --- a/dict/smudge-vi.go +++ b/dict/smudge-vi.go @@ -14,5 +14,9 @@ func init() { Pattern: "bạn@ví_dụ.com", Replace: "you@example.com", }, + { + Pattern: "…", + Replace: "...", + }, } } diff --git a/test/t0031-check-typos-in-po.sh b/test/t0031-check-typos-in-po.sh index b02d0b9..3da6173 100755 --- a/test/t0031-check-typos-in-po.sh +++ b/test/t0031-check-typos-in-po.sh @@ -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=" level=warning msg="[po/zh_CN.po] >> msgstr: 相当于 --word-diff=color --word-diff-regex=正则" level=warning msg="[po/zh_CN.po]" diff --git a/test/t0036-typos-in-sv.sh b/test/t0036-typos-in-sv.sh index a5fbcfd..0d07981 100755 --- a/test/t0036-typos-in-sv.sh +++ b/test/t0036-typos-in-sv.sh @@ -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) " level=warning msg="[po/sv.po] >> msgstr: git submodule--helper set-branch [-q|--quiet] (-b|--brand) " 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=] ..." level=warning msg="[po/sv.po] >> msgstr: git verify-tag [-v | --verbose] [--format=..." level=warning msg="[po/sv.po]"