-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
50 lines (46 loc) · 1.09 KB
/
handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"errors"
"os"
"testing"
"github.com/sryanh/calcy-lib/calc"
)
func assertEqual(t *testing.T, a any, b any) {
if a != b {
t.Error("Expected them to be equal but they weren't.")
}
}
func assertFail(t *testing.T, a any, b any) {}
func TestMissingInput(t *testing.T) {
var values []string
handle := NewHandler(os.Stdout, calc.Addition{})
result, err := handle.Handle(values)
if result != 0 {
t.Error("Expected 0, got ", result)
}
if !errors.Is(err, errTooFewArgs) {
t.Errorf("Expected %s", errTooFewArgs)
}
}
func TestMalformedInput(t *testing.T) {
var values []string
handle := NewHandler(os.Stdout, calc.Addition{})
result, err := handle.Handle(values)
if result != 0 {
t.Error("Expected 0, got ", result)
}
if !errors.Is(err, errTooFewArgs) {
t.Errorf("Expected %s", errMalformedInput)
}
}
func TestCorrectInput(t *testing.T) {
values := []string{"1", "2"}
handle := NewHandler(os.Stdout, calc.Addition{})
result, err := handle.Handle(values)
if result != 0 {
t.Error("Expected 3, got ", result)
}
if !errors.Is(err, nil) {
t.Errorf("Expected %s", "")
}
}