github.com/MontFerret/ferret@v0.18.0/pkg/drivers/http/element_test.go (about)

     1  package http_test
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"testing"
     7  
     8  	"github.com/PuerkitoBio/goquery"
     9  	. "github.com/smartystreets/goconvey/convey"
    10  
    11  	"github.com/MontFerret/ferret/pkg/drivers"
    12  	"github.com/MontFerret/ferret/pkg/drivers/http"
    13  	"github.com/MontFerret/ferret/pkg/runtime/values"
    14  	"github.com/MontFerret/ferret/pkg/runtime/values/types"
    15  )
    16  
    17  func TestElement(t *testing.T) {
    18  	doc := `
    19  <html lang="en"><head>
    20      <meta charset="utf-8">
    21      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    22      <meta name="description" content="">
    23      <meta name="author" content="">
    24      <link rel="icon" href="../../../../favicon.ico">
    25  
    26      <title>Album example for Bootstrap</title>
    27  
    28      <!-- Bootstrap core CSS -->
    29      <link href="../../dist/css/bootstrap.min.css" rel="stylesheet">
    30  
    31      <!-- Custom styles for this template -->
    32      <link href="album.css" rel="stylesheet">
    33    </head>
    34  
    35    <body>
    36  
    37      <header>
    38        <div class="collapse bg-dark" id="navbarHeader">
    39          <div class="container">
    40            <div class="row">
    41              <div class="col-sm-8 col-md-7 py-4">
    42                <h4 class="text-white">About</h4>
    43                <p class="text-muted">Add some information about the album below, the author, or any other background context. Make it a few sentences long so folks can pick up some informative tidbits. Then, link them off to some social networking sites or contact information.</p>
    44              </div>
    45              <div class="col-sm-4 offset-md-1 py-4">
    46                <h4 class="text-white">Contact</h4>
    47                <ul class="list-unstyled">
    48                  <li><a href="#" class="text-white">Follow on Twitter</a></li>
    49                  <li><a href="#" class="text-white">Like on Facebook</a></li>
    50                  <li><a href="#" class="text-white">Email me</a></li>
    51                </ul>
    52              </div>
    53            </div>
    54          </div>
    55        </div>
    56        <div class="navbar navbar-dark bg-dark shadow-sm">
    57          <div class="container d-flex justify-content-between">
    58            <a href="#" class="navbar-brand d-flex align-items-center">
    59              <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>
    60              <strong>Album</strong>
    61            </a>
    62            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
    63              <span class="navbar-toggler-icon"></span>
    64            </button>
    65          </div>
    66        </div>
    67      </header>
    68  
    69      <main role="main">
    70  
    71        <section class="jumbotron text-center">
    72          <div class="container">
    73            <h1 class="jumbotron-heading">Album example</h1>
    74            <p class="lead text-muted">Something short and leading about the collection below—its contents, the creator, etc. Make it short and sweet, but not too short so folks don't simply skip over it entirely.</p>
    75            <p>
    76              <a href="#" class="btn btn-primary my-2">Main call to action</a>
    77              <a href="#" class="btn btn-secondary my-2">Secondary action</a>
    78            </p>
    79          </div>
    80        </section>
    81  
    82        <div class="album py-5 bg-light">
    83          <div class="container">
    84  
    85            <div class="row">
    86              <div class="col-md-4">
    87                <div class="card mb-4 shadow-sm">
    88                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" style="height: 225px; width: 100%; display: block;" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea5071fe%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea5071fe%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true">
    89                  <div class="card-body">
    90                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    91                    <div class="d-flex justify-content-between align-items-center">
    92                      <div class="btn-group">
    93                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
    94                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
    95                      </div>
    96                      <small class="text-muted">9 mins</small>
    97                    </div>
    98                  </div>
    99                </div>
   100              </div>
   101              <div class="col-md-4">
   102                <div class="card mb-4 shadow-sm">
   103                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea5071fe%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea5071fe%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   104                  <div class="card-body">
   105                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   106                    <div class="d-flex justify-content-between align-items-center">
   107                      <div class="btn-group">
   108                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   109                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   110                      </div>
   111                      <small class="text-muted">9 mins</small>
   112                    </div>
   113                  </div>
   114                </div>
   115              </div>
   116              <div class="col-md-4">
   117                <div class="card mb-4 shadow-sm">
   118                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507200%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507200%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   119                  <div class="card-body">
   120                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   121                    <div class="d-flex justify-content-between align-items-center">
   122                      <div class="btn-group">
   123                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   124                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   125                      </div>
   126                      <small class="text-muted">9 mins</small>
   127                    </div>
   128                  </div>
   129                </div>
   130              </div>
   131  
   132              <div class="col-md-4">
   133                <div class="card mb-4 shadow-sm">
   134                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507200%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507200%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   135                  <div class="card-body">
   136                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   137                    <div class="d-flex justify-content-between align-items-center">
   138                      <div class="btn-group">
   139                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   140                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   141                      </div>
   142                      <small class="text-muted">9 mins</small>
   143                    </div>
   144                  </div>
   145                </div>
   146              </div>
   147              <div class="col-md-4">
   148                <div class="card mb-4 shadow-sm">
   149                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507201%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507201%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   150                  <div class="card-body">
   151                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   152                    <div class="d-flex justify-content-between align-items-center">
   153                      <div class="btn-group">
   154                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   155                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   156                      </div>
   157                      <small class="text-muted">9 mins</small>
   158                    </div>
   159                  </div>
   160                </div>
   161              </div>
   162              <div class="col-md-4">
   163                <div class="card mb-4 shadow-sm">
   164                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507202%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507202%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   165                  <div class="card-body">
   166                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   167                    <div class="d-flex justify-content-between align-items-center">
   168                      <div class="btn-group">
   169                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   170                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   171                      </div>
   172                      <small class="text-muted">9 mins</small>
   173                    </div>
   174                  </div>
   175                </div>
   176              </div>
   177  
   178              <div class="col-md-4">
   179                <div class="card mb-4 shadow-sm">
   180                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507203%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507203%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   181                  <div class="card-body">
   182                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   183                    <div class="d-flex justify-content-between align-items-center">
   184                      <div class="btn-group">
   185                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   186                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   187                      </div>
   188                      <small class="text-muted">9 mins</small>
   189                    </div>
   190                  </div>
   191                </div>
   192              </div>
   193              <div class="col-md-4">
   194                <div class="card mb-4 shadow-sm">
   195                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507203%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507203%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   196                  <div class="card-body">
   197                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   198                    <div class="d-flex justify-content-between align-items-center">
   199                      <div class="btn-group">
   200                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   201                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   202                      </div>
   203                      <small class="text-muted">9 mins</small>
   204                    </div>
   205                  </div>
   206                </div>
   207              </div>
   208              <div class="col-md-4">
   209                <div class="card mb-4 shadow-sm">
   210                  <img class="card-img-top" data-src="holder.js/100px225?theme=thumb&amp;bg=55595c&amp;fg=eceeef&amp;text=Thumbnail" alt="Thumbnail [100%x225]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22348%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20348%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_165ea507203%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A17pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_165ea507203%22%3E%3Crect%20width%3D%22348%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22116.71875%22%20y%3D%22120.15%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-holder-rendered="true" style="height: 225px; width: 100%; display: block;">
   211                  <div class="card-body">
   212                    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
   213                    <div class="d-flex justify-content-between align-items-center">
   214                      <div class="btn-group">
   215                        <button type="button" class="btn btn-sm btn-outline-secondary">View</button>
   216                        <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
   217                      </div>
   218                      <small class="text-muted">9 mins</small>
   219                    </div>
   220                  </div>
   221                </div>
   222              </div>
   223            </div>
   224          </div>
   225        </div>
   226  
   227      </main>
   228  
   229      <footer class="text-muted">
   230        <div class="container">
   231          <p class="float-right">
   232            <a href="#">Back to top</a>
   233          </p>
   234          <p>Album example is © Bootstrap, but please download and customize it for yourself!</p>
   235          <p>New to Bootstrap? <a href="../../">Visit the homepage</a> or read our <a href="../../getting-started/">getting started guide</a>.</p>
   236        </div>
   237      </footer>
   238  
   239      <!-- Bootstrap core JavaScript
   240      ================================================== -->
   241      <!-- Placed at the end of the document so the pages load faster -->
   242      <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
   243      <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
   244      <script src="../../assets/js/vendor/popper.min.js"></script>
   245      <script src="../../dist/js/bootstrap.min.js"></script>
   246      <script src="../../assets/js/vendor/holder.min.js"></script>
   247  	<svg xmlns="http://www.w3.org/2000/svg" width="348" height="225" viewBox="0 0 348 225" preserveAspectRatio="none" style="display: none; visibility: hidden; position: absolute; top: -100%; left: -100%;"><defs><style type="text/css"></style></defs><text x="0" y="17" style="font-weight:bold;font-size:17pt;font-family:Arial, Helvetica, Open Sans, sans-serif">Thumbnail</text></svg></body></html>
   248  `
   249  
   250  	Convey(".GetNodeType", t, func() {
   251  		buff := bytes.NewBuffer([]byte(doc))
   252  
   253  		buff.Write([]byte(doc))
   254  
   255  		doc, err := goquery.NewDocumentFromReader(buff)
   256  
   257  		So(err, ShouldBeNil)
   258  
   259  		el, err := http.NewHTMLElement(doc.Find("body"))
   260  
   261  		So(err, ShouldBeNil)
   262  
   263  		nt, err := el.GetNodeType(context.Background())
   264  
   265  		So(err, ShouldBeNil)
   266  		So(nt, ShouldEqual, 1)
   267  	})
   268  
   269  	Convey(".GetNodeName", t, func() {
   270  		buff := bytes.NewBuffer([]byte(doc))
   271  
   272  		buff.Write([]byte(doc))
   273  
   274  		doc, err := goquery.NewDocumentFromReader(buff)
   275  
   276  		So(err, ShouldBeNil)
   277  
   278  		el, err := http.NewHTMLElement(doc.Find("body"))
   279  
   280  		So(err, ShouldBeNil)
   281  
   282  		nn, err := el.GetNodeName(context.Background())
   283  
   284  		So(err, ShouldBeNil)
   285  		So(nn, ShouldEqual, "body")
   286  	})
   287  
   288  	Convey(".Length", t, func() {
   289  		buff := bytes.NewBuffer([]byte(`
   290  			<html>
   291  				<head></head>
   292  				<body>
   293  					<span></span>
   294  					<span></span>
   295  					<span></span>
   296  					<span></span>
   297  				</body>
   298  			</html>
   299  		`))
   300  
   301  		doc, err := goquery.NewDocumentFromReader(buff)
   302  
   303  		So(err, ShouldBeNil)
   304  
   305  		el, err := http.NewHTMLElement(doc.Find("body"))
   306  
   307  		So(err, ShouldBeNil)
   308  
   309  		So(el.Length(), ShouldEqual, 4)
   310  	})
   311  
   312  	Convey(".Value", t, func() {
   313  		buff := bytes.NewBuffer([]byte(`
   314  			<html>
   315  				<head></head>
   316  				<body>
   317  					<input id="q" value="find" />
   318  					<span></span>
   319  					<span></span>
   320  					<span></span>
   321  					<span></span>
   322  				</body>
   323  			</html>
   324  		`))
   325  
   326  		doc, err := goquery.NewDocumentFromReader(buff)
   327  
   328  		So(err, ShouldBeNil)
   329  
   330  		el, err := http.NewHTMLElement(doc.Find("#q"))
   331  
   332  		So(err, ShouldBeNil)
   333  
   334  		v, err := el.GetValue(context.Background())
   335  
   336  		So(err, ShouldBeNil)
   337  		So(v, ShouldEqual, "find")
   338  	})
   339  
   340  	Convey(".GetInnerText", t, func() {
   341  		buff := bytes.NewBuffer([]byte(`
   342  			<html>
   343  				<head></head>
   344  				<body>
   345  					<h2>Ferret</h2>
   346  					<span></span>
   347  					<span></span>
   348  					<span></span>
   349  					<span></span>
   350  				</body>
   351  			</html>
   352  		`))
   353  
   354  		doc, err := goquery.NewDocumentFromReader(buff)
   355  
   356  		So(err, ShouldBeNil)
   357  
   358  		el, err := http.NewHTMLElement(doc.Find("h2"))
   359  
   360  		So(err, ShouldBeNil)
   361  
   362  		v, _ := el.GetInnerText(context.Background())
   363  
   364  		So(v, ShouldEqual, "Ferret")
   365  	})
   366  
   367  	Convey(".InnerHtml", t, func() {
   368  		buff := bytes.NewBuffer([]byte(`
   369  			<html>
   370  				<head></head>
   371  				<body>
   372  					<div id="content"><h2>Ferret</h2></div>
   373  					<span></span>
   374  					<span></span>
   375  					<span></span>
   376  					<span></span>
   377  				</body>
   378  			</html>
   379  		`))
   380  
   381  		doc, err := goquery.NewDocumentFromReader(buff)
   382  
   383  		So(err, ShouldBeNil)
   384  
   385  		el, err := http.NewHTMLElement(doc.Find("#content"))
   386  
   387  		So(err, ShouldBeNil)
   388  
   389  		v, err := el.GetInnerHTML(context.Background())
   390  
   391  		So(err, ShouldBeNil)
   392  		So(v, ShouldEqual, "<h2>Ferret</h2>")
   393  	})
   394  
   395  	Convey(".QuerySelector", t, func() {
   396  		buff := bytes.NewBuffer([]byte(doc))
   397  
   398  		doc, err := goquery.NewDocumentFromReader(buff)
   399  
   400  		So(err, ShouldBeNil)
   401  
   402  		el, err := http.NewHTMLElement(doc.Selection)
   403  
   404  		So(err, ShouldBeNil)
   405  
   406  		found, err := el.QuerySelector(context.Background(), drivers.NewCSSSelector("body .card-img-top:nth-child(1)"))
   407  
   408  		So(err, ShouldBeNil)
   409  		So(found, ShouldNotEqual, values.None)
   410  
   411  		v, err := found.(drivers.HTMLNode).GetNodeName(context.Background())
   412  
   413  		So(err, ShouldBeNil)
   414  		So(v, ShouldEqual, "img")
   415  	})
   416  
   417  	Convey(".CountBySelector", t, func() {
   418  		buff := bytes.NewBuffer([]byte(doc))
   419  
   420  		doc, err := goquery.NewDocumentFromReader(buff)
   421  
   422  		So(err, ShouldBeNil)
   423  
   424  		el, err := http.NewHTMLElement(doc.Selection)
   425  
   426  		So(err, ShouldBeNil)
   427  
   428  		v, err := el.CountBySelector(context.Background(), drivers.NewCSSSelector("head meta"))
   429  
   430  		So(err, ShouldBeNil)
   431  		So(v, ShouldEqual, 4)
   432  	})
   433  
   434  	Convey(".XPath", t, func() {
   435  		Convey("Text nodes", func() {
   436  			buff := bytes.NewBuffer([]byte(doc))
   437  
   438  			buff.Write([]byte(doc))
   439  
   440  			doc, err := goquery.NewDocumentFromReader(buff)
   441  
   442  			So(err, ShouldBeNil)
   443  
   444  			el, err := http.NewHTMLElement(doc.Find("html"))
   445  
   446  			So(err, ShouldBeNil)
   447  
   448  			nt, err := el.XPath(context.Background(), values.NewString("/head/title/text()"))
   449  
   450  			So(err, ShouldBeNil)
   451  			So(nt.String(), ShouldEqual, "[\"Album example for Bootstrap\"]")
   452  		})
   453  
   454  		Convey("Func", func() {
   455  			buff := bytes.NewBuffer([]byte(doc))
   456  
   457  			buff.Write([]byte(doc))
   458  
   459  			doc, err := goquery.NewDocumentFromReader(buff)
   460  
   461  			So(err, ShouldBeNil)
   462  
   463  			el, err := http.NewHTMLElement(doc.Find("html"))
   464  
   465  			So(err, ShouldBeNil)
   466  
   467  			nt, err := el.XPath(context.Background(), values.NewString("count(//div)"))
   468  
   469  			So(err, ShouldBeNil)
   470  			So(nt.Type().String(), ShouldEqual, types.Float.String())
   471  		})
   472  
   473  		Convey("Attributes", func() {
   474  			buff := bytes.NewBuffer([]byte(`<!DOCTYPE html><body><div><a title="30"/></div></body></html>`))
   475  			godoc, err := goquery.NewDocumentFromReader(buff)
   476  			So(err, ShouldBeNil)
   477  
   478  			doc, err := http.NewRootHTMLDocument(godoc, "localhost:9090")
   479  			So(err, ShouldBeNil)
   480  
   481  			nt, err := doc.XPath(context.Background(), values.NewString("//a/@title"))
   482  
   483  			So(err, ShouldBeNil)
   484  			So(nt.Type().String(), ShouldEqual, types.Array.String())
   485  			So(nt.(*values.Array).First().Type().String(), ShouldEqual, types.String.String())
   486  			So(nt.(*values.Array).First().String(), ShouldEqual, "30")
   487  		})
   488  
   489  		Convey("Element node", func() {
   490  			buff := bytes.NewBuffer([]byte(`<!DOCTYPE html><body><div><a title="30"/></div></body></html>`))
   491  			godoc, err := goquery.NewDocumentFromReader(buff)
   492  			So(err, ShouldBeNil)
   493  
   494  			doc, err := http.NewRootHTMLDocument(godoc, "localhost:9090")
   495  			So(err, ShouldBeNil)
   496  
   497  			nt, err := doc.XPath(context.Background(), values.NewString("//div"))
   498  
   499  			So(err, ShouldBeNil)
   500  			So(nt.Type().String(), ShouldEqual, types.Array.String())
   501  			So(nt.(*values.Array).First().Type().String(), ShouldEqual, drivers.HTMLElementType.String())
   502  		})
   503  	})
   504  }