forked from roman-mazur/architecture-lab-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
48 lines (39 loc) · 1.1 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
package lab2
import (
"bytes"
"gopkg.in/check.v1"
"strings"
)
type ComputeHandlerSuite struct{}
var _ = check.Suite(&ComputeHandlerSuite{})
func (s *ComputeHandlerSuite) TestValidExpression(c *check.C) {
validExpression := "+ + 1 * 2 3 9"
expectedExpression := "1 2 3 * + 9 +\n"
outputBuffer := bytes.NewBuffer(nil)
handler := ComputeHandler{
Input: strings.NewReader(validExpression),
Output: outputBuffer,
}
err := handler.Compute()
c.Assert(err, check.IsNil)
c.Assert(outputBuffer.String(), check.Equals, expectedExpression)
}
func (s *ComputeHandlerSuite) TestInvalidCharactersInput(c *check.C) {
invalidCharactersInput := "wrong characters"
outputBuffer := bytes.NewBuffer(nil)
handler := ComputeHandler{
Input: strings.NewReader(invalidCharactersInput),
Output: outputBuffer,
}
err := handler.Compute()
c.Assert(err, check.NotNil)
}
func (s *ComputeHandlerSuite) TestInvalidExpression(c *check.C) {
outputBuffer := bytes.NewBuffer(nil)
handler := ComputeHandler{
Input: strings.NewReader("+ + 1"),
Output: outputBuffer,
}
err := handler.Compute()
c.Assert(err, check.NotNil)
}