github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/app/command_groupmsg_test.go (about)

     1  package app
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestGroupMsgUsernames(t *testing.T) {
     8  	if users, parsedMessage := groupMsgUsernames(""); len(users) != 0 || parsedMessage != "" {
     9  		t.Fatal("error parsing empty message")
    10  	}
    11  	if users, parsedMessage := groupMsgUsernames("test"); len(users) != 1 || parsedMessage != "" {
    12  		t.Fatal("error parsing simple user")
    13  	}
    14  	if users, parsedMessage := groupMsgUsernames("test1, test2, test3 , test4"); len(users) != 4 || parsedMessage != "" {
    15  		t.Fatal("error parsing various users")
    16  	}
    17  
    18  	if users, parsedMessage := groupMsgUsernames("test1, test2 message with spaces"); len(users) != 2 || parsedMessage != "message with spaces" {
    19  		t.Fatal("error parsing message")
    20  	}
    21  
    22  	if users, parsedMessage := groupMsgUsernames("test1, test2 message with, comma"); len(users) != 2 || parsedMessage != "message with, comma" {
    23  		t.Fatal("error parsing messages with comma")
    24  	}
    25  
    26  	if users, parsedMessage := groupMsgUsernames("test1,,,test2"); len(users) != 2 || parsedMessage != "" {
    27  		t.Fatal("error parsing multiple commas in username ")
    28  	}
    29  
    30  	if users, parsedMessage := groupMsgUsernames("    test1,       test2     other message         "); len(users) != 2 || parsedMessage != "other message" {
    31  		t.Fatal("error parsing strange usage of spaces")
    32  	}
    33  
    34  	if users, _ := groupMsgUsernames("    test1,       test2,,123,@321,+123"); len(users) != 5 || users[0] != "test1" || users[1] != "test2" || users[2] != "123" || users[3] != "321" || users[4] != "+123" {
    35  		t.Fatal("error parsing different types of users")
    36  	}
    37  }