hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

urls_test.go (1588B)

    1 // Copyright 2017 The Hugo Authors. All rights reserved.
    2 //
    3 // Licensed under the Apache License, Version 2.0 (the "License");
    4 // you may not use this file except in compliance with the License.
    5 // You may obtain a copy of the License at
    6 // http://www.apache.org/licenses/LICENSE-2.0
    7 //
    8 // Unless required by applicable law or agreed to in writing, software
    9 // distributed under the License is distributed on an "AS IS" BASIS,
   10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   11 // See the License for the specific language governing permissions and
   12 // limitations under the License.
   13 
   14 package urls
   15 
   16 import (
   17 	"net/url"
   18 	"testing"
   19 
   20 	"github.com/gohugoio/hugo/config"
   21 
   22 	"github.com/gohugoio/hugo/htesting/hqt"
   23 
   24 	qt "github.com/frankban/quicktest"
   25 	"github.com/gohugoio/hugo/deps"
   26 )
   27 
   28 var ns = New(&deps.Deps{Cfg: config.New()})
   29 
   30 type tstNoStringer struct{}
   31 
   32 func TestParse(t *testing.T) {
   33 	t.Parallel()
   34 	c := qt.New(t)
   35 
   36 	for _, test := range []struct {
   37 		rawurl any
   38 		expect any
   39 	}{
   40 		{
   41 			"http://www.google.com",
   42 			&url.URL{
   43 				Scheme: "http",
   44 				Host:   "www.google.com",
   45 			},
   46 		},
   47 		{
   48 			"http://j@ne:password@google.com",
   49 			&url.URL{
   50 				Scheme: "http",
   51 				User:   url.UserPassword("j@ne", "password"),
   52 				Host:   "google.com",
   53 			},
   54 		},
   55 		// errors
   56 		{tstNoStringer{}, false},
   57 	} {
   58 
   59 		result, err := ns.Parse(test.rawurl)
   60 
   61 		if b, ok := test.expect.(bool); ok && !b {
   62 			c.Assert(err, qt.Not(qt.IsNil))
   63 			continue
   64 		}
   65 
   66 		c.Assert(err, qt.IsNil)
   67 		c.Assert(result,
   68 			qt.CmpEquals(hqt.DeepAllowUnexported(&url.URL{}, url.Userinfo{})), test.expect)
   69 	}
   70 }