закрыты известные остатки
- документ самоуправления объявляется ключом governance, а не угадывается по «он один и без ключей оси»: конвенция, потерявшая topic, была от него неотличима и тихо теряла все проверки об отъезде к потребителю - проверка путей канона больше не ловит README.md и READING.md — эти два имени значат что-то и на стороне потребителя - lang.Recognize требует совпадения и слов, и номера версии; директории компонентов сверяются на вложенность, а не только на равенство - у обеих проверок появился --json, а convy sync называет ссылки на темы, которых компонент не взял
This commit is contained in:
@@ -298,22 +298,19 @@ func Lookup(version int, code string) (Vocabulary, error) {
|
||||
// and by nothing else: no manifest travels with it, and no path back to the
|
||||
// suite is written anywhere in it. So a check run outside a suite learns which
|
||||
// words are normative the same way a reader does — off the line the document
|
||||
// carries. The version number decides between vocabularies naming the same
|
||||
// words, which is what two versions of one natural language would do.
|
||||
// carries. Both halves have to agree: the words say which natural language,
|
||||
// the number says which version of the language, and two versions of one
|
||||
// natural language would otherwise be told apart by nothing at all.
|
||||
func Recognize(text string) (Vocabulary, bool) {
|
||||
var best Vocabulary
|
||||
for _, version := range sortedVersions() {
|
||||
for _, code := range sortedCodes(version) {
|
||||
v := registry[version][code]
|
||||
if !namesAll(text, v.Words()) {
|
||||
continue
|
||||
}
|
||||
if best.Version == 0 || matchesVersion(text, v.Version) {
|
||||
best = v
|
||||
if namesAll(text, v.Words()) && matchesVersion(text, v.Version) {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return best, best.Version != 0
|
||||
return Vocabulary{}, false
|
||||
}
|
||||
|
||||
func namesAll(text string, words []string) bool {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package lang_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.vakhrushev.me/av/convy/internal/lang"
|
||||
@@ -100,3 +101,25 @@ func TestRecognizeReadsTheLanguageOffTheVersionLine(t *testing.T) {
|
||||
t.Errorf("prose naming no words passed for a version line")
|
||||
}
|
||||
}
|
||||
|
||||
// Words say which natural language, the number says which version. One without
|
||||
// the other names no vocabulary: two versions of the same language would be
|
||||
// told apart by nothing at all.
|
||||
func TestRecognizeNeedsTheVersionToAgree(t *testing.T) {
|
||||
ru, err := lang.Lookup(1, "ru")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
line := ru.VersionLine()
|
||||
|
||||
if _, ok := lang.Recognize(line); !ok {
|
||||
t.Fatalf("the line the tool itself writes was not recognized")
|
||||
}
|
||||
wrong := strings.Replace(line, "версии 1", "версии 7", 1)
|
||||
if wrong == line {
|
||||
t.Fatal("the fixture did not change the version")
|
||||
}
|
||||
if v, ok := lang.Recognize(wrong); ok {
|
||||
t.Errorf("a line naming version 7 was read as version %d (%s)", v.Version, v.Code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user