`
+ d, err := NewDocumentFromReader(strings.NewReader(src))
+ if err != nil {
+ t.Fatal(err)
+ }
+ txt := d.Find("p").Text()
+ ix := strings.Index(txt, "\u00a0")
+ if ix != 4 {
+ t.Errorf("Text: expected a non-breaking space at index 4, got %d", ix)
+ }
+
+ h, err := d.Find("p").Html()
+ if err != nil {
+ t.Fatal(err)
+ }
+ ix = strings.Index(h, "\u00a0")
+ if ix != 4 {
+ t.Errorf("Html: expected a non-breaking space at index 4, got %d", ix)
+ }
+}
+
+func TestAddClass(t *testing.T) {
+ sel := Doc2Clone().Find("#main")
+ sel.AddClass("main main main")
+
+ // Make sure that class was only added once
+ if a, ok := sel.Attr("class"); !ok || a != "main" {
+ t.Error("Expected #main to have class main")
+ }
+}
+
+func TestAddClassSimilar(t *testing.T) {
+ sel := Doc2Clone().Find("#nf5")
+ sel.AddClass("odd")
+
+ assertClass(t, sel, "odd")
+ assertClass(t, sel, "odder")
+ printSel(t, sel.Parent())
+}
+
+func TestAddEmptyClass(t *testing.T) {
+ sel := Doc2Clone().Find("#main")
+ sel.AddClass("")
+
+ // Make sure that class was only added once
+ if a, ok := sel.Attr("class"); ok {
+ t.Errorf("Expected #main to not to have a class, have: %s", a)
+ }
+}
+
+func TestAddClasses(t *testing.T) {
+ sel := Doc2Clone().Find("#main")
+ sel.AddClass("a b")
+
+ // Make sure that class was only added once
+ if !sel.HasClass("a") || !sel.HasClass("b") {
+ t.Errorf("#main does not have classes")
+ }
+}
+
+func TestHasClass(t *testing.T) {
+ sel := Doc().Find("div")
+ if !sel.HasClass("span12") {
+ t.Error("Expected at least one div to have class span12.")
+ }
+}
+
+func TestHasClassNone(t *testing.T) {
+ sel := Doc().Find("h2")
+ if sel.HasClass("toto") {
+ t.Error("Expected h1 to have no class.")
+ }
+}
+
+func TestHasClassNotFirst(t *testing.T) {
+ sel := Doc().Find(".alert")
+ if !sel.HasClass("alert-error") {
+ t.Error("Expected .alert to also have class .alert-error.")
+ }
+}
+
+func TestRemoveClass(t *testing.T) {
+ sel := Doc2Clone().Find("#nf1")
+ sel.RemoveClass("one row")
+
+ if !sel.HasClass("even") || sel.HasClass("one") || sel.HasClass("row") {
+ classes, _ := sel.Attr("class")
+ t.Error("Expected #nf1 to have class even, has ", classes)
+ }
+}
+
+func TestRemoveClassSimilar(t *testing.T) {
+ sel := Doc2Clone().Find("#nf5, #nf6")
+ assertLength(t, sel.Nodes, 2)
+
+ sel.RemoveClass("odd")
+ assertClass(t, sel.Eq(0), "odder")
+ printSel(t, sel)
+}
+
+func TestRemoveAllClasses(t *testing.T) {
+ sel := Doc2Clone().Find("#nf1")
+ sel.RemoveClass()
+
+ if a, ok := sel.Attr("class"); ok {
+ t.Error("All classes were not removed, has ", a)
+ }
+
+ sel = Doc2Clone().Find("#main")
+ sel.RemoveClass()
+ if a, ok := sel.Attr("class"); ok {
+ t.Error("All classes were not removed, has ", a)
+ }
+}
+
+func TestToggleClass(t *testing.T) {
+ sel := Doc2Clone().Find("#nf1")
+
+ sel.ToggleClass("one")
+ if sel.HasClass("one") {
+ t.Error("Expected #nf1 to not have class one")
+ }
+
+ sel.ToggleClass("one")
+ if !sel.HasClass("one") {
+ t.Error("Expected #nf1 to have class one")
+ }
+
+ sel.ToggleClass("one even row")
+ if a, ok := sel.Attr("class"); ok {
+ t.Errorf("Expected #nf1 to have no classes, have %q", a)
+ }
+}
diff --git a/vendor/github.com/PuerkitoBio/goquery/query_test.go b/vendor/github.com/PuerkitoBio/goquery/query_test.go
new file mode 100644
index 00000000..2f40f424
--- /dev/null
+++ b/vendor/github.com/PuerkitoBio/goquery/query_test.go
@@ -0,0 +1,96 @@
+package goquery
+
+import (
+ "testing"
+)
+
+func TestIs(t *testing.T) {
+ sel := Doc().Find(".footer p:nth-child(1)")
+ if !sel.Is("p") {
+ t.Error("Expected .footer p:nth-child(1) to be p.")
+ }
+}
+
+func TestIsPositional(t *testing.T) {
+ sel := Doc().Find(".footer p:nth-child(2)")
+ if !sel.Is("p:nth-child(2)") {
+ t.Error("Expected .footer p:nth-child(2) to be p:nth-child(2).")
+ }
+}
+
+func TestIsPositionalNot(t *testing.T) {
+ sel := Doc().Find(".footer p:nth-child(1)")
+ if sel.Is("p:nth-child(2)") {
+ t.Error("Expected .footer p:nth-child(1) NOT to be p:nth-child(2).")
+ }
+}
+
+func TestIsFunction(t *testing.T) {
+ ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
+ return s.HasClass("container-fluid")
+ })
+
+ if !ok {
+ t.Error("Expected some div to have a container-fluid class.")
+ }
+}
+
+func TestIsFunctionRollback(t *testing.T) {
+ ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
+ return s.HasClass("container-fluid")
+ })
+
+ if !ok {
+ t.Error("Expected some div to have a container-fluid class.")
+ }
+}
+
+func TestIsSelection(t *testing.T) {
+ sel := Doc().Find("div")
+ sel2 := Doc().Find(".pvk-gutter")
+
+ if !sel.IsSelection(sel2) {
+ t.Error("Expected some div to have a pvk-gutter class.")
+ }
+}
+
+func TestIsSelectionNot(t *testing.T) {
+ sel := Doc().Find("div")
+ sel2 := Doc().Find("a")
+
+ if sel.IsSelection(sel2) {
+ t.Error("Expected some div NOT to be an anchor.")
+ }
+}
+
+func TestIsNodes(t *testing.T) {
+ sel := Doc().Find("div")
+ sel2 := Doc().Find(".footer")
+
+ if !sel.IsNodes(sel2.Nodes[0]) {
+ t.Error("Expected some div to have a footer class.")
+ }
+}
+
+func TestDocContains(t *testing.T) {
+ sel := Doc().Find("h1")
+ if !Doc().Contains(sel.Nodes[0]) {
+ t.Error("Expected document to contain H1 tag.")
+ }
+}
+
+func TestSelContains(t *testing.T) {
+ sel := Doc().Find(".row-fluid")
+ sel2 := Doc().Find("a[ng-click]")
+ if !sel.Contains(sel2.Nodes[0]) {
+ t.Error("Expected .row-fluid to contain a[ng-click] tag.")
+ }
+}
+
+func TestSelNotContains(t *testing.T) {
+ sel := Doc().Find("a.link")
+ sel2 := Doc().Find("span")
+ if sel.Contains(sel2.Nodes[0]) {
+ t.Error("Expected a.link to NOT contain span tag.")
+ }
+}
diff --git a/vendor/github.com/PuerkitoBio/goquery/testdata/gotesting.html b/vendor/github.com/PuerkitoBio/goquery/testdata/gotesting.html
new file mode 100644
index 00000000..ba5348fd
--- /dev/null
+++ b/vendor/github.com/PuerkitoBio/goquery/testdata/gotesting.html
@@ -0,0 +1,855 @@
+
+
+
+
+
+ testing - The Go Programming Language
+
+
+
+
+
+
+
+
+
+
+
+Package testing provides support for automated testing of Go packages.
+It is intended to be used in concert with the “go test” command, which automates
+execution of any function of the form
+
+
func TestXxx(*testing.T)
+
+
+where Xxx can be any alphanumeric string (but the first letter must not be in
+[a-z]) and serves to identify the test routine.
+These TestXxx routines should be declared within the package they are testing.
+
+
+Functions of the form
+
+
func BenchmarkXxx(*testing.B)
+
+
+are considered benchmarks, and are executed by the "go test" command when
+the -test.bench flag is provided.
+
+
+A sample benchmark function looks like this:
+
+
func BenchmarkHello(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ fmt.Sprintf("hello")
+ }
+}
+
+
+The benchmark package will vary b.N until the benchmark function lasts
+long enough to be timed reliably. The output
+
+
testing.BenchmarkHello 10000000 282 ns/op
+
+
+means that the loop ran 10000000 times at a speed of 282 ns per loop.
+
+
+If a benchmark needs some expensive setup before running, the timer
+may be stopped:
+
+
func BenchmarkBigLen(b *testing.B) {
+ b.StopTimer()
+ big := NewBig()
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ big.Len()
+ }
+}
+
+
+The package also runs and verifies example code. Example functions may
+include a concluding comment that begins with "Output:" and is compared with
+the standard output of the function when the tests are run, as in these
+examples of an example:
+
+Multiple example functions for a type/function/method may be provided by
+appending a distinct suffix to the name. The suffix must start with a
+lower-case letter.
+
+The entire test file is presented as the example when it contains a single
+example function, at least one other function, type, variable, or constant
+declaration, and no test or benchmark functions.
+
+StartTimer starts timing a test. This function is called automatically
+before a benchmark starts, but it can also used to resume timing after
+a call to StopTimer.
+
type BenchmarkResult struct {
+ N int // The number of iterations.
+ T time.Duration // The total time taken.
+ Bytes int64 // Bytes processed in one iteration.
+}
type T struct {
+ // contains filtered or unexported fields
+}
+
+T is a type passed to Test functions to manage test state and support formatted test logs.
+Logs are accumulated during execution and dumped to standard error when done.
+
The syntax of Go is broadly similar to that of C: blocks of code are surrounded with curly braces; common control flow structures include for, switch, and if. Unlike C, line-ending semicolons are optional, variable declarations are written differently and are usually optional, type conversions must be made explicit, and new go and select control keywords have been introduced to support concurrent programming. New built-in types include maps, Unicode strings, array slices, and channels for inter-thread communication.
+
Go is designed for exceptionally fast compiling times, even on modest hardware.[10] The language requires garbage collection. Certain concurrency-related structural conventions of Go (channels and alternative channel inputs) are borrowed from Tony Hoare'sCSP. Unlike previous concurrent programming languages such as occam or Limbo, Go does not provide any built-in notion of safe or verifiable concurrency.[11]
+
Of features found in C++ or Java, Go does not include type inheritance, generic programming, assertions, method overloading, or pointer arithmetic.[2] Of these, the Go authors express an openness to generic programming, explicitly argue against assertions and pointer arithmetic, while defending the choice to omit type inheritance as giving a more useful language, encouraging heavy use of interfaces instead.[2] Initially, the language did not include exception handling, but in March 2010 a mechanism known as panic/recover was implemented to handle exceptional errors while avoiding some of the problems the Go authors find with exceptions.[12][13]
Go allows a programmer to write functions that can operate on inputs of arbitrary type, provided that the type implements the functions defined by a given interface.
+
Unlike Java, the interfaces a type supports do not need to be specified at the point at which the type is defined, and Go interfaces do not participate in a type hierarchy. A Go interface is best described as a set of methods, each identified by a name and signature. A type is considered to implement an interface if all the required methods have been defined for that type. An interface can be declared to "embed" other interfaces, meaning the declared interface includes the methods defined in the other interfaces.[11]
+
Unlike Java, the in-memory representation of an object does not contain a pointer to a virtual method table. Instead a value of interface type is implemented as a pair of a pointer to the object, and a pointer to a dictionary containing implementations of the interface methods for that type.
These four definitions could have been placed in separate files, in different parts of the program. Notably, the programmer who defined the Sequence type did not need to declare that the type implemented HasLength, and the person who implemented the Len method for Sequence did not need to specify that this method was part of HasLength.
Visibility of structures, structure fields, variables, constants, methods, top-level types and functions outside their defining package is defined implicitly according to the capitalization of their identifier.[14]
Go provides goroutines, small lightweight threads; the name alludes to coroutines. Goroutines are created with the go statement from anonymous or named functions.
+
Goroutines are executed in parallel with other goroutines, including their caller. They do not necessarily run in separate threads, but a group of goroutines are multiplexed onto multiple threads — execution control is moved between them by blocking them when sending or receiving messages over channels.
6g/8g/5g (the compilers for AMD64, x86, and ARM respectively) with their supporting tools (collectively known as "gc") based on Ken's previous work on Plan 9's C toolchain.
+
gccgo, a GCC frontend written in C++,[15] and now officially supported as of version 4.6, albeit not part of the standard binary for gcc.[16]
+
+
Both compilers work on Unix-like systems, and a port to Microsoft Windows of the gc compiler and runtime have been integrated in the main distribution. Most of the standard libraries also work on Windows.
+
There is also an unmaintained "tiny" runtime environment that allows Go programs to run on bare hardware.[17]
Go's automatic semicolon insertion feature requires that opening braces not be placed on their own lines, and this is thus the preferred brace style; the examples shown comply with this style.[18]
Michele Simionato wrote in an article for artima.com:[20]
+
+
Here I just wanted to point out the design choices about interfaces and inheritance. Such ideas are not new and it is a shame that no popular language has followed such particular route in the design space. I hope Go will become popular; if not, I hope such ideas will finally enter in a popular language, we are already 10 or 20 years too late :-(
Go is extremely easy to dive into. There are a minimal number of fundamental language concepts and the syntax is clean and designed to be clear and unambiguous. Go is still experimental and still a little rough around the edges.
+
+
Ars Technica interviewed Rob Pike, one of the authors of Go, and asked why a new language was needed. He replied that:[22]
+
+
It wasn't enough to just add features to existing programming languages, because sometimes you can get more in the long run by taking things away. They wanted to start from scratch and rethink everything. ... [But they did not want] to deviate too much from what developers already knew because they wanted to avoid alienating Go's target audience.
The complexity of C++ (even more complexity has been added in the new C++), and the resulting impact on productivity, is no longer justified. All the hoops that the C++ programmer had to jump through in order to use a C-compatible language make no sense anymore -- they're just a waste of time and effort. Now, Go makes much more sense for the class of problems that C++ was originally intended to solve.
On the day of the general release of the language, Francis McCabe, developer of the Go! programming language (note the exclamation point), requested a name change of Google's language to prevent confusion with his language.[25] The issue was closed by a Google developer on 12 October 2010 with the custom status "Unfortunate", with a comment that "there are many computing products and services named Go. In the 11 months since our release, there has been minimal confusion of the two languages."[26]
^"A Tutorial for the Go Programming Language". The Go Programming Language. Google. http://golang.org/doc/go_tutorial.html. Retrieved 10 March 2010. "In Go the rule about visibility of information is simple: if a name (of a top-level type, function, method, constant or variable, or of a structure field or method) is capitalized, users of the package may see it. Otherwise, the name and hence the thing being named is visible only inside the package in which it is declared."
^"A Tutorial for the Go Programming Language". The Go Programming Language. Google. http://golang.org/doc/go_tutorial.html. Retrieved 10 March 2010. "The one surprise is that it's important to put the opening brace of a construct such as an if statement on the same line as the if; however, if you don't, there are situations that may not compile or may give the wrong result. The language forces the brace style to some extent."