<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/walk/walk_test.go
blob: 759c50113835515f894adac573dc1a2bce698374 (plain)
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
package walk

import (
	"testing"
	"log"
)

func TestValueIter(t *testing.T) {
	values := ValueList{
		NumberValue(1),
		NumberValue(2),
		NumberValue(3),
	}

	valuesCopy := ValueList{}

	iter := NewValueIter(values)

	for {
		edible := iter.Next()
		if edible == nil {
			break
		}

		log.Println(edible)

		value, isValue := edible.(Value)

		if !isValue {
			t.Fatalf("Iterator produced a non-value")
		}

		valuesCopy = append(valuesCopy, value)
	}

	if len(values) != len(valuesCopy) {
		t.Fatalf("iter gave the wrong number of values")
	}

	for i, value := range values {
		if value != valuesCopy[i] {
			t.Fatalf("iter produced an incorrect value")
		}
	}
}