main_test.go
This file
Path
examples/simple/main_test.go
88 lines · 2.2 KiB · Go
Last changed by
Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
History of this fileTake it
The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.
feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 1–2why, one step back1package main2Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 3why, one step back3/*feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 4why, one step back4func TestApp(t *testing.T) {Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 5–12why, one step back5 // TODO: Enable this test again6 // Since we added colorprofile.Writer to standard_renderer.go, this test7 // keeps failing. This is because the output is colored and has escape8 // sequences but the test runs against a buffer output and not a terminal,9 // tty, or pty. One way to fix this is to pass a color profile to the test10 // program using [tea.WithColorProfile(Ascii)].11 t.Skip("this test is currently disabled")12feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 13–26why, one step back13 m := model(10)14 tm := teatest.NewTestModel(15 t, m,16 teatest.WithInitialTermSize(70, 30),17 )18 t.Cleanup(func() {19 if err := tm.Quit(); err != nil {20 t.Fatal(err)21 }22 })2324 time.Sleep(time.Second + time.Millisecond*200)25 tm.Type("I'm typing things, but it'll be ignored by my program")26 tm.Send("ignored msg")Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 27–28why, one step back27 tm.Send(tea.KeyPressMsg{28 Code: tea.KeyEnter,feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 29–46why, one step back29 })3031 if err := tm.Quit(); err != nil {32 t.Fatal(err)33 }3435 out := readBts(t, tm.FinalOutput(t))36 if !regexp.MustCompile(`This program will exit in \d+ seconds`).Match(out) {37 t.Fatalf("output does not match the given regular expression: %s", string(out))38 }39 teatest.RequireEqualOutput(t, out)4041 if tm.FinalModel(t).(model) != 9 {42 t.Errorf("expected model to be 10, was %d", m)43 }44}4546func TestAppInteractive(t *testing.T) {Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 47–49why, one step back47 t.Skip("This test is flaky and needs to be fixed.\n" +48 "We need a more concrete way to set the initial terminal size")49feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 50–66why, one step back50 m := model(10)51 tm := teatest.NewTestModel(52 t, m,53 teatest.WithInitialTermSize(70, 30),54 )5556 time.Sleep(time.Second + time.Millisecond*200)57 tm.Send("ignored msg")5859 if bts := readBts(t, tm.Output()); !bytes.Contains(bts, []byte("This program will exit in 9 seconds")) {60 t.Fatalf("output does not match: expected %q", string(bts))61 }6263 teatest.WaitFor(t, tm.Output(), func(out []byte) bool {64 return bytes.Contains(out, []byte("This program will exit in 7 seconds"))65 }, teatest.WithDuration(5*time.Second))66Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 67–68why, one step back67 tm.Send(tea.KeyPressMsg{68 Code: tea.KeyEnter,feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 69–87why, one step back69 })7071 if err := tm.Quit(); err != nil {72 t.Fatal(err)73 }7475 if tm.FinalModel(t).(model) != 7 {76 t.Errorf("expected model to be 7, was %d", m)77 }78}7980func readBts(tb testing.TB, r io.Reader) []byte {81 tb.Helper()82 bts, err := io.ReadAll(r)83 if err != nil {84 tb.Fatal(err)85 }86 return bts87}Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 88why, one step back88*/