...

Source file src/goji.io/pat/url_test.go

Documentation: goji.io/pat

     1  package pat
     2  
     3  import (
     4  	"net/url"
     5  	"testing"
     6  )
     7  
     8  var HexTexts = []struct {
     9  	input byte
    10  	ishex bool
    11  	unhex byte
    12  }{
    13  	{'0', true, 0},
    14  	{'4', true, 4},
    15  	{'a', true, 10},
    16  	{'F', true, 15},
    17  	{'h', false, 0},
    18  	{'^', false, 0},
    19  }
    20  
    21  func TestHex(t *testing.T) {
    22  	t.Parallel()
    23  
    24  	for _, test := range HexTexts {
    25  		if actual := ishex(test.input); actual != test.ishex {
    26  			t.Errorf("ishex(%v) == %v, expected %v", test.input, actual, test.ishex)
    27  		}
    28  		if actual := unhex(test.input); actual != test.unhex {
    29  			t.Errorf("unhex(%v) == %v, expected %v", test.input, actual, test.unhex)
    30  		}
    31  	}
    32  }
    33  
    34  var UnescapeTests = []struct {
    35  	input  string
    36  	err    error
    37  	output string
    38  }{
    39  	{"hello", nil, "hello"},
    40  	{"file%20one%26two", nil, "file one&two"},
    41  	{"one/two%2fthree", nil, "one/two/three"},
    42  	{"this%20is%0not%valid", url.EscapeError("%0n"), ""},
    43  }
    44  
    45  func TestUnescape(t *testing.T) {
    46  	t.Parallel()
    47  
    48  	for _, test := range UnescapeTests {
    49  		if actual, err := unescape(test.input); err != test.err {
    50  			t.Errorf("unescape(%q) had err %v, expected %q", test.input, err, test.err)
    51  		} else if actual != test.output {
    52  			t.Errorf("unescape(%q) = %q, expected %q)", test.input, actual, test.output)
    53  		}
    54  	}
    55  }
    56  

View as plain text