mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
42757a2a5a
* #105 Added ELEMENTS_COUNT function * Some minor updates * Invalid return type
420 lines
23 KiB
Go
420 lines
23 KiB
Go
package static_test
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/MontFerret/ferret/pkg/html/static"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
"github.com/PuerkitoBio/goquery"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
"testing"
|
|
)
|
|
|
|
func TestElement(t *testing.T) {
|
|
doc := `
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<meta name="description" content="">
|
|
<meta name="author" content="">
|
|
<link rel="icon" href="../../../../favicon.ico">
|
|
|
|
<title>Album example for Bootstrap</title>
|
|
|
|
<!-- Bootstrap core CSS -->
|
|
<link href="../../dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
<!-- Custom styles for this template -->
|
|
<link href="album.css" rel="stylesheet">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<header>
|
|
<div class="collapse bg-dark" id="navbarHeader">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-sm-8 col-md-7 py-4">
|
|
<h4 class="text-white">About</h4>
|
|
<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>
|
|
</div>
|
|
<div class="col-sm-4 offset-md-1 py-4">
|
|
<h4 class="text-white">Contact</h4>
|
|
<ul class="list-unstyled">
|
|
<li><a href="#" class="text-white">Follow on Twitter</a></li>
|
|
<li><a href="#" class="text-white">Like on Facebook</a></li>
|
|
<li><a href="#" class="text-white">Email me</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="navbar navbar-dark bg-dark shadow-sm">
|
|
<div class="container d-flex justify-content-between">
|
|
<a href="#" class="navbar-brand d-flex align-items-center">
|
|
<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>
|
|
<strong>Album</strong>
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main role="main">
|
|
|
|
<section class="jumbotron text-center">
|
|
<div class="container">
|
|
<h1 class="jumbotron-heading">Album example</h1>
|
|
<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>
|
|
<p>
|
|
<a href="#" class="btn btn-primary my-2">Main call to action</a>
|
|
<a href="#" class="btn btn-secondary my-2">Secondary action</a>
|
|
</p>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="album py-5 bg-light">
|
|
<div class="container">
|
|
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card mb-4 shadow-sm">
|
|
<img class="card-img-top" data-src="holder.js/100px225?theme=thumb&bg=55595c&fg=eceeef&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;">
|
|
<div class="card-body">
|
|
<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>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</div>
|
|
<small class="text-muted">9 mins</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</main>
|
|
|
|
<footer class="text-muted">
|
|
<div class="container">
|
|
<p class="float-right">
|
|
<a href="#">Back to top</a>
|
|
</p>
|
|
<p>Album example is © Bootstrap, but please download and customize it for yourself!</p>
|
|
<p>New to Bootstrap? <a href="../../">Visit the homepage</a> or read our <a href="../../getting-started/">getting started guide</a>.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<!-- Bootstrap core JavaScript
|
|
================================================== -->
|
|
<!-- Placed at the end of the document so the pages load faster -->
|
|
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
|
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
|
|
<script src="../../assets/js/vendor/popper.min.js"></script>
|
|
<script src="../../dist/js/bootstrap.min.js"></script>
|
|
<script src="../../assets/js/vendor/holder.min.js"></script>
|
|
<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>
|
|
`
|
|
|
|
Convey(".NodeType", t, func() {
|
|
buff := bytes.NewBuffer([]byte(doc))
|
|
|
|
buff.Write([]byte(doc))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Find("body"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(el.NodeType(), ShouldEqual, 1)
|
|
})
|
|
|
|
Convey(".NodeName", t, func() {
|
|
buff := bytes.NewBuffer([]byte(doc))
|
|
|
|
buff.Write([]byte(doc))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Find("body"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(el.NodeName(), ShouldEqual, "body")
|
|
})
|
|
|
|
Convey(".Length", t, func() {
|
|
buff := bytes.NewBuffer([]byte(`
|
|
<html>
|
|
<head></head>
|
|
<body>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
</body>
|
|
</html>
|
|
`))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Find("body"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(el.Length(), ShouldEqual, 4)
|
|
})
|
|
|
|
Convey(".Value", t, func() {
|
|
buff := bytes.NewBuffer([]byte(`
|
|
<html>
|
|
<head></head>
|
|
<body>
|
|
<input id="q" value="find" />
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
</body>
|
|
</html>
|
|
`))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Find("#q"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
v := el.Value()
|
|
|
|
So(v, ShouldEqual, "find")
|
|
})
|
|
|
|
Convey(".InnerText", t, func() {
|
|
buff := bytes.NewBuffer([]byte(`
|
|
<html>
|
|
<head></head>
|
|
<body>
|
|
<h2>Ferret</h2>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
</body>
|
|
</html>
|
|
`))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Find("h2"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
v := el.InnerText()
|
|
|
|
So(v, ShouldEqual, "Ferret")
|
|
})
|
|
|
|
Convey(".InnerHtml", t, func() {
|
|
buff := bytes.NewBuffer([]byte(`
|
|
<html>
|
|
<head></head>
|
|
<body>
|
|
<div id="content"><h2>Ferret</h2></div>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
</body>
|
|
</html>
|
|
`))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Find("#content"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
v := el.InnerHTML()
|
|
|
|
So(v, ShouldEqual, "<h2>Ferret</h2>")
|
|
})
|
|
|
|
Convey(".QuerySelector", t, func() {
|
|
buff := bytes.NewBuffer([]byte(doc))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Selection)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
found := el.QuerySelector(values.NewString("body .card-img-top:nth-child(1)"))
|
|
|
|
So(found, ShouldNotEqual, values.None)
|
|
|
|
v := found.(values.HTMLNode).NodeName()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(v, ShouldEqual, "img")
|
|
})
|
|
|
|
Convey(".CountBySelector", t, func() {
|
|
buff := bytes.NewBuffer([]byte(doc))
|
|
|
|
doc, err := goquery.NewDocumentFromReader(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
el, err := static.NewHTMLElement(doc.Selection)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
v := el.CountBySelector(values.NewString("head meta"))
|
|
|
|
So(v, ShouldEqual, 4)
|
|
})
|
|
}
|