Compare commits
2
Commits
a0f776a154
..
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
967930f9bc | ||
|
|
fe23bb5045 |
@@ -627,6 +627,10 @@ func (a *App) cmdWindow(args string) {
|
|||||||
nick, buf.Name, "connected",
|
nick, buf.Name, "connected",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
a.mu.Lock()
|
||||||
|
a.target = ""
|
||||||
|
a.mu.Unlock()
|
||||||
|
|
||||||
a.ui.SetStatus(nick, "", "connected")
|
a.ui.SetStatus(nick, "", "connected")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,6 +219,63 @@ func TestJoinResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAltDigit checks that Alt and a digit shows that window and
|
||||||
|
// makes its channel or user the target, as /window does. Window
|
||||||
|
// 0, the status window, leaves no target.
|
||||||
|
func TestAltDigit(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
digit rune
|
||||||
|
// The buffer shown and the target after the key.
|
||||||
|
wantBuffer string
|
||||||
|
wantTarget string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "channel window",
|
||||||
|
digit: '1',
|
||||||
|
wantBuffer: testChannel,
|
||||||
|
wantTarget: testChannel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "status window",
|
||||||
|
digit: '0',
|
||||||
|
wantBuffer: "(status)",
|
||||||
|
wantTarget: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
app := &App{ui: NewUI(), nick: testNick, target: testOtherNick}
|
||||||
|
app.ui.OnInput(app.handleInput)
|
||||||
|
runUI(t, app.ui)
|
||||||
|
|
||||||
|
// Window 1 is the channel. Window 2, the one shown, is
|
||||||
|
// the other user's.
|
||||||
|
app.ui.SwitchToBuffer(testChannel)
|
||||||
|
app.ui.SwitchToBuffer(testOtherNick)
|
||||||
|
|
||||||
|
key := tcell.NewEventKey(tcell.KeyRune, test.digit, tcell.ModAlt)
|
||||||
|
app.ui.app.GetInputCapture()(key)
|
||||||
|
|
||||||
|
var shown string
|
||||||
|
|
||||||
|
app.ui.app.QueueUpdate(func() {
|
||||||
|
shown = app.ui.buffers[app.ui.currentBuffer].Name
|
||||||
|
})
|
||||||
|
|
||||||
|
if shown != test.wantBuffer || app.target != test.wantTarget {
|
||||||
|
t.Fatalf("got buffer %s and target %q, want %s and %q",
|
||||||
|
shown, app.target, test.wantBuffer, test.wantTarget)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestOwnEventFromOtherClient checks that a message, notice,
|
// TestOwnEventFromOtherClient checks that a message, notice,
|
||||||
// join or part that the user's session makes from another
|
// join or part that the user's session makes from another
|
||||||
// client shows as one line in the buffer it belongs to.
|
// client shows as one line in the buffer it belongs to.
|
||||||
|
|||||||
+5
-2
@@ -240,10 +240,13 @@ func (ui *UI) initKeyCapture() {
|
|||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Alt and a digit runs /window with that digit.
|
||||||
|
// SwitchBuffer alone would leave the target as it was.
|
||||||
r := event.Rune()
|
r := event.Rune()
|
||||||
if r >= '0' && r <= '9' {
|
if r >= '0' && r <= '9' {
|
||||||
idx := int(r - '0')
|
if ui.onInput != nil {
|
||||||
ui.SwitchBuffer(idx)
|
ui.onInput("/window " + string(r))
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,9 +191,9 @@ func parseInt(key string, minimum int, value *int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseFloat sets *value to the setting key read as a decimal number. It
|
// parseFloat sets *value to the setting key read as a floating-point
|
||||||
// returns an error when the value does not parse or is not a finite
|
// number. It returns an error when the value does not parse or is not a
|
||||||
// number above zero.
|
// finite number above zero.
|
||||||
func parseFloat(key string, value *float64) error {
|
func parseFloat(key string, value *float64) error {
|
||||||
raw := viper.GetString(key)
|
raw := viper.GetString(key)
|
||||||
|
|
||||||
|
|||||||
@@ -78,26 +78,28 @@ func TestUnsetSettingsKeepDefaults(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestValidSettingsAreUsed(t *testing.T) {
|
func TestValidSettingsAreUsed(t *testing.T) {
|
||||||
t.Setenv("PORT", "9000")
|
// Each whole number is the lowest value its setting allows, and 1ns
|
||||||
t.Setenv("MAX_MESSAGE_SIZE", "1024")
|
// is the shortest duration allowed.
|
||||||
|
t.Setenv("PORT", "0")
|
||||||
|
t.Setenv("MAX_MESSAGE_SIZE", "1")
|
||||||
t.Setenv("NEOIRC_HASHCASH_BITS", "0")
|
t.Setenv("NEOIRC_HASHCASH_BITS", "0")
|
||||||
t.Setenv("LOGIN_RATE_BURST", "10")
|
t.Setenv("LOGIN_RATE_BURST", "1")
|
||||||
t.Setenv("LOGIN_RATE_LIMIT", "0.5")
|
t.Setenv("LOGIN_RATE_LIMIT", "0.5")
|
||||||
t.Setenv("DEBUG", "true")
|
t.Setenv("DEBUG", "true")
|
||||||
t.Setenv("MAINTENANCE_MODE", "true")
|
t.Setenv("MAINTENANCE_MODE", "true")
|
||||||
t.Setenv("MESSAGE_MAX_AGE", "24h")
|
t.Setenv("MESSAGE_MAX_AGE", "1ns")
|
||||||
t.Setenv("QUEUE_MAX_AGE", "1h30m")
|
t.Setenv("QUEUE_MAX_AGE", "1h30m")
|
||||||
t.Setenv("SESSION_IDLE_TIMEOUT", "45m")
|
t.Setenv("SESSION_IDLE_TIMEOUT", "45m")
|
||||||
|
|
||||||
want := settings{
|
want := settings{
|
||||||
Port: 9000,
|
Port: 0,
|
||||||
MaxMessageSize: 1024,
|
MaxMessageSize: 1,
|
||||||
HashcashBits: 0,
|
HashcashBits: 0,
|
||||||
LoginRateBurst: 10,
|
LoginRateBurst: 1,
|
||||||
LoginRateLimit: 0.5,
|
LoginRateLimit: 0.5,
|
||||||
Debug: true,
|
Debug: true,
|
||||||
MaintenanceMode: true,
|
MaintenanceMode: true,
|
||||||
MessageMaxAge: "24h",
|
MessageMaxAge: "1ns",
|
||||||
QueueMaxAge: "1h30m",
|
QueueMaxAge: "1h30m",
|
||||||
SessionIdleTimeout: "45m",
|
SessionIdleTimeout: "45m",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user