module main fn test_listing_renders_plain_entries() { old := color_flag defer { color_flag = old } color_flag = 'never' // the entries are plain values; the render styles them, and shows an // empty one as '-' l := Listing{ fields: ['name', 'version', 'description'] entries: [ListEntry{ name: 'zsh' values: ['zsh', '5.9-1', ''] }, ListEntry{ name: 'bash' values: ['bash', '5.2-1', 'shell'] }] } assert table_text(l.entries.map(listing_row(l.fields, it)), '', ' ') == 'zsh 5.9-1 -\nbash 5.2-1 shell' } // a row built against another listing's fields is shortened, not tripped // over: an entry always carries one value per field, but a mismatched one // fills its tail with empties and renders as '-' instead of panicking fn test_listing_row_survives_a_short_entry() { old := color_flag defer { color_flag = old } color_flag = 'never' r := listing_row(['name', 'version', 'description'], ListEntry{ name: 'zsh' values: ['zsh'] }) assert r.cols.len == 3 assert table_text([r], '', ' ') == 'zsh - -' } fn test_info_table() { old := color_flag defer { color_flag = old } color_flag = 'never' assert info_table([]) == '' // -F all on a package without optional deps: an optdepends with no // items shows '-' and draws no continuation line assert info_table([InfoField{ field: 'optdepends' }, InfoField{ field: 'install_reason' value: 'explicitly installed' }]) == 'optdepends -\ninstall reason explicitly installed' // optdepends puts each item on its own line, padded to the value column assert info_table([InfoField{ field: 'optdepends' value: 'a, b' items: ['a: x', 'b'] }]) == 'optdepends a: x\n b' } fn test_reason_spellings() ! { // every reason in both spellings, and the frontend's key is a word mark // reads back as that reason for reason, want in { nspkg.PackageReason.explicit: ['explicit', 'explicitly installed'] nspkg.PackageReason.depend: ['depend', 'installed as a dependency'] nspkg.PackageReason.unknown: ['unknown', 'unknown'] } { assert [reason_key(reason), reason_to_str(reason)] == want assert parse_reason(reason_key(reason))! == reason } for short, reason in { 'e': nspkg.PackageReason.explicit 'dep': nspkg.PackageReason.depend 'dependency': nspkg.PackageReason.depend 'u': nspkg.PackageReason.unknown } { assert parse_reason(short)! == reason } if _ := parse_reason('optional') { assert false, 'an unknown reason was read' } } fn test_info_width() { // no terminal (a pipe answers 0), or a size no terminal has: the fallback assert info_width(0) == info_fallback_cols assert info_width(-1) == info_fallback_cols assert info_width(info_min_cols - 1) == info_fallback_cols // a terminal's own width, from the narrowest one taken on assert info_width(info_min_cols) == info_min_cols assert info_width(132) == 132 }