MCPcopy
hub / github.com/peco/peco / TestGHIssue294_PromptStyleUsedForPromptPrefix

Function TestGHIssue294_PromptStyleUsedForPromptPrefix

layout_test.go:127–178  ·  view source on GitHub ↗

TestGHIssue294_PromptStyleUsedForPromptPrefix verifies that UserPrompt.Draw uses the Prompt style (not Basic) when rendering the prompt prefix string.

(t *testing.T)

Source from the content-addressed store, hash-verified

125// TestGHIssue294_PromptStyleUsedForPromptPrefix verifies that UserPrompt.Draw
126// uses the Prompt style (not Basic) when rendering the prompt prefix string.
127func TestGHIssue294_PromptStyleUsedForPromptPrefix(t *testing.T) {
128 styles := config.NewStyleSet()
129 styles.Prompt.Fg = config.ColorGreen | config.AttrBold
130 styles.Prompt.Bg = config.ColorBlue
131 // Make sure Basic is different so we can distinguish them.
132 styles.Basic.Fg = config.ColorDefault
133 styles.Basic.Bg = config.ColorDefault
134
135 screen := NewDummyScreen()
136 prompt, err := NewUserPrompt(screen, AnchorTop, 0, "QUERY>", styles)
137 require.NoError(t, err)
138
139 state := New()
140 state.screen = screen
141
142 state.Filters().Add(filter.NewIgnoreCase())
143
144 prompt.Draw(state)
145
146 // Collect SetCell events for y=0 (the prompt row).
147 events := screen.events["SetCell"]
148
149 promptStr := "QUERY>"
150 promptLen := len(promptStr)
151 require.True(t, len(events) >= promptLen,
152 "expected at least %d SetCell events, got %d", promptLen, len(events))
153
154 // The first promptLen cells should use the Prompt style colors.
155 for i := range promptLen {
156 ev := events[i]
157 x := ev[0].(int)
158 ch := ev[2].(rune)
159 fg := ev[3].(config.Attribute)
160 bg := ev[4].(config.Attribute)
161
162 require.Equal(t, i, x, "expected x=%d", i)
163 require.Equal(t, rune(promptStr[i]), ch, "expected character %c at position %d", promptStr[i], i)
164 require.Equal(t, styles.Prompt.Fg, fg,
165 "cell at x=%d should use Prompt.Fg, got %v", i, fg)
166 require.Equal(t, styles.Prompt.Bg, bg,
167 "cell at x=%d should use Prompt.Bg, got %v", i, bg)
168 }
169
170 // The cells after the prompt should NOT use the Prompt style —
171 // they should use the Query style (for the query text area).
172 if len(events) > promptLen {
173 ev := events[promptLen]
174 fg := ev[3].(config.Attribute)
175 require.NotEqual(t, styles.Prompt.Fg, fg,
176 "cell after prompt should not use Prompt style")
177 }
178}
179
180// TestGHIssue460_MatchedStyleDoesNotBleedToEndOfLine verifies that matched
181// text highlighting in ListArea.Draw does not extend to the screen edge.

Callers

nothing calls this directly

Calls 8

DrawMethod · 0.95
NewStyleSetFunction · 0.92
NewIgnoreCaseFunction · 0.92
NewDummyScreenFunction · 0.85
NewUserPromptFunction · 0.85
FiltersMethod · 0.80
NewFunction · 0.70
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…