|
| 1 | +package guard |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/donislawdev/TestingFilesGenerator/internal/format" |
| 7 | + _ "github.com/donislawdev/TestingFilesGenerator/internal/format/all" |
| 8 | +) |
| 9 | + |
| 10 | +// spreadsheetWidth is where a spreadsheet stops, measured rather than |
| 11 | +// remembered: 2026-09-03 for CSV and again 2026-09-08 for XLSX, both with |
| 12 | +// LibreOffice Calc 26.2.5.2 headless. A table of this many columns comes back |
| 13 | +// whole. One column more comes back with this many, the last column dropped, |
| 14 | +// exit 0 and not one word on either stream. |
| 15 | +const spreadsheetWidth = 16384 |
| 16 | + |
| 17 | +// narrowerOnPurpose names a format whose columns cannot reach past a |
| 18 | +// spreadsheet because the format itself stops first, with the reason. |
| 19 | +// |
| 20 | +// It is empty, and that is the point rather than an oversight. A format ends up |
| 21 | +// here only when its OWN structure caps it - the way an icon stores each side |
| 22 | +// in a single byte - and never because a smaller number felt tidier. Writing |
| 23 | +// the reason down is the price of the exception, which is what stops this |
| 24 | +// becoming the sort of list somebody adds to instead of thinking. |
| 25 | +var narrowerOnPurpose = map[string]string{} |
| 26 | + |
| 27 | +// A format with columns has to offer more of them than a spreadsheet accepts. |
| 28 | +// |
| 29 | +// The ceiling of a setting belongs to the reader under test, not to what this |
| 30 | +// tool finds comfortable to write. Standing on both sides of a limit is what a |
| 31 | +// boundary set is for, so a ceiling that stops at the limit offers the last |
| 32 | +// table that survives and never the first that does not. |
| 33 | +// |
| 34 | +// This is not hypothetical tidiness, it is a defect this project shipped. |
| 35 | +// XLSX declared 64 from the day it was written until 2026-09-08, with the |
| 36 | +// reason "the width a person would actually look at" - which describes a |
| 37 | +// document somebody reads rather than a fixture somebody tests with. CSV asked |
| 38 | +// the same question of the same reader and answered 32768. Nothing compared |
| 39 | +// them, and at 64 there was no way to build a sheet that asks Excel about its |
| 40 | +// own limit at all. |
| 41 | +// |
| 42 | +// What it asks about is the OFFER, because that is what a ceiling is. That the |
| 43 | +// file itself works was measured on 2026-09-08 rather than asserted here: a |
| 44 | +// workbook of 16385 columns built by this tool converts through Calc at exit 0 |
| 45 | +// and comes back with 16384, which is the same silent loss a workbook from |
| 46 | +// another writer produces. Building one costs twelve megabytes, which is not a |
| 47 | +// price worth paying on every run of this suite. |
| 48 | +// |
| 49 | +// Asked of every registered format rather than of the two that have the |
| 50 | +// setting today, so a third tabular format is covered on the day it arrives. |
| 51 | +func TestAFormatWithColumnsReachesPastWhatASpreadsheetAccepts(t *testing.T) { |
| 52 | + examined := 0 |
| 53 | + |
| 54 | + for _, d := range format.All() { |
| 55 | + for _, p := range d.Properties { |
| 56 | + if p.Name != "columns" || p.Kind != format.PropertyInt { |
| 57 | + continue |
| 58 | + } |
| 59 | + if why, narrow := narrowerOnPurpose[d.ID]; narrow { |
| 60 | + if p.Max > spreadsheetWidth { |
| 61 | + t.Errorf("%s is excused as narrower on purpose (%s) and reaches %d anyway - take the excuse off", |
| 62 | + d.ID, why, p.Max) |
| 63 | + } |
| 64 | + continue |
| 65 | + } |
| 66 | + examined++ |
| 67 | + if p.Max <= spreadsheetWidth { |
| 68 | + t.Errorf("%s offers at most %d columns and a spreadsheet accepts %d, "+ |
| 69 | + "so no fixture built from it can ask the reader about its own limit - "+ |
| 70 | + "raise the ceiling, or name the structural reason in narrowerOnPurpose", |
| 71 | + d.ID, p.Max, spreadsheetWidth) |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + if examined == 0 { |
| 77 | + t.Fatal("no format offers a column count, so this proved nothing") |
| 78 | + } |
| 79 | +} |
0 commit comments