github.com/getgauge/gauge@v1.6.9/gauge/specCollection_test.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package gauge
     8  
     9  import (
    10  	"reflect"
    11  	"testing"
    12  )
    13  
    14  func TestSpecCollection(t *testing.T) {
    15  	s1 := &Specification{FileName: "filename1"}
    16  	s2 := &Specification{FileName: "filename2"}
    17  	s3 := &Specification{FileName: "filename3"}
    18  
    19  	collection := NewSpecCollection([]*Specification{s1, s2, s3}, false)
    20  
    21  	got := [][]*Specification{collection.Next(), collection.Next(), collection.Next()}
    22  	want := [][]*Specification{{s1}, {s2}, {s3}}
    23  
    24  	if !reflect.DeepEqual(want, got) {
    25  		t.Errorf("Spec Collection Failed\n\tWant: %v\n\t Got:%v", want, got)
    26  	}
    27  }
    28  
    29  func TestGroupSpecCollection(t *testing.T) {
    30  	s1 := &Specification{FileName: "filename1"}
    31  	s3 := &Specification{FileName: "filename3"}
    32  
    33  	collection := NewSpecCollection([]*Specification{s1, s3, s3}, true)
    34  
    35  	got := [][]*Specification{collection.Next(), collection.Next()}
    36  	want := [][]*Specification{{s1}, {s3, s3}}
    37  
    38  	if !reflect.DeepEqual(set(want), set(got)) {
    39  		t.Errorf("Spec Collection Failed\n\tWant: %v\n\t Got:%v", want, got)
    40  	}
    41  
    42  	for key, value := range got {
    43  		if value[0].FileName != want[key][0].FileName {
    44  			t.Errorf("Spec Collection order is not maintained\n\tWant: %v\n\t Got:%v", want[key], got[key])
    45  		}
    46  	}
    47  }
    48  
    49  func set(s [][]*Specification) map[int][]*Specification {
    50  	specs := make(map[int][]*Specification)
    51  	for _, sp := range s {
    52  		specs[len(sp)] = sp
    53  	}
    54  	return specs
    55  }