Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import "github.com/devhindo/x/src/cli/x"
func main() {
x.Run()
}

123 changes: 123 additions & 0 deletions src/cli/tweet/future_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package tweet

import (
"testing"
)


func TestHandleTweetTime(t *testing.T) {
tests := []struct {
name string
input string
wantHours int
wantMinutes int
wantErr bool
}{
{
name: "hours and minutes",
input: "2h3m",
wantHours: 2,
wantMinutes: 3,
wantErr: false,
},
{
name: "only hours",
input: "5h",
wantHours: 5,
wantMinutes: 0,
wantErr: false,
},
{
name: "only minutes",
input: "30m",
wantHours: 0,
wantMinutes: 30,
wantErr: false,
},
{
name: "empty string",
input: "",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
{
name: "invalid format garbage",
input: "abc",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
{
name: "missing suffix",
input: "2h3",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
{
name: "invalid number",
input: "xh",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHours, gotMinutes, err := handleTweetTime(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("handleTweetTime() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotHours != tt.wantHours {
t.Errorf("handleTweetTime() gotHours = %v, want %v", gotHours, tt.wantHours)
}
if gotMinutes != tt.wantMinutes {
t.Errorf("handleTweetTime() gotMinutes = %v, want %v", gotMinutes, tt.wantMinutes)
}
})
}
}

func TestHandleFutureTweetArgs(t *testing.T) {
tests := []struct {
name string
args []string
wantTweet string
wantTime string
wantErr bool
}{
{
name: "valid args",
args: []string{"x", "f", "hello world", "2h"},
wantTweet: "hello world",
wantTime: "2h",
wantErr: false,
},
{
name: "not enough args",
args: []string{"x", "f"},
wantTweet: "",
wantTime: "",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotTweet, gotTime, err := handleFutureTweetArgs(tt.args)
if (err != nil) != tt.wantErr {
t.Errorf("handleFutureTweetArgs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotTweet != tt.wantTweet {
t.Errorf("handleFutureTweetArgs() gotTweet = %v, want %v", gotTweet, tt.wantTweet)
}
if gotTime != tt.wantTime {
t.Errorf("handleFutureTweetArgs() gotTime = %v, want %v", gotTime, tt.wantTime)
}
})
}
}
Loading