github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/taskgroup_test.go (about)

     1  package alfred
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestParseTaskGroup(t *testing.T) {
     9  	task := Task{}
    10  	tg := task.ParseTaskGroup(" task.one task.two task.three ")
    11  	if tg[0].Name != "task.one" {
    12  		t.Fatalf("tg should contain task.one")
    13  	}
    14  
    15  	if tg[1].Name != "task.two" {
    16  		t.Fatalf("tg should contain task.two")
    17  	}
    18  
    19  	if tg[2].Name != "task.three" {
    20  		t.Fatalf("tg should contain task.three")
    21  	}
    22  
    23  	tgWArgs := task.ParseTaskGroup("task.one\n task.two(arg1, arg2 , arg3, arg4 ) \ntask.two\ntask.three(arg1)")
    24  
    25  	if tgWArgs[0].Name != "task.one" {
    26  		t.Fatalf("task with args name not set")
    27  	}
    28  
    29  	if len(tgWArgs[0].Args) != 0 {
    30  		t.Fatalf("task with args, the args should be empty")
    31  	}
    32  
    33  	fmt.Println("1.Name", tgWArgs[1].Name)
    34  	if tgWArgs[1].Name != "task.two" {
    35  		t.Fatalf("task.two was expected, with arguments")
    36  	}
    37  
    38  	if len(tgWArgs[1].Args) != 4 {
    39  		t.Fatalf("task.two should have 4 arguments")
    40  	}
    41  
    42  	if tgWArgs[1].Args[1] != "arg2" {
    43  		t.Fatalf("Expected 'arg2' as argument with no white space")
    44  	}
    45  }