|
| 1 | +//go:build !windows |
| 2 | + |
| 3 | +package ui |
| 4 | + |
| 5 | +import ( |
| 6 | + "errors" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/xo/terminfo" |
| 11 | +) |
| 12 | + |
| 13 | +func TestUnixLastColumnGuardUsesTerminfoXenl(t *testing.T) { |
| 14 | + report := TerminalReport{Platform: "linux", VTProcessing: true, DelayedNewline: true} |
| 15 | + |
| 16 | + applyUnixLastColumnGuard(&report, "st-256color", func() (*terminfo.Terminfo, error) { |
| 17 | + return &terminfo.Terminfo{Bools: map[int]bool{ |
| 18 | + terminfo.AutoRightMargin: true, |
| 19 | + terminfo.EatNewlineGlitch: true, |
| 20 | + }}, nil |
| 21 | + }) |
| 22 | + |
| 23 | + if !report.LastColumnGuard { |
| 24 | + t.Fatal("LastColumnGuard = false, want enabled for am+xenl terminal") |
| 25 | + } |
| 26 | + if !strings.Contains(report.Detail, "TERM=st-256color") || !strings.Contains(report.Detail, "am+xenl") { |
| 27 | + t.Fatalf("Detail = %q, want terminfo guard context", report.Detail) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestUnixLastColumnGuardRequiresXenl(t *testing.T) { |
| 32 | + report := TerminalReport{Platform: "linux", VTProcessing: true, DelayedNewline: true} |
| 33 | + |
| 34 | + applyUnixLastColumnGuard(&report, "xterm-256color", func() (*terminfo.Terminfo, error) { |
| 35 | + return &terminfo.Terminfo{Bools: map[int]bool{ |
| 36 | + terminfo.AutoRightMargin: true, |
| 37 | + }}, nil |
| 38 | + }) |
| 39 | + |
| 40 | + if report.LastColumnGuard { |
| 41 | + t.Fatal("LastColumnGuard = true, want disabled without xenl") |
| 42 | + } |
| 43 | + if report.Detail != "" { |
| 44 | + t.Fatalf("Detail = %q, want empty without guard", report.Detail) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func TestUnixLastColumnGuardIgnoresTerminfoLoadFailure(t *testing.T) { |
| 49 | + report := TerminalReport{Platform: "linux", VTProcessing: true, DelayedNewline: true} |
| 50 | + |
| 51 | + applyUnixLastColumnGuard(&report, "unknown", func() (*terminfo.Terminfo, error) { |
| 52 | + return nil, errors.New("missing terminfo") |
| 53 | + }) |
| 54 | + |
| 55 | + if report.LastColumnGuard { |
| 56 | + t.Fatal("LastColumnGuard = true, want disabled when terminfo cannot be loaded") |
| 57 | + } |
| 58 | + if report.Detail != "" { |
| 59 | + t.Fatalf("Detail = %q, want empty on load failure", report.Detail) |
| 60 | + } |
| 61 | +} |
0 commit comments