github.com/jgbaldwinbrown/perf@v0.1.1/analysis/app/parse_test.go (about)

     1  // Copyright 2017 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package app
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestParseQueryString(t *testing.T) {
    13  	tests := []struct {
    14  		q          string
    15  		wantPrefix string
    16  		wantParts  []string
    17  	}{
    18  		{"prefix | one vs two", "prefix", []string{"one", "two"}},
    19  		{"prefix one vs two", "", []string{"prefix one", "two"}},
    20  		{"anything else", "", []string{"anything else"}},
    21  		{`one vs "two vs three"`, "", []string{"one", `"two vs three"`}},
    22  		{"mixed\ttabs \"and\tspaces\"", "", []string{"mixed tabs \"and\tspaces\""}},
    23  	}
    24  	for _, test := range tests {
    25  		t.Run(test.q, func(t *testing.T) {
    26  			havePrefix, haveParts := parseQueryString(test.q)
    27  			if havePrefix != test.wantPrefix {
    28  				t.Errorf("parseQueryString returned prefix %q, want %q", havePrefix, test.wantPrefix)
    29  			}
    30  			if !reflect.DeepEqual(haveParts, test.wantParts) {
    31  				t.Errorf("parseQueryString returned parts %#v, want %#v", haveParts, test.wantParts)
    32  			}
    33  		})
    34  	}
    35  }