github.com/masahide/goansible@v0.0.0-20160116054156-01eac649e9f2/lisp/cons_test.go (about)

     1  package lisp
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func cons() Cons {
     8  	v1 := &Value{numberValue, int64(1)}
     9  	v2 := &Value{numberValue, int64(2)}
    10  	v3 := &Value{numberValue, int64(3)}
    11  	c2 := &Value{consValue, &Cons{v3, &Value{nilValue, nil}}}
    12  	c1 := &Value{consValue, &Cons{v2, c2}}
    13  	return Cons{v1, c1}
    14  }
    15  
    16  func TestConsMap(t *testing.T) {
    17  	s, _ := cons().Map(func(v Value) (Value, error) {
    18  		return Value{numberValue, v.val.(int64) + 1}, nil
    19  	})
    20  	if len(s) != 3 || s[0].val != int64(2) || s[1].val != int64(3) || s[2].val != int64(4) {
    21  		t.Errorf("Expected (1 2 3), got %v", s)
    22  	}
    23  }
    24  
    25  func TestConsLen(t *testing.T) {
    26  	got := cons().Len()
    27  	if got != 3 {
    28  		t.Errorf("Expected 3, got %v\n", got)
    29  	}
    30  }
    31  
    32  func TestConsVector(t *testing.T) {
    33  	s := cons().Vector()
    34  	if len(s) != 3 || s[0].val != int64(1) || s[1].val != int64(2) || s[2].val != int64(3) {
    35  		t.Errorf("Expected (1 2 3), got %v", s)
    36  	}
    37  }
    38  
    39  func TestConsString(t *testing.T) {
    40  	expected := "(1 2 3)"
    41  	s := cons().String()
    42  	if s != expected {
    43  		t.Errorf("Cons.String() failed. Expected %v, got %v", expected, s)
    44  	}
    45  }