Name the tests' holds, header and row lookup by their one meaning, and drop the dead bound_test.go pointer
This commit is contained in:
+1
-1
@@ -125,7 +125,7 @@ func TestCalcGuardsPanic(t *testing.T) {
|
||||
// TestCalcOperandReadsTheExpansionsDraw pins the one-draw rule for a calc operand.
|
||||
// A field the format renders and a calc reads is drawn once per expansion, so the
|
||||
// operand shown is the operand computed — the correlation the dotted-path rule
|
||||
// already gives a level (see bound_test.go), applied to a plain sibling.
|
||||
// already gives a level, applied to a plain sibling.
|
||||
func TestCalcOperandReadsTheExpansionsDraw(t *testing.T) {
|
||||
dir := writeData(t, map[string]string{
|
||||
"inv": `{"format":"{net} x {qty} = {calc(net * qty, 2)}","net":["19.99","5.00","100.00"],"qty":["2","3","7"]}`,
|
||||
|
||||
+8
-8
@@ -117,7 +117,7 @@ func TestReferenceNamingAHeldLevelIsRejected(t *testing.T) {
|
||||
t.Errorf("%s: New = %v, want the reference rejected as an overlap", name, err)
|
||||
}
|
||||
}
|
||||
// A reference to anything this format does not bind is untouched.
|
||||
// A reference to anything this format does not hold is untouched.
|
||||
if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
|
||||
"cat": `{"format":"{p.first} {/surname}","p":{"format":"{first}","first":["Anna","Bo"]}}`,
|
||||
"surname": `["Eriksson","Lindqvist"]`,
|
||||
@@ -479,7 +479,7 @@ func TestFieldWithoutAPathTokenStillDrawsEachTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTwoHeldHeadsDrawIndependently(t *testing.T) {
|
||||
// Binding is per head, so two correlated sets in one format compose instead
|
||||
// A hold is per head, so two correlated sets in one format compose instead
|
||||
// of needing a cross product of variants.
|
||||
f := engine(4)
|
||||
seen := map[string]bool{}
|
||||
@@ -495,8 +495,8 @@ func TestTwoHeldHeadsDrawIndependently(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatRedrawsTheBinding(t *testing.T) {
|
||||
// The binding lives for one expansion, so each repetition is a fresh draw —
|
||||
func TestRepeatRedrawsTheHold(t *testing.T) {
|
||||
// The hold lives for one expansion, so each repetition is a fresh draw —
|
||||
// and each repetition is internally consistent.
|
||||
f := engine(5)
|
||||
tmpl := strings.Replace(places("{place.postal-code} {place.locality}"), `"format":"{place.postal-code} {place.locality}"`,
|
||||
@@ -522,8 +522,8 @@ func TestRepeatRedrawsTheBinding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedTemplateKeepsItsOwnBinding(t *testing.T) {
|
||||
// A binding belongs to the expansion that made it: an inner template's own
|
||||
func TestNestedTemplateKeepsItsOwnHold(t *testing.T) {
|
||||
// A hold belongs to the expansion that made it: an inner template's own
|
||||
// place is not the outer one's.
|
||||
f := engine(6)
|
||||
tmpl := `{"format":"{place.v}{inner}",
|
||||
@@ -534,7 +534,7 @@ func TestNestedTemplateKeepsItsOwnBinding(t *testing.T) {
|
||||
seen[mustRender(t, f, tmpl)] = true
|
||||
}
|
||||
if !seen["AB"] && !seen["BA"] {
|
||||
t.Fatalf("400 draws produced %v, want the inner binding to be independent", seen)
|
||||
t.Fatalf("400 draws produced %v, want the inner hold to be independent", seen)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,7 +722,7 @@ func TestCycleThroughAPathTokenIsRejected(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeldPathIsReachableByFake(t *testing.T) {
|
||||
// Binding changes how a format reads a sibling, not what List and Fake offer:
|
||||
// Holding changes how a format reads a sibling, not what List and Fake offer:
|
||||
// the sub-fields stay addressable on their own.
|
||||
dir := writeData(t, map[string]string{"address": places("{place.postal-code} {place.locality}")})
|
||||
f, err := New(WithoutShippedData(), WithDataPath(dir), WithSeed(9))
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ func TestNoTableAllocRegression(t *testing.T) {
|
||||
{"two columns of one draw", "x", 10},
|
||||
} {
|
||||
if allocs := testing.AllocsPerRun(10000, func() { f.Fake(s.path) }); allocs > s.base*1.10 {
|
||||
t.Errorf("%s: %.1f allocs/op regressed past %.1f (baseline %.1f + 10%%); a row index built per draw is the usual cause", s.name, allocs, s.base*1.10, s.base)
|
||||
t.Errorf("%s: %.1f allocs/op regressed past %.1f (baseline %.1f + 10%%); a row lookup built per draw is the usual cause", s.name, allocs, s.base*1.10, s.base)
|
||||
}
|
||||
}
|
||||
// Five linked tables, the depth a country's geo tree has: every pin must stay inline.
|
||||
|
||||
+22
-22
@@ -819,13 +819,13 @@ func TestShippedTables(t *testing.T) {
|
||||
// TestEveryTerritoryNamesAShippedCountry proves what no parent can: the sovereign a
|
||||
// territory names is a row of the same table, which a link would make a cycle.
|
||||
func TestEveryTerritoryNamesAShippedCountry(t *testing.T) {
|
||||
head, rows := shippedRows(t, "territory.tsv", "alpha2", "country")
|
||||
header, rows := shippedRows(t, "territory.tsv", "alpha2", "country")
|
||||
keys := map[string]bool{}
|
||||
for _, r := range rows {
|
||||
keys[r[head["alpha2"]]] = true
|
||||
keys[r[header["alpha2"]]] = true
|
||||
}
|
||||
for i, r := range rows {
|
||||
if c := r[head["country"]]; !keys[c] {
|
||||
if c := r[header["country"]]; !keys[c] {
|
||||
t.Errorf("territory.tsv line %d: country %q is no alpha2 of the table", i+2, c)
|
||||
}
|
||||
}
|
||||
@@ -835,34 +835,34 @@ func TestEveryTerritoryNamesAShippedCountry(t *testing.T) {
|
||||
// every Chromium fork carries Chrome's token, so a mis-ordered pattern relabels a
|
||||
// row rather than dropping it.
|
||||
func TestEveryUserAgentColumnAgreesWithItsString(t *testing.T) {
|
||||
head, rows := shippedRows(t, "useragent.tsv", "browser", "device", "os", "ua")
|
||||
header, rows := shippedRows(t, "useragent.tsv", "browser", "device", "os", "ua")
|
||||
for _, token := range []struct{ in, browser string }{
|
||||
{"Edg", "Edge"}, {"OPR/", "Opera"}, {"SamsungBrowser/", "Samsung Internet"}, {"CriOS/", "Chrome"},
|
||||
} {
|
||||
for i, r := range rows {
|
||||
if strings.Contains(r[head["ua"]], token.in) && r[head["browser"]] != token.browser {
|
||||
t.Errorf("useragent.tsv line %d: %q carries %q but is labelled %q", i+2, r[head["ua"]], token.in, r[head["browser"]])
|
||||
if strings.Contains(r[header["ua"]], token.in) && r[header["browser"]] != token.browser {
|
||||
t.Errorf("useragent.tsv line %d: %q carries %q but is labelled %q", i+2, r[header["ua"]], token.in, r[header["browser"]])
|
||||
}
|
||||
}
|
||||
}
|
||||
for i, r := range rows {
|
||||
if r[head["device"]] == "mobile" && r[head["os"]] != "Android" && r[head["os"]] != "iOS" {
|
||||
t.Errorf("useragent.tsv line %d: a mobile row runs %q", i+2, r[head["os"]])
|
||||
if r[header["device"]] == "mobile" && r[header["os"]] != "Android" && r[header["os"]] != "iOS" {
|
||||
t.Errorf("useragent.tsv line %d: a mobile row runs %q", i+2, r[header["os"]])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestEveryTimezoneRowIsWellFormed scans the file rather than drawing: the draw is
|
||||
// population-weighted, so it samples the populous head and leaves most rows unrendered.
|
||||
// population-weighted, so it samples the populous zones and leaves most rows unrendered.
|
||||
func TestEveryTimezoneRowIsWellFormed(t *testing.T) {
|
||||
head, rows := shippedRows(t, "timezone.tsv", "offset", "territory", "weight", "zone")
|
||||
header, rows := shippedRows(t, "timezone.tsv", "offset", "territory", "weight", "zone")
|
||||
offset := regexp.MustCompile(`^[+-](0\d|1[0-4]):[0-5]\d$`)
|
||||
for i, r := range rows {
|
||||
if !offset.MatchString(r[head["offset"]]) {
|
||||
t.Errorf("timezone.tsv line %d: offset %q is no ±HH:MM", i+2, r[head["offset"]])
|
||||
if !offset.MatchString(r[header["offset"]]) {
|
||||
t.Errorf("timezone.tsv line %d: offset %q is no ±HH:MM", i+2, r[header["offset"]])
|
||||
}
|
||||
if w, err := strconv.Atoi(r[head["weight"]]); err != nil || w < 1 {
|
||||
t.Errorf("timezone.tsv line %d: weight %q is not a positive number", i+2, r[head["weight"]])
|
||||
if w, err := strconv.Atoi(r[header["weight"]]); err != nil || w < 1 {
|
||||
t.Errorf("timezone.tsv line %d: weight %q is not a positive number", i+2, r[header["weight"]])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -871,10 +871,10 @@ func TestEveryTimezoneRowIsWellFormed(t *testing.T) {
|
||||
// most of 1438 rows unrendered, and the register wraps a right-to-left label in bidi
|
||||
// marks that belong to its display, not to the label.
|
||||
func TestEveryTldRowSpellsItsKey(t *testing.T) {
|
||||
head, rows := shippedRows(t, "tld.tsv", "tld", "type", "unicode")
|
||||
header, rows := shippedRows(t, "tld.tsv", "tld", "type", "unicode")
|
||||
types := map[string]bool{"country-code": true, "generic": true, "generic-restricted": true, "infrastructure": true, "sponsored": true}
|
||||
for i, r := range rows {
|
||||
key, kind, shown := r[head["tld"]], r[head["type"]], r[head["unicode"]]
|
||||
key, kind, shown := r[header["tld"]], r[header["type"]], r[header["unicode"]]
|
||||
if !types[kind] {
|
||||
t.Errorf("tld.tsv line %d: %s is typed %q, which the register assigns no TLD", i+2, key, kind)
|
||||
}
|
||||
@@ -900,24 +900,24 @@ func shippedRows(t *testing.T, file string, want ...string) (map[string]int, [][
|
||||
t.Fatal(err)
|
||||
}
|
||||
lines := strings.Split(strings.TrimSuffix(string(data), "\n"), "\n")
|
||||
head := map[string]int{}
|
||||
header := map[string]int{}
|
||||
for i, name := range strings.Split(lines[0], "\t") {
|
||||
head[name] = i
|
||||
header[name] = i
|
||||
}
|
||||
for _, name := range want {
|
||||
if _, ok := head[name]; !ok {
|
||||
if _, ok := header[name]; !ok {
|
||||
t.Fatalf("%s columns %v, want %v", file, lines[0], want)
|
||||
}
|
||||
}
|
||||
rows := make([][]string, 0, len(lines)-1)
|
||||
for i, line := range lines[1:] {
|
||||
cells := strings.Split(line, "\t")
|
||||
if len(cells) != len(head) {
|
||||
t.Fatalf("%s line %d has %d cells, want %d", file, i+2, len(cells), len(head))
|
||||
if len(cells) != len(header) {
|
||||
t.Fatalf("%s line %d has %d cells, want %d", file, i+2, len(cells), len(header))
|
||||
}
|
||||
rows = append(rows, cells)
|
||||
}
|
||||
return head, rows
|
||||
return header, rows
|
||||
}
|
||||
|
||||
// TestNamedTableWithoutAKeyResolvesInsideItsParent pins a table whose rows are
|
||||
|
||||
Reference in New Issue
Block a user