diff --git a/_meta/beat.yml b/_meta/beat.yml index 2619358..ad8881d 100644 --- a/_meta/beat.yml +++ b/_meta/beat.yml @@ -5,4 +5,4 @@ youtubebeat: # Defines how often an event is sent to the output period: 1s - start_url: "https://www.youtube.com/watch?v=SmBCZgcGlKk" + start_id: "SmBCZgcGlKk" diff --git a/_meta/fields.yml b/_meta/fields.yml index 56276e3..abd0c5a 100644 --- a/_meta/fields.yml +++ b/_meta/fields.yml @@ -2,8 +2,23 @@ title: youtubebeat description: fields: - - name: counter + - name: url + type: string + required: true + description: > + Video's full URL + - name: title + type: string + required: true + description: > + Video title + - name: views type: long required: true description: > - PLEASE UPDATE DOCUMENTATION + Video's view count + - name: date + type: string + required: true + description: > + Video's publish date diff --git a/_meta/kibana.generated/5/index-pattern/youtubebeat.json b/_meta/kibana.generated/5/index-pattern/youtubebeat.json index 48051e3..bf532db 100644 --- a/_meta/kibana.generated/5/index-pattern/youtubebeat.json +++ b/_meta/kibana.generated/5/index-pattern/youtubebeat.json @@ -1,6 +1,6 @@ { "fieldFormatMap": "{\"@timestamp\":{\"id\":\"date\"}}", - "fields": "[{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"counter\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.hostname\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.timezone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"@timestamp\",\"scripted\":false,\"searchable\":true,\"type\":\"date\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"tags\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"fields\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.message\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.code\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.provider\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.machine_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.availability_zone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.project_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.region\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.architecture\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.platform\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.family\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.ip\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.mac\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.uid\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.namespace\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.node.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.annotations\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_id\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_index\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_score\",\"scripted\":false,\"searchable\":false,\"type\":\"number\"}]", + "fields": "[{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"url\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"title\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"views\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"date\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.hostname\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.timezone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"@timestamp\",\"scripted\":false,\"searchable\":true,\"type\":\"date\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"tags\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"fields\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.message\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.code\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.provider\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.machine_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.availability_zone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.project_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.region\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.architecture\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.platform\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.family\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.ip\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.mac\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.uid\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.namespace\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.node.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.annotations\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_id\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_index\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_score\",\"scripted\":false,\"searchable\":false,\"type\":\"number\"}]", "timeFieldName": "@timestamp", "title": "youtubebeat-*" } \ No newline at end of file diff --git a/_meta/kibana.generated/6/index-pattern/youtubebeat.json b/_meta/kibana.generated/6/index-pattern/youtubebeat.json index d7c8600..084b923 100644 --- a/_meta/kibana.generated/6/index-pattern/youtubebeat.json +++ b/_meta/kibana.generated/6/index-pattern/youtubebeat.json @@ -3,7 +3,7 @@ { "attributes": { "fieldFormatMap": "{\"@timestamp\":{\"id\":\"date\"}}", - "fields": "[{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"counter\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.hostname\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.timezone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"@timestamp\",\"scripted\":false,\"searchable\":true,\"type\":\"date\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"tags\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"fields\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.message\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.code\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.provider\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.machine_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.availability_zone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.project_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.region\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.architecture\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.platform\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.family\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.ip\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.mac\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.uid\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.namespace\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.node.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.annotations\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_id\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_index\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_score\",\"scripted\":false,\"searchable\":false,\"type\":\"number\"}]", + "fields": "[{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"url\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"title\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"views\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"date\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.hostname\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.timezone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"beat.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"@timestamp\",\"scripted\":false,\"searchable\":true,\"type\":\"date\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"tags\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"fields\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.message\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.code\",\"scripted\":false,\"searchable\":true,\"type\":\"number\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"error.type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.provider\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.instance_name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.machine_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.availability_zone\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.project_id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"meta.cloud.region\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"docker.container.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.id\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.architecture\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.platform\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.version\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.os.family\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.ip\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"host.mac\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.pod.uid\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.namespace\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.node.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.labels\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.annotations\",\"scripted\":false,\"searchable\":true},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.name\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":true,\"indexed\":true,\"name\":\"kubernetes.container.image\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_id\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":true,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_type\",\"scripted\":false,\"searchable\":true,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_index\",\"scripted\":false,\"searchable\":false,\"type\":\"string\"},{\"aggregatable\":false,\"analyzed\":false,\"count\":0,\"doc_values\":false,\"indexed\":false,\"name\":\"_score\",\"scripted\":false,\"searchable\":false,\"type\":\"number\"}]", "timeFieldName": "@timestamp", "title": "youtubebeat-*" }, diff --git a/beater/youtubebeat.go b/beater/youtubebeat.go index 307fb15..bdade93 100644 --- a/beater/youtubebeat.go +++ b/beater/youtubebeat.go @@ -2,6 +2,9 @@ package beater import ( "fmt" + "github.com/gocolly/colly" + "strconv" + "strings" "time" "github.com/elastic/beats/libbeat/beat" @@ -32,6 +35,54 @@ func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) { return bt, nil } +func scrapeVideos(startId string, fieldsToSend chan common.MapStr) { + const BaseUrl = "https://www.youtube.com" + const BaseSuffix = "/watch?v=" + + videoCollector := colly.NewCollector( + colly.AllowedDomains("youtube.com", "www.youtube.com"), + colly.Async(true), + colly.MaxDepth(10), + ) + + videoCollector.OnHTML("body", func(e *colly.HTMLElement) { + url := e.Request.URL.String() + isPaid := e.ChildAttr("meta[itemprop=\"paid\"]", "content") + if isPaid == "True" { + logp.Err("Not parsing video because of isPaid" + url) + return + } + title := e.ChildAttr("meta[itemprop=\"name\"]", "content") + if title == "YouTube" { + logp.Err("Not parsing video because of title " + url) + return + } + views, err := strconv.ParseInt(e.ChildAttr("meta[itemprop=\"interactionCount\"]", "content"), 10, 64) + if err != nil { + logp.Err("Can't parse view count for URL " + url) + return + } + date := e.ChildAttr("meta[itemprop=\"datePublished\"]", "content") + fields := common.MapStr{ + "url": url, + "title": title, + "views": views, + "date": date, + } + fieldsToSend <- fields + }) + + videoCollector.OnHTML("a[href]", func(e *colly.HTMLElement) { + href := e.Attr("href") + if strings.HasPrefix(href, BaseSuffix) { + e.Request.Visit(BaseUrl + href) + } + }) + + videoCollector.Visit(BaseUrl + BaseSuffix + startId) + videoCollector.Wait() +} + // Run starts youtubebeat. func (bt *Youtubebeat) Run(b *beat.Beat) error { logp.Info("youtubebeat is running! Hit CTRL-C to stop it.") @@ -42,25 +93,24 @@ func (bt *Youtubebeat) Run(b *beat.Beat) error { return err } + fieldsToSend := make(chan common.MapStr) + go scrapeVideos(bt.config.StartId, fieldsToSend) + ticker := time.NewTicker(bt.config.Period) - counter := 1 for { select { case <-bt.done: return nil case <-ticker.C: } - + fields := <-fieldsToSend + fields["type"] = b.Info.Name event := beat.Event{ Timestamp: time.Now(), - Fields: common.MapStr{ - "type": b.Info.Name, - "counter": counter, - }, + Fields: fields, } bt.client.Publish(event) logp.Info("Event sent") - counter++ } } diff --git a/config/config.go b/config/config.go index 41f9583..7d0f392 100644 --- a/config/config.go +++ b/config/config.go @@ -6,11 +6,11 @@ package config import "time" type Config struct { - Period time.Duration `config:"period"` - StartUrl string `config:"start_url"` + Period time.Duration `config:"period"` + StartId string `config:"start_id"` } var DefaultConfig = Config{ - Period: 1 * time.Second, - StartUrl: "https://www.youtube.com/watch?v=SmBCZgcGlKk", + Period: 1 * time.Second, + StartId: "SmBCZgcGlKk", } diff --git a/data/meta.json b/data/meta.json new file mode 100644 index 0000000..00f74d2 --- /dev/null +++ b/data/meta.json @@ -0,0 +1 @@ +{"uuid":"a5fddc65-b03a-4cde-b7a9-f884d277841d"} diff --git a/docs/fields.asciidoc b/docs/fields.asciidoc index 2128a8e..3186438 100644 --- a/docs/fields.asciidoc +++ b/docs/fields.asciidoc @@ -431,14 +431,50 @@ Kubernetes container image None -*`counter`*:: +*`url`*:: ++ +-- +type: string + +required: True + +Video's full URL + + +-- + +*`title`*:: ++ +-- +type: string + +required: True + +Video title + + +-- + +*`views`*:: + -- type: long required: True -PLEASE UPDATE DOCUMENTATION +Video's view count + + +-- + +*`date`*:: ++ +-- +type: string + +required: True + +Video's publish date -- diff --git a/fields.yml b/fields.yml index 219eb87..2943860 100644 --- a/fields.yml +++ b/fields.yml @@ -2,11 +2,26 @@ title: youtubebeat description: fields: - - name: counter + - name: url + type: string + required: true + description: > + Video's full URL + - name: title + type: string + required: true + description: > + Video title + - name: views type: long required: true description: > - PLEASE UPDATE DOCUMENTATION + Video's view count + - name: date + type: string + required: true + description: > + Video's publish date - key: beat title: Beat diff --git a/include/fields.go b/include/fields.go index e89f25b..541fdd1 100644 --- a/include/fields.go +++ b/include/fields.go @@ -31,5 +31,5 @@ func init() { // Asset returns asset data func Asset() string { - return "eJy0WFtz2zYTffev2MnT983InMZuPB09dOrankbTOPE09rOyAlYkahJgcLGs/voOQPBmUpQcqy8ZE5dzzgK7Z6GcwiNt57BVzroVrQjtCYAVNqeXg5wM06K0Qsn5CcBaUM6N/wvgFCQWNAemnLSkwxiA3ZY0h1zJNA5o+u6EJj4Hqx3FwS4s/BoHAe4+3Vx+vYGHu+vL+xu4/nL1cHvz+f7yfvHl88lJFN1X+/tQZsS7UtKikAaYKgolw76oH/AJRY6rnEBIwDwHeiJpg3aTdMLsxekBEv/ndAz3GYUNoNZgMwoKwZDkQqZhIFcpFGQMpmQSWHRWhW3CNFCGrBfo55mSa5E6jZ4O1iKnmR/3k2jhCXPnd4IzxAOmsP5TKtsFC1sgU8ZGprj+XgWqno6ZnwtD3/zntwZHhYh360qGh1Yz7j+4Rhsa0GSdlsRhtQ1UqiRPI1MwW2OpACVhkwmWtcI7Z6edlEKmI2qsKOgfJQ9QU6/8L9U8kTZCyf1i4sI6rUI6h8tPSXopxMFmwlSpnPRT991vPhRjsSjf9eqUo6WpOl0rXaDtraNnLEpfepcudcbC2YXN4Oyn9xczeH82P/8w/3CenJ+fHXa6QRJsqkSmWIa+QDQxpTls0LTxvQjKYmqmWS71SliNehvWVqfF0FtByPeSdHVRKHn4sBqlQWbb+6jO6QVx5Q69c1Srv4nVtVZ9LKuZR9pulObTQhuvcoZ0W1PeoCqyFwpIa9U33FQrV06T3PhNtQOyitHnL3Iu/FrMQci18pXN0AT/CjwmqZOhY/5dNdHMmvFak6Vn2xncIauVFnGSAQFTfIjeaTEHoXuQIbTHGkD37+wg9CpNYotiuXK87VFX/hNKrZ4EJx+mRY4Wx9vWbZyFtVZFhdRsNf6uWgtCzpdhwbKG9CsZGaP0zi7mlyZhV1LDvixsYnuq93OnvfUVJnCnjBE+cUNPMoCaPOAMUkYzUBq4SIXFXDFCmezUJqSxKBktxZ7SWcSFsLiuJfkmAgWyTMiXpTvGsL8zNRzdvn4YS1yw7ORZc872LCmIC1dMs99WECHFXkcenzkiF3a77LS8RoEzp4TGnr5ne4y0AwShI4q22wlTyRGmbXMTKRe8sbnVRkqcOX0+PPXiFq/lD6XSnKpK282uKd3bav8Ka/bFFwudK/YY6idW+nX9PQJezYGxaL395jkx37NDmVdzvmZNprRdVh1gDmvMjb80lCxTuuY7bap8x4u8kQWj/WGXj8eeQDoR/G2e+CDFd0ctIAg+5uoNXTHWPl7F2M2LAFe/TqMA/5BYOZFbUHJKSscMflDJVcPpsaa4clxRbgZsvbcETL8n9mhZhJOoeJqk9cncpuzH6msEZOEfA51E9V1uYD1tbvrxvZkZuV+Xl2+/k4/xZ8XwNo6U6ZVBjCQ5apYJS8w6fYQYenDwP0rSBJ5/uVhe/DwD1MUMypLNoBCl+f9QijJJmaP1T/q3KfnyFWqgqIGRtMrMwK2ctG4GGyG52uwQ0f/F8+MaIs4oxxoLkW/fTFHBxCA18QztDDitBMoZrDXRyvCpaEU5kNAbmmD/JIz1hra4O0XONRlDZkhQIHtbkDVNhppvUFNLNgNnHOb5Fm4vr7oaah95dCvSkiyZ1k3+7I6N0LbzzTO4/6ZtQaHrJdNtsd2014B6ouFVNlQqfoT20DmBUvHK20ap3FutqcN0pzg8LK6HRP5fUyI7XlAt4pDM/wI76gl6xB1HeGhzPYyoQoMCyyETSqls+P+vo9F1IMc5j/lg6fCy3ttlivYIT7ZR3gr33wAAAP//UV6dfg==" + return "eJy0WEtvGzcX3edXXGST7wOkQWM3RqFF0dQpGqFJG6RJtwpFXs2w5pATXtKy+usLcjgvz+jhSN0Y4uucc3lfHM/hDncL2Bnv/BrXyNwzACedwseTAolbWTlp9OIZwEaiEhR+AcxBsxIX4K2KYwC3q3AB5KzUeZqy+NVLi2IBznpMk31Q+DFNAvwlBZoXBBuvFHz++G7AEtVdkKcH2FDcS9zSgEKZswwJgMCN127AI5i7pCUvCCq/VpKKGvlZ8u7QrT+P/ZmAbo12TGoCbsrS6HguORrYPZOKrRWC1MCUArxH7aJsynrxMLAvAGTh52HxnwqMB8BswBUYFQKhFlLncUKZHEokYjlSBsvernhMUgtF6ILAsM6N3sjcWxboYCMVzsJ8WGQO7pny4SR4QhExpQtDbVwfLB6BwpBLTGn/JxOpBjpmYS1OfQnDLy2OiRbv15WNL61hPH5xrTZGYNF5q1HAehepTIWBRudAO3JYgtGwLSQvOuG9u7Nea6nzCTVOlviP0SeoaXb+l2ru0ZI0+riYtLEJqxjO0fk56iAFBbhCUh3K2TB0n/8UTCHHyur5IEV7OTuZoBtjS+YG+/CBlVVIvdc+9+Tg6sYVcPXdy5sZvLxaXL9avLrOrq+vTrvdKAm2dSBjSsOQIBa5sQK2jDr7HhnlWE6HWV7btXSW2V3cW98WZ6EUxHiv0NaOYlrEgbNME+Ou80d9T4+I6+owuEez/ht5k2v1YFWv3OFua6w4LLStVZ7QdjkVClRN9kgBWmvsQEBuja8Ok/wSDjUVkNeMIX6ZEDLsZQqk3piQ2ZxRrF+Rh7ImGHpdsq8mFbN2vtHk8MH1JvfI6qQlnGxEwI0Yo/ea2EnoAWQMHbBG0EOfnYReh0lqUVwZL7oedRuGUFlzLwUGMx0TzLHptvU+rcLGmrJGao9S8FVXgpgQq7hh1UCGnRyJjN3bxcLWLJ7KGtjHiY38SPb+3mtvQ4UZfDBEMgRu7EkEzGIAnEHOcQbGgpC5dEwZjkxne7VJTY5pjit5JHWWaSMs3zSSQhOBkvFC6sepO8VwvDO1HP2+fhpL2rDqxVl7z+4qK1FIXx5mf19DxBB7Gnl65kgl3W7Va3mtAk9zZOTmL/mRQtoDgtgRZdftJNVyJHVt7kDIxdrYerWVklbmD6eHXjoStPxqTK6wzrT97Bbzo632Y9xzzL6U6MLwu5g/KdPfNOMJ8HoNyDEXyq9SyEPPjmler4WcpcJYt6o7wAI2TFFwGtO8MLbhm7dZvufTpZUFk/1hXx1PPQFtJsV5NfGzll89doAgxVRVb+nKqfbxJMZ+XES45nWaBISHxNpL5cDoQ1J6xeAbldy2nAHrEJdia1Q0Yhu8JeDwe+KIlmW8iZqnDdoQzF3Ivq1HEyDL8BjoBWrocqPS08VmmD8amYn7aXF5vk/eps+KsTcuFOl1gZgIcmZ5IR1y5+0FbBjAwf8wyzN4+OFmdfP9DJgtZ1BVfAalrOj/YymGskoxF5705yn5409ogJIGjtoZmoFfe+38DLZSC7PdI2L4xfPtGhLOJMeGlVLtzqaoYZKRFkXB3AwEriXTM9hYxDWJQ9bKaiRhMHWA/Z0kFwra8sOcCWGRCGlMUDJ+npENTcGs2DKLHdkMPHmm1A7ev77ta2jqyJ1fo9XokLpq8lt/boK2W2+fwcM3bQcK/VpyuC12h44WoIFoeFIZqoy4QHvo3UBlRF3bJqn8uaWpx/TBCPi8fDMmCn+pYvxyRnWIY7LwBXbRGwyIe67w1OZ6GlGNBiWrxkxMa+Pi/78uRteDnOa85IOlx8sHb5dDtBd4sk3y1rj/BgAA///8ffLf" } diff --git a/logs/youtubebeat b/logs/youtubebeat new file mode 100644 index 0000000..eeb62f1 --- /dev/null +++ b/logs/youtubebeat @@ -0,0 +1,8 @@ +2018-11-18T11:09:17.508+0100 INFO instance/beat.go:616 Home path: [/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat] Config path: [/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat] Data path: [/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat/data] Logs path: [/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat/logs] +2018-11-18T11:09:17.509+0100 INFO instance/beat.go:623 Beat UUID: a5fddc65-b03a-4cde-b7a9-f884d277841d +2018-11-18T11:09:17.509+0100 INFO [beat] instance/beat.go:849 Beat info {"system_info": {"beat": {"path": {"config": "/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat", "data": "/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat/data", "home": "/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat", "logs": "/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat/logs"}, "type": "youtubebeat", "uuid": "a5fddc65-b03a-4cde-b7a9-f884d277841d"}}} +2018-11-18T11:09:17.509+0100 INFO [beat] instance/beat.go:858 Build info {"system_info": {"build": {"commit": "38fd4465358c195b17152b60e7e32e6ed0345528", "libbeat": "6.5.0", "time": "2018-11-18T10:08:58.000Z", "version": "6.5.0"}}} +2018-11-18T11:09:17.509+0100 INFO [beat] instance/beat.go:861 Go runtime info {"system_info": {"go": {"os":"darwin","arch":"amd64","max_procs":8,"version":"go1.11.2"}}} +2018-11-18T11:09:17.511+0100 INFO [beat] instance/beat.go:865 Host info {"system_info": {"host": {"architecture":"x86_64","boot_time":"2018-11-13T17:51:46.564974+01:00","name":"persephone.local","ip":["127.0.0.1/8","::1/128","fe80::1/64","fe80::1cb1:a370:e195:1b14/64","10.0.0.11/24","2a01:e34:ec0f:96a0:1c7d:59bf:1f3b:b4d9/64","2a01:e34:ec0f:96a0:bdde:b4b8:e13:d8da/64","fe80::d891:cff:fe4e:3f99/64","fe80::8aed:bb9d:8b99:8746/64","fe80::e055:800e:12a0:b862/64","fe80::4e1b:e233:d6da:218/64","fe80::aede:48ff:fe00:1122/64"],"kernel_version":"18.2.0","mac":["b6:00:34:c9:44:01","b6:00:34:c9:44:00","b6:00:34:c9:44:05","b6:00:34:c9:44:04","dc:a9:04:7d:4a:e4","0e:a9:04:7d:4a:e4","da:91:0c:4e:3f:99","b6:00:34:c9:44:01","ac:de:48:00:11:22"],"os":{"family":"darwin","platform":"darwin","name":"Mac OS X","version":"10.14.1","major":10,"minor":14,"patch":1,"build":"18B75"},"timezone":"CET","timezone_offset_sec":3600}}} +2018-11-18T11:09:17.511+0100 INFO [beat] instance/beat.go:894 Process info {"system_info": {"process": {"cwd": "/Users/gaugendre/Projects/golang/src/github.com/Crocmagnon/youtubebeat", "exe": "./youtubebeat", "name": "youtubebeat", "pid": 75764, "ppid": 74760, "start_time": "2018-11-18T11:09:17.481+0100"}}} +2018-11-18T11:09:17.511+0100 INFO instance/beat.go:302 Setup Beat: youtubebeat; Version: 6.5.0 diff --git a/vendor/github.com/PuerkitoBio/goquery/LICENSE b/vendor/github.com/PuerkitoBio/goquery/LICENSE new file mode 100644 index 0000000..f743d37 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/LICENSE @@ -0,0 +1,12 @@ +Copyright (c) 2012-2016, Martin Angers & Contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/PuerkitoBio/goquery/README.md b/vendor/github.com/PuerkitoBio/goquery/README.md new file mode 100644 index 0000000..84f9af3 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/README.md @@ -0,0 +1,179 @@ +# goquery - a little like that j-thing, only in Go +[![build status](https://secure.travis-ci.org/PuerkitoBio/goquery.svg?branch=master)](http://travis-ci.org/PuerkitoBio/goquery) [![GoDoc](https://godoc.org/github.com/PuerkitoBio/goquery?status.png)](http://godoc.org/github.com/PuerkitoBio/goquery) [![Sourcegraph Badge](https://sourcegraph.com/github.com/PuerkitoBio/goquery/-/badge.svg)](https://sourcegraph.com/github.com/PuerkitoBio/goquery?badge) + +goquery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on Go's [net/html package][html] and the CSS Selector library [cascadia][]. Since the net/html parser returns nodes, and not a full-featured DOM tree, jQuery's stateful manipulation functions (like height(), css(), detach()) have been left off. + +Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. See the [wiki][] for various options to do this. + +Syntax-wise, it is as close as possible to jQuery, with the same function names when possible, and that warm and fuzzy chainable interface. jQuery being the ultra-popular library that it is, I felt that writing a similar HTML-manipulating library was better to follow its API than to start anew (in the same spirit as Go's `fmt` package), even though some of its methods are less than intuitive (looking at you, [index()][index]...). + +## Table of Contents + +* [Installation](#installation) +* [Changelog](#changelog) +* [API](#api) +* [Examples](#examples) +* [Related Projects](#related-projects) +* [Support](#support) +* [License](#license) + +## Installation + +Please note that because of the net/html dependency, goquery requires Go1.1+. + + $ go get github.com/PuerkitoBio/goquery + +(optional) To run unit tests: + + $ cd $GOPATH/src/github.com/PuerkitoBio/goquery + $ go test + +(optional) To run benchmarks (warning: it runs for a few minutes): + + $ cd $GOPATH/src/github.com/PuerkitoBio/goquery + $ go test -bench=".*" + +## Changelog + +**Note that goquery's API is now stable, and will not break.** + +* **2018-11-15 (v1.5.0)** : Go module support (thanks @Zaba505). +* **2018-06-07 (v1.4.1)** : Add `NewDocumentFromReader` examples. +* **2018-03-24 (v1.4.0)** : Deprecate `NewDocument(url)` and `NewDocumentFromResponse(response)`. +* **2018-01-28 (v1.3.0)** : Add `ToEnd` constant to `Slice` until the end of the selection (thanks to @davidjwilkins for raising the issue). +* **2018-01-11 (v1.2.0)** : Add `AddBack*` and deprecate `AndSelf` (thanks to @davidjwilkins). +* **2017-02-12 (v1.1.0)** : Add `SetHtml` and `SetText` (thanks to @glebtv). +* **2016-12-29 (v1.0.2)** : Optimize allocations for `Selection.Text` (thanks to @radovskyb). +* **2016-08-28 (v1.0.1)** : Optimize performance for large documents. +* **2016-07-27 (v1.0.0)** : Tag version 1.0.0. +* **2016-06-15** : Invalid selector strings internally compile to a `Matcher` implementation that never matches any node (instead of a panic). So for example, `doc.Find("~")` returns an empty `*Selection` object. +* **2016-02-02** : Add `NodeName` utility function similar to the DOM's `nodeName` property. It returns the tag name of the first element in a selection, and other relevant values of non-element nodes (see godoc for details). Add `OuterHtml` utility function similar to the DOM's `outerHTML` property (named `OuterHtml` in small caps for consistency with the existing `Html` method on the `Selection`). +* **2015-04-20** : Add `AttrOr` helper method to return the attribute's value or a default value if absent. Thanks to [piotrkowalczuk][piotr]. +* **2015-02-04** : Add more manipulation functions - Prepend* - thanks again to [Andrew Stone][thatguystone]. +* **2014-11-28** : Add more manipulation functions - ReplaceWith*, Wrap* and Unwrap - thanks again to [Andrew Stone][thatguystone]. +* **2014-11-07** : Add manipulation functions (thanks to [Andrew Stone][thatguystone]) and `*Matcher` functions, that receive compiled cascadia selectors instead of selector strings, thus avoiding potential panics thrown by goquery via `cascadia.MustCompile` calls. This results in better performance (selectors can be compiled once and reused) and more idiomatic error handling (you can handle cascadia's compilation errors, instead of recovering from panics, which had been bugging me for a long time). Note that the actual type expected is a `Matcher` interface, that `cascadia.Selector` implements. Other matcher implementations could be used. +* **2014-11-06** : Change import paths of net/html to golang.org/x/net/html (see https://groups.google.com/forum/#!topic/golang-nuts/eD8dh3T9yyA). Make sure to update your code to use the new import path too when you call goquery with `html.Node`s. +* **v0.3.2** : Add `NewDocumentFromReader()` (thanks jweir) which allows creating a goquery document from an io.Reader. +* **v0.3.1** : Add `NewDocumentFromResponse()` (thanks assassingj) which allows creating a goquery document from an http response. +* **v0.3.0** : Add `EachWithBreak()` which allows to break out of an `Each()` loop by returning false. This function was added instead of changing the existing `Each()` to avoid breaking compatibility. +* **v0.2.1** : Make go-getable, now that [go.net/html is Go1.0-compatible][gonet] (thanks to @matrixik for pointing this out). +* **v0.2.0** : Add support for negative indices in Slice(). **BREAKING CHANGE** `Document.Root` is removed, `Document` is now a `Selection` itself (a selection of one, the root element, just like `Document.Root` was before). Add jQuery's Closest() method. +* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases). +* **v0.1.0** : Initial release. + +## API + +goquery exposes two structs, `Document` and `Selection`, and the `Matcher` interface. Unlike jQuery, which is loaded as part of a DOM document, and thus acts on its containing document, goquery doesn't know which HTML document to act upon. So it needs to be told, and that's what the `Document` type is for. It holds the root document node as the initial Selection value to manipulate. + +jQuery often has many variants for the same function (no argument, a selector string argument, a jQuery object argument, a DOM element argument, ...). Instead of exposing the same features in goquery as a single method with variadic empty interface arguments, statically-typed signatures are used following this naming convention: + +* When the jQuery equivalent can be called with no argument, it has the same name as jQuery for the no argument signature (e.g.: `Prev()`), and the version with a selector string argument is called `XxxFiltered()` (e.g.: `PrevFiltered()`) +* When the jQuery equivalent **requires** one argument, the same name as jQuery is used for the selector string version (e.g.: `Is()`) +* The signatures accepting a jQuery object as argument are defined in goquery as `XxxSelection()` and take a `*Selection` object as argument (e.g.: `FilterSelection()`) +* The signatures accepting a DOM element as argument in jQuery are defined in goquery as `XxxNodes()` and take a variadic argument of type `*html.Node` (e.g.: `FilterNodes()`) +* The signatures accepting a function as argument in jQuery are defined in goquery as `XxxFunction()` and take a function as argument (e.g.: `FilterFunction()`) +* The goquery methods that can be called with a selector string have a corresponding version that take a `Matcher` interface and are defined as `XxxMatcher()` (e.g.: `IsMatcher()`) + +Utility functions that are not in jQuery but are useful in Go are implemented as functions (that take a `*Selection` as parameter), to avoid a potential naming clash on the `*Selection`'s methods (reserved for jQuery-equivalent behaviour). + +The complete [godoc reference documentation can be found here][doc]. + +Please note that Cascadia's selectors do not necessarily match all supported selectors of jQuery (Sizzle). See the [cascadia project][cascadia] for details. Invalid selector strings compile to a `Matcher` that fails to match any node. Behaviour of the various functions that take a selector string as argument follows from that fact, e.g. (where `~` is an invalid selector string): + +* `Find("~")` returns an empty selection because the selector string doesn't match anything. +* `Add("~")` returns a new selection that holds the same nodes as the original selection, because it didn't add any node (selector string didn't match anything). +* `ParentsFiltered("~")` returns an empty selection because the selector string doesn't match anything. +* `ParentsUntil("~")` returns all parents of the selection because the selector string didn't match any element to stop before the top element. + +## Examples + +See some tips and tricks in the [wiki][]. + +Adapted from example_test.go: + +```Go +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/PuerkitoBio/goquery" +) + +func ExampleScrape() { + // Request the HTML page. + res, err := http.Get("http://metalsucks.net") + if err != nil { + log.Fatal(err) + } + defer res.Body.Close() + if res.StatusCode != 200 { + log.Fatalf("status code error: %d %s", res.StatusCode, res.Status) + } + + // Load the HTML document + doc, err := goquery.NewDocumentFromReader(res.Body) + if err != nil { + log.Fatal(err) + } + + // Find the review items + doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) { + // For each item found, get the band and title + band := s.Find("a").Text() + title := s.Find("i").Text() + fmt.Printf("Review %d: %s - %s\n", i, band, title) + }) +} + +func main() { + ExampleScrape() +} +``` + +## Related Projects + +- [Goq][goq], an HTML deserialization and scraping library based on goquery and struct tags. +- [andybalholm/cascadia][cascadia], the CSS selector library used by goquery. +- [suntong/cascadia][cascadiacli], a command-line interface to the cascadia CSS selector library, useful to test selectors. +- [asciimoo/colly](https://github.com/asciimoo/colly), a lightning fast and elegant Scraping Framework +- [gnulnx/goperf](https://github.com/gnulnx/goperf), a website performance test tool that also fetches static assets. +- [MontFerret/ferret](https://github.com/MontFerret/ferret), declarative web scraping. + +## Support + +There are a number of ways you can support the project: + +* Use it, star it, build something with it, spread the word! + - If you do build something open-source or otherwise publicly-visible, let me know so I can add it to the [Related Projects](#related-projects) section! +* Raise issues to improve the project (note: doc typos and clarifications are issues too!) + - Please search existing issues before opening a new one - it may have already been adressed. +* Pull requests: please discuss new code in an issue first, unless the fix is really trivial. + - Make sure new code is tested. + - Be mindful of existing code - PRs that break existing code have a high probability of being declined, unless it fixes a serious issue. + +If you desperately want to send money my way, I have a BuyMeACoffee.com page: + +Buy Me A Coffee + +## License + +The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia's license is [here][caslic]. + +[jquery]: http://jquery.com/ +[go]: http://golang.org/ +[cascadia]: https://github.com/andybalholm/cascadia +[cascadiacli]: https://github.com/suntong/cascadia +[bsd]: http://opensource.org/licenses/BSD-3-Clause +[golic]: http://golang.org/LICENSE +[caslic]: https://github.com/andybalholm/cascadia/blob/master/LICENSE +[doc]: http://godoc.org/github.com/PuerkitoBio/goquery +[index]: http://api.jquery.com/index/ +[gonet]: https://github.com/golang/net/ +[html]: http://godoc.org/golang.org/x/net/html +[wiki]: https://github.com/PuerkitoBio/goquery/wiki/Tips-and-tricks +[thatguystone]: https://github.com/thatguystone +[piotr]: https://github.com/piotrkowalczuk +[goq]: https://github.com/andrewstuart/goq diff --git a/vendor/github.com/PuerkitoBio/goquery/array.go b/vendor/github.com/PuerkitoBio/goquery/array.go new file mode 100644 index 0000000..1b1f6cb --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/array.go @@ -0,0 +1,124 @@ +package goquery + +import ( + "golang.org/x/net/html" +) + +const ( + maxUint = ^uint(0) + maxInt = int(maxUint >> 1) + + // ToEnd is a special index value that can be used as end index in a call + // to Slice so that all elements are selected until the end of the Selection. + // It is equivalent to passing (*Selection).Length(). + ToEnd = maxInt +) + +// First reduces the set of matched elements to the first in the set. +// It returns a new Selection object, and an empty Selection object if the +// the selection is empty. +func (s *Selection) First() *Selection { + return s.Eq(0) +} + +// Last reduces the set of matched elements to the last in the set. +// It returns a new Selection object, and an empty Selection object if +// the selection is empty. +func (s *Selection) Last() *Selection { + return s.Eq(-1) +} + +// Eq reduces the set of matched elements to the one at the specified index. +// If a negative index is given, it counts backwards starting at the end of the +// set. It returns a new Selection object, and an empty Selection object if the +// index is invalid. +func (s *Selection) Eq(index int) *Selection { + if index < 0 { + index += len(s.Nodes) + } + + if index >= len(s.Nodes) || index < 0 { + return newEmptySelection(s.document) + } + + return s.Slice(index, index+1) +} + +// Slice reduces the set of matched elements to a subset specified by a range +// of indices. The start index is 0-based and indicates the index of the first +// element to select. The end index is 0-based and indicates the index at which +// the elements stop being selected (the end index is not selected). +// +// The indices may be negative, in which case they represent an offset from the +// end of the selection. +// +// The special value ToEnd may be specified as end index, in which case all elements +// until the end are selected. This works both for a positive and negative start +// index. +func (s *Selection) Slice(start, end int) *Selection { + if start < 0 { + start += len(s.Nodes) + } + if end == ToEnd { + end = len(s.Nodes) + } else if end < 0 { + end += len(s.Nodes) + } + return pushStack(s, s.Nodes[start:end]) +} + +// Get retrieves the underlying node at the specified index. +// Get without parameter is not implemented, since the node array is available +// on the Selection object. +func (s *Selection) Get(index int) *html.Node { + if index < 0 { + index += len(s.Nodes) // Negative index gets from the end + } + return s.Nodes[index] +} + +// Index returns the position of the first element within the Selection object +// relative to its sibling elements. +func (s *Selection) Index() int { + if len(s.Nodes) > 0 { + return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length() + } + return -1 +} + +// IndexSelector returns the position of the first element within the +// Selection object relative to the elements matched by the selector, or -1 if +// not found. +func (s *Selection) IndexSelector(selector string) int { + if len(s.Nodes) > 0 { + sel := s.document.Find(selector) + return indexInSlice(sel.Nodes, s.Nodes[0]) + } + return -1 +} + +// IndexMatcher returns the position of the first element within the +// Selection object relative to the elements matched by the matcher, or -1 if +// not found. +func (s *Selection) IndexMatcher(m Matcher) int { + if len(s.Nodes) > 0 { + sel := s.document.FindMatcher(m) + return indexInSlice(sel.Nodes, s.Nodes[0]) + } + return -1 +} + +// IndexOfNode returns the position of the specified node within the Selection +// object, or -1 if not found. +func (s *Selection) IndexOfNode(node *html.Node) int { + return indexInSlice(s.Nodes, node) +} + +// IndexOfSelection returns the position of the first node in the specified +// Selection object within this Selection object, or -1 if not found. +func (s *Selection) IndexOfSelection(sel *Selection) int { + if sel != nil && len(sel.Nodes) > 0 { + return indexInSlice(s.Nodes, sel.Nodes[0]) + } + return -1 +} diff --git a/vendor/github.com/PuerkitoBio/goquery/array_test.go b/vendor/github.com/PuerkitoBio/goquery/array_test.go new file mode 100644 index 0000000..7857b38 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/array_test.go @@ -0,0 +1,234 @@ +package goquery + +import ( + "testing" +) + +func TestFirst(t *testing.T) { + sel := Doc().Find(".pvk-content").First() + assertLength(t, sel.Nodes, 1) +} + +func TestFirstEmpty(t *testing.T) { + sel := Doc().Find(".pvk-zzcontentzz").First() + assertLength(t, sel.Nodes, 0) +} + +func TestFirstInvalid(t *testing.T) { + sel := Doc().Find("").First() + assertLength(t, sel.Nodes, 0) +} + +func TestFirstRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.First().End() + assertEqual(t, sel, sel2) +} + +func TestLast(t *testing.T) { + sel := Doc().Find(".pvk-content").Last() + assertLength(t, sel.Nodes, 1) + + // Should contain Footer + foot := Doc().Find(".footer") + if !sel.Contains(foot.Nodes[0]) { + t.Error("Last .pvk-content should contain .footer.") + } +} + +func TestLastEmpty(t *testing.T) { + sel := Doc().Find(".pvk-zzcontentzz").Last() + assertLength(t, sel.Nodes, 0) +} + +func TestLastInvalid(t *testing.T) { + sel := Doc().Find("").Last() + assertLength(t, sel.Nodes, 0) +} + +func TestLastRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Last().End() + assertEqual(t, sel, sel2) +} + +func TestEq(t *testing.T) { + sel := Doc().Find(".pvk-content").Eq(1) + assertLength(t, sel.Nodes, 1) +} + +func TestEqNegative(t *testing.T) { + sel := Doc().Find(".pvk-content").Eq(-1) + assertLength(t, sel.Nodes, 1) + + // Should contain Footer + foot := Doc().Find(".footer") + if !sel.Contains(foot.Nodes[0]) { + t.Error("Index -1 of .pvk-content should contain .footer.") + } +} + +func TestEqEmpty(t *testing.T) { + sel := Doc().Find("something_random_that_does_not_exists").Eq(0) + assertLength(t, sel.Nodes, 0) +} + +func TestEqInvalid(t *testing.T) { + sel := Doc().Find("").Eq(0) + assertLength(t, sel.Nodes, 0) +} + +func TestEqInvalidPositive(t *testing.T) { + sel := Doc().Find(".pvk-content").Eq(3) + assertLength(t, sel.Nodes, 0) +} + +func TestEqInvalidNegative(t *testing.T) { + sel := Doc().Find(".pvk-content").Eq(-4) + assertLength(t, sel.Nodes, 0) +} + +func TestEqRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Eq(1).End() + assertEqual(t, sel, sel2) +} + +func TestSlice(t *testing.T) { + sel := Doc().Find(".pvk-content").Slice(0, 2) + + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#pc1", "#pc2") +} + +func TestSliceToEnd(t *testing.T) { + sel := Doc().Find(".pvk-content").Slice(1, ToEnd) + + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel.Eq(0), "#pc2") + if _, ok := sel.Eq(1).Attr("id"); ok { + t.Error("Want no attribute ID, got one") + } +} + +func TestSliceEmpty(t *testing.T) { + defer assertPanic(t) + Doc().Find("x").Slice(0, 2) +} + +func TestSliceInvalid(t *testing.T) { + defer assertPanic(t) + Doc().Find("").Slice(0, 2) +} + +func TestSliceInvalidToEnd(t *testing.T) { + defer assertPanic(t) + Doc().Find("").Slice(2, ToEnd) +} + +func TestSliceOutOfBounds(t *testing.T) { + defer assertPanic(t) + Doc().Find(".pvk-content").Slice(2, 12) +} + +func TestNegativeSliceStart(t *testing.T) { + sel := Doc().Find(".container-fluid").Slice(-2, 3) + assertLength(t, sel.Nodes, 1) + assertSelectionIs(t, sel.Eq(0), "#cf3") +} + +func TestNegativeSliceEnd(t *testing.T) { + sel := Doc().Find(".container-fluid").Slice(1, -1) + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel.Eq(0), "#cf2") + assertSelectionIs(t, sel.Eq(1), "#cf3") +} + +func TestNegativeSliceBoth(t *testing.T) { + sel := Doc().Find(".container-fluid").Slice(-3, -1) + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel.Eq(0), "#cf2") + assertSelectionIs(t, sel.Eq(1), "#cf3") +} + +func TestNegativeSliceToEnd(t *testing.T) { + sel := Doc().Find(".container-fluid").Slice(-3, ToEnd) + assertLength(t, sel.Nodes, 3) + assertSelectionIs(t, sel, "#cf2", "#cf3", "#cf4") +} + +func TestNegativeSliceOutOfBounds(t *testing.T) { + defer assertPanic(t) + Doc().Find(".container-fluid").Slice(-12, -7) +} + +func TestSliceRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Slice(0, 2).End() + assertEqual(t, sel, sel2) +} + +func TestGet(t *testing.T) { + sel := Doc().Find(".pvk-content") + node := sel.Get(1) + if sel.Nodes[1] != node { + t.Errorf("Expected node %v to be %v.", node, sel.Nodes[1]) + } +} + +func TestGetNegative(t *testing.T) { + sel := Doc().Find(".pvk-content") + node := sel.Get(-3) + if sel.Nodes[0] != node { + t.Errorf("Expected node %v to be %v.", node, sel.Nodes[0]) + } +} + +func TestGetInvalid(t *testing.T) { + defer assertPanic(t) + sel := Doc().Find(".pvk-content") + sel.Get(129) +} + +func TestIndex(t *testing.T) { + sel := Doc().Find(".pvk-content") + if i := sel.Index(); i != 1 { + t.Errorf("Expected index of 1, got %v.", i) + } +} + +func TestIndexSelector(t *testing.T) { + sel := Doc().Find(".hero-unit") + if i := sel.IndexSelector("div"); i != 4 { + t.Errorf("Expected index of 4, got %v.", i) + } +} + +func TestIndexSelectorInvalid(t *testing.T) { + sel := Doc().Find(".hero-unit") + if i := sel.IndexSelector(""); i != -1 { + t.Errorf("Expected index of -1, got %v.", i) + } +} + +func TestIndexOfNode(t *testing.T) { + sel := Doc().Find("div.pvk-gutter") + if i := sel.IndexOfNode(sel.Nodes[1]); i != 1 { + t.Errorf("Expected index of 1, got %v.", i) + } +} + +func TestIndexOfNilNode(t *testing.T) { + sel := Doc().Find("div.pvk-gutter") + if i := sel.IndexOfNode(nil); i != -1 { + t.Errorf("Expected index of -1, got %v.", i) + } +} + +func TestIndexOfSelection(t *testing.T) { + sel := Doc().Find("div") + sel2 := Doc().Find(".hero-unit") + if i := sel.IndexOfSelection(sel2); i != 4 { + t.Errorf("Expected index of 4, got %v.", i) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_array_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_array_test.go new file mode 100644 index 0000000..29c7e20 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_array_test.go @@ -0,0 +1,120 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkFirst(b *testing.B) { + b.StopTimer() + sel := DocB().Find("dd") + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.First() + } +} + +func BenchmarkLast(b *testing.B) { + b.StopTimer() + sel := DocB().Find("dd") + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Last() + } +} + +func BenchmarkEq(b *testing.B) { + b.StopTimer() + sel := DocB().Find("dd") + j := 0 + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Eq(j) + if j++; j >= sel.Length() { + j = 0 + } + } +} + +func BenchmarkSlice(b *testing.B) { + b.StopTimer() + sel := DocB().Find("dd") + j := 0 + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Slice(j, j+4) + if j++; j >= (sel.Length() - 4) { + j = 0 + } + } +} + +func BenchmarkGet(b *testing.B) { + b.StopTimer() + sel := DocB().Find("dd") + j := 0 + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Get(j) + if j++; j >= sel.Length() { + j = 0 + } + } +} + +func BenchmarkIndex(b *testing.B) { + var j int + + b.StopTimer() + sel := DocB().Find("#Main") + b.StartTimer() + for i := 0; i < b.N; i++ { + j = sel.Index() + } + if j != 3 { + b.Fatalf("want 3, got %d", j) + } +} + +func BenchmarkIndexSelector(b *testing.B) { + var j int + + b.StopTimer() + sel := DocB().Find("#manual-nav dl dd:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + j = sel.IndexSelector("dd") + } + if j != 4 { + b.Fatalf("want 4, got %d", j) + } +} + +func BenchmarkIndexOfNode(b *testing.B) { + var j int + + b.StopTimer() + sel := DocB().Find("span a") + sel2 := DocB().Find("span a:nth-child(3)") + n := sel2.Get(0) + b.StartTimer() + for i := 0; i < b.N; i++ { + j = sel.IndexOfNode(n) + } + if j != 2 { + b.Fatalf("want 2, got %d", j) + } +} + +func BenchmarkIndexOfSelection(b *testing.B) { + var j int + b.StopTimer() + sel := DocB().Find("span a") + sel2 := DocB().Find("span a:nth-child(3)") + b.StartTimer() + for i := 0; i < b.N; i++ { + j = sel.IndexOfSelection(sel2) + } + if j != 2 { + b.Fatalf("want 2, got %d", j) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_example_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_example_test.go new file mode 100644 index 0000000..ba9ebe5 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_example_test.go @@ -0,0 +1,40 @@ +package goquery + +import ( + "bytes" + "fmt" + "strconv" + "testing" +) + +func BenchmarkMetalReviewExample(b *testing.B) { + var n int + var buf bytes.Buffer + + b.StopTimer() + doc := loadDoc("metalreview.html") + b.StartTimer() + for i := 0; i < b.N; i++ { + doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) { + var band, title string + var score float64 + var e error + + n++ + // For each item found, get the band, title and score, and print it + band = s.Find("strong").Text() + title = s.Find("em").Text() + if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil { + // Not a valid float, ignore score + if n <= 4 { + buf.WriteString(fmt.Sprintf("Review %d: %s - %s.\n", i, band, title)) + } + } else { + // Print all, including score + if n <= 4 { + buf.WriteString(fmt.Sprintf("Review %d: %s - %s (%2.1f).\n", i, band, title, score)) + } + } + }) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_expand_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_expand_test.go new file mode 100644 index 0000000..61f1947 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_expand_test.go @@ -0,0 +1,104 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkAdd(b *testing.B) { + var n int + + b.StopTimer() + sel := DocB().Find("dd") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Add("h2[title]").Length() + } else { + sel.Add("h2[title]") + } + } + if n != 43 { + b.Fatalf("want 43, got %d", n) + } +} + +func BenchmarkAddSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocB().Find("dd") + sel2 := DocB().Find("h2[title]") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.AddSelection(sel2).Length() + } else { + sel.AddSelection(sel2) + } + } + if n != 43 { + b.Fatalf("want 43, got %d", n) + } +} + +func BenchmarkAddNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocB().Find("dd") + sel2 := DocB().Find("h2[title]") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.AddNodes(nodes...).Length() + } else { + sel.AddNodes(nodes...) + } + } + if n != 43 { + b.Fatalf("want 43, got %d", n) + } +} + +func BenchmarkAddNodesBig(b *testing.B) { + var n int + + doc := DocW() + sel := doc.Find("li") + // make nodes > 1000 + nodes := sel.Nodes + nodes = append(nodes, nodes...) + nodes = append(nodes, nodes...) + sel = doc.Find("xyz") + b.ResetTimer() + + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.AddNodes(nodes...).Length() + } else { + sel.AddNodes(nodes...) + } + } + if n != 373 { + b.Fatalf("want 373, got %d", n) + } +} + +func BenchmarkAndSelf(b *testing.B) { + var n int + + b.StopTimer() + sel := DocB().Find("dd").Parent() + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.AndSelf().Length() + } else { + sel.AndSelf() + } + } + if n != 44 { + b.Fatalf("want 44, got %d", n) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_filter_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_filter_test.go new file mode 100644 index 0000000..38e39f5 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_filter_test.go @@ -0,0 +1,236 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkFilter(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Filter(".toclevel-1").Length() + } else { + sel.Filter(".toclevel-1") + } + } + if n != 13 { + b.Fatalf("want 13, got %d", n) + } +} + +func BenchmarkNot(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Not(".toclevel-2").Length() + } else { + sel.Filter(".toclevel-2") + } + } + if n != 371 { + b.Fatalf("want 371, got %d", n) + } +} + +func BenchmarkFilterFunction(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + f := func(i int, s *Selection) bool { + return len(s.Get(0).Attr) > 0 + } + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.FilterFunction(f).Length() + } else { + sel.FilterFunction(f) + } + } + if n != 112 { + b.Fatalf("want 112, got %d", n) + } +} + +func BenchmarkNotFunction(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + f := func(i int, s *Selection) bool { + return len(s.Get(0).Attr) > 0 + } + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NotFunction(f).Length() + } else { + sel.NotFunction(f) + } + } + if n != 261 { + b.Fatalf("want 261, got %d", n) + } +} + +func BenchmarkFilterNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".toclevel-2") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.FilterNodes(nodes...).Length() + } else { + sel.FilterNodes(nodes...) + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkNotNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".toclevel-1") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NotNodes(nodes...).Length() + } else { + sel.NotNodes(nodes...) + } + } + if n != 360 { + b.Fatalf("want 360, got %d", n) + } +} + +func BenchmarkFilterSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".toclevel-2") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.FilterSelection(sel2).Length() + } else { + sel.FilterSelection(sel2) + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkNotSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".toclevel-1") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NotSelection(sel2).Length() + } else { + sel.NotSelection(sel2) + } + } + if n != 360 { + b.Fatalf("want 360, got %d", n) + } +} + +func BenchmarkHas(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Has(".editsection").Length() + } else { + sel.Has(".editsection") + } + } + if n != 13 { + b.Fatalf("want 13, got %d", n) + } +} + +func BenchmarkHasNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".tocnumber") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.HasNodes(nodes...).Length() + } else { + sel.HasNodes(nodes...) + } + } + if n != 15 { + b.Fatalf("want 15, got %d", n) + } +} + +func BenchmarkHasSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".tocnumber") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.HasSelection(sel2).Length() + } else { + sel.HasSelection(sel2) + } + } + if n != 15 { + b.Fatalf("want 15, got %d", n) + } +} + +func BenchmarkEnd(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li").Has(".tocnumber") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.End().Length() + } else { + sel.End() + } + } + if n != 373 { + b.Fatalf("want 373, got %d", n) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go new file mode 100644 index 0000000..39445b0 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go @@ -0,0 +1,68 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkEach(b *testing.B) { + var tmp, n int + + b.StopTimer() + sel := DocW().Find("td") + f := func(i int, s *Selection) { + tmp++ + } + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Each(f) + if n == 0 { + n = tmp + } + } + if n != 59 { + b.Fatalf("want 59, got %d", n) + } +} + +func BenchmarkMap(b *testing.B) { + var tmp, n int + + b.StopTimer() + sel := DocW().Find("td") + f := func(i int, s *Selection) string { + tmp++ + return string(tmp) + } + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Map(f) + if n == 0 { + n = tmp + } + } + if n != 59 { + b.Fatalf("want 59, got %d", n) + } +} + +func BenchmarkEachWithBreak(b *testing.B) { + var tmp, n int + + b.StopTimer() + sel := DocW().Find("td") + f := func(i int, s *Selection) bool { + tmp++ + return tmp < 10 + } + b.StartTimer() + for i := 0; i < b.N; i++ { + tmp = 0 + sel.EachWithBreak(f) + if n == 0 { + n = tmp + } + } + if n != 10 { + b.Fatalf("want 10, got %d", n) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_property_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_property_test.go new file mode 100644 index 0000000..8acf5bf --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_property_test.go @@ -0,0 +1,51 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkAttr(b *testing.B) { + var s string + + b.StopTimer() + sel := DocW().Find("h1") + b.StartTimer() + for i := 0; i < b.N; i++ { + s, _ = sel.Attr("id") + } + if s != "firstHeading" { + b.Fatalf("want firstHeading, got %q", s) + } +} + +func BenchmarkText(b *testing.B) { + b.StopTimer() + sel := DocW().Find("h2") + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Text() + } +} + +func BenchmarkLength(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + b.StartTimer() + for i := 0; i < b.N; i++ { + n = sel.Length() + } + if n != 14 { + b.Fatalf("want 14, got %d", n) + } +} + +func BenchmarkHtml(b *testing.B) { + b.StopTimer() + sel := DocW().Find("h2") + b.StartTimer() + for i := 0; i < b.N; i++ { + sel.Html() + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_query_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_query_test.go new file mode 100644 index 0000000..64fdbc4 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_query_test.go @@ -0,0 +1,111 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkIs(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find("li") + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.Is(".toclevel-2") + } + if !y { + b.Fatal("want true") + } +} + +func BenchmarkIsPositional(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find("li") + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.Is("li:nth-child(2)") + } + if !y { + b.Fatal("want true") + } +} + +func BenchmarkIsFunction(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find(".toclevel-1") + f := func(i int, s *Selection) bool { + return i == 8 + } + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.IsFunction(f) + } + if !y { + b.Fatal("want true") + } +} + +func BenchmarkIsSelection(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".toclevel-2") + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.IsSelection(sel2) + } + if !y { + b.Fatal("want true") + } +} + +func BenchmarkIsNodes(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find("li") + sel2 := DocW().Find(".toclevel-2") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.IsNodes(nodes...) + } + if !y { + b.Fatal("want true") + } +} + +func BenchmarkHasClass(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find("span") + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.HasClass("official") + } + if !y { + b.Fatal("want true") + } +} + +func BenchmarkContains(b *testing.B) { + var y bool + + b.StopTimer() + sel := DocW().Find("span.url") + sel2 := DocW().Find("a[rel=\"nofollow\"]") + node := sel2.Nodes[0] + b.StartTimer() + for i := 0; i < b.N; i++ { + y = sel.Contains(node) + } + if !y { + b.Fatal("want true") + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_traversal_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_traversal_test.go new file mode 100644 index 0000000..de84bcd --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/bench_traversal_test.go @@ -0,0 +1,802 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkFind(b *testing.B) { + var n int + + for i := 0; i < b.N; i++ { + if n == 0 { + n = DocB().Find("dd").Length() + + } else { + DocB().Find("dd") + } + } + if n != 41 { + b.Fatalf("want 41, got %d", n) + } +} + +func BenchmarkFindWithinSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("ul") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Find("a[class]").Length() + } else { + sel.Find("a[class]") + } + } + if n != 39 { + b.Fatalf("want 39, got %d", n) + } +} + +func BenchmarkFindSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("ul") + sel2 := DocW().Find("span") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.FindSelection(sel2).Length() + } else { + sel.FindSelection(sel2) + } + } + if n != 73 { + b.Fatalf("want 73, got %d", n) + } +} + +func BenchmarkFindNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("ul") + sel2 := DocW().Find("span") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.FindNodes(nodes...).Length() + } else { + sel.FindNodes(nodes...) + } + } + if n != 73 { + b.Fatalf("want 73, got %d", n) + } +} + +func BenchmarkContents(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find(".toclevel-1") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Contents().Length() + } else { + sel.Contents() + } + } + if n != 16 { + b.Fatalf("want 16, got %d", n) + } +} + +func BenchmarkContentsFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find(".toclevel-1") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ContentsFiltered("a[href=\"#Examples\"]").Length() + } else { + sel.ContentsFiltered("a[href=\"#Examples\"]") + } + } + if n != 1 { + b.Fatalf("want 1, got %d", n) + } +} + +func BenchmarkChildren(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find(".toclevel-2") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Children().Length() + } else { + sel.Children() + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkChildrenFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h3") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ChildrenFiltered(".editsection").Length() + } else { + sel.ChildrenFiltered(".editsection") + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkParent(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Parent().Length() + } else { + sel.Parent() + } + } + if n != 55 { + b.Fatalf("want 55, got %d", n) + } +} + +func BenchmarkParentFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentFiltered("ul[id]").Length() + } else { + sel.ParentFiltered("ul[id]") + } + } + if n != 4 { + b.Fatalf("want 4, got %d", n) + } +} + +func BenchmarkParents(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("th a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Parents().Length() + } else { + sel.Parents() + } + } + if n != 73 { + b.Fatalf("want 73, got %d", n) + } +} + +func BenchmarkParentsFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("th a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFiltered("tr").Length() + } else { + sel.ParentsFiltered("tr") + } + } + if n != 18 { + b.Fatalf("want 18, got %d", n) + } +} + +func BenchmarkParentsUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("th a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsUntil("table").Length() + } else { + sel.ParentsUntil("table") + } + } + if n != 52 { + b.Fatalf("want 52, got %d", n) + } +} + +func BenchmarkParentsUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("th a") + sel2 := DocW().Find("#content") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsUntilSelection(sel2).Length() + } else { + sel.ParentsUntilSelection(sel2) + } + } + if n != 70 { + b.Fatalf("want 70, got %d", n) + } +} + +func BenchmarkParentsUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("th a") + sel2 := DocW().Find("#content") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsUntilNodes(nodes...).Length() + } else { + sel.ParentsUntilNodes(nodes...) + } + } + if n != 70 { + b.Fatalf("want 70, got %d", n) + } +} + +func BenchmarkParentsFilteredUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find(".toclevel-1 a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFilteredUntil(":nth-child(1)", "ul").Length() + } else { + sel.ParentsFilteredUntil(":nth-child(1)", "ul") + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkParentsFilteredUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find(".toclevel-1 a") + sel2 := DocW().Find("ul") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFilteredUntilSelection(":nth-child(1)", sel2).Length() + } else { + sel.ParentsFilteredUntilSelection(":nth-child(1)", sel2) + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkParentsFilteredUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find(".toclevel-1 a") + sel2 := DocW().Find("ul") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFilteredUntilNodes(":nth-child(1)", nodes...).Length() + } else { + sel.ParentsFilteredUntilNodes(":nth-child(1)", nodes...) + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkSiblings(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("ul li:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Siblings().Length() + } else { + sel.Siblings() + } + } + if n != 293 { + b.Fatalf("want 293, got %d", n) + } +} + +func BenchmarkSiblingsFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("ul li:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.SiblingsFiltered("[class]").Length() + } else { + sel.SiblingsFiltered("[class]") + } + } + if n != 46 { + b.Fatalf("want 46, got %d", n) + } +} + +func BenchmarkNext(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Next().Length() + } else { + sel.Next() + } + } + if n != 49 { + b.Fatalf("want 49, got %d", n) + } +} + +func BenchmarkNextFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextFiltered("[class]").Length() + } else { + sel.NextFiltered("[class]") + } + } + if n != 6 { + b.Fatalf("want 6, got %d", n) + } +} + +func BenchmarkNextAll(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:nth-child(3)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextAll().Length() + } else { + sel.NextAll() + } + } + if n != 234 { + b.Fatalf("want 234, got %d", n) + } +} + +func BenchmarkNextAllFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:nth-child(3)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextAllFiltered("[class]").Length() + } else { + sel.NextAllFiltered("[class]") + } + } + if n != 33 { + b.Fatalf("want 33, got %d", n) + } +} + +func BenchmarkPrev(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:last-child") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Prev().Length() + } else { + sel.Prev() + } + } + if n != 49 { + b.Fatalf("want 49, got %d", n) + } +} + +func BenchmarkPrevFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:last-child") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevFiltered("[class]").Length() + } else { + sel.PrevFiltered("[class]") + } + } + // There is one more Prev li with a class, compared to Next li with a class + // (confirmed by looking at the HTML, this is ok) + if n != 7 { + b.Fatalf("want 7, got %d", n) + } +} + +func BenchmarkPrevAll(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:nth-child(4)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevAll().Length() + } else { + sel.PrevAll() + } + } + if n != 78 { + b.Fatalf("want 78, got %d", n) + } +} + +func BenchmarkPrevAllFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:nth-child(4)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevAllFiltered("[class]").Length() + } else { + sel.PrevAllFiltered("[class]") + } + } + if n != 6 { + b.Fatalf("want 6, got %d", n) + } +} + +func BenchmarkNextUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:first-child") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextUntil(":nth-child(4)").Length() + } else { + sel.NextUntil(":nth-child(4)") + } + } + if n != 84 { + b.Fatalf("want 84, got %d", n) + } +} + +func BenchmarkNextUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("ul") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextUntilSelection(sel2).Length() + } else { + sel.NextUntilSelection(sel2) + } + } + if n != 42 { + b.Fatalf("want 42, got %d", n) + } +} + +func BenchmarkNextUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("p") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextUntilNodes(nodes...).Length() + } else { + sel.NextUntilNodes(nodes...) + } + } + if n != 12 { + b.Fatalf("want 12, got %d", n) + } +} + +func BenchmarkPrevUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("li:last-child") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevUntil(":nth-child(4)").Length() + } else { + sel.PrevUntil(":nth-child(4)") + } + } + if n != 238 { + b.Fatalf("want 238, got %d", n) + } +} + +func BenchmarkPrevUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("ul") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevUntilSelection(sel2).Length() + } else { + sel.PrevUntilSelection(sel2) + } + } + if n != 49 { + b.Fatalf("want 49, got %d", n) + } +} + +func BenchmarkPrevUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("p") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevUntilNodes(nodes...).Length() + } else { + sel.PrevUntilNodes(nodes...) + } + } + if n != 11 { + b.Fatalf("want 11, got %d", n) + } +} + +func BenchmarkNextFilteredUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextFilteredUntil("p", "div").Length() + } else { + sel.NextFilteredUntil("p", "div") + } + } + if n != 22 { + b.Fatalf("want 22, got %d", n) + } +} + +func BenchmarkNextFilteredUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("div") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextFilteredUntilSelection("p", sel2).Length() + } else { + sel.NextFilteredUntilSelection("p", sel2) + } + } + if n != 22 { + b.Fatalf("want 22, got %d", n) + } +} + +func BenchmarkNextFilteredUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("div") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.NextFilteredUntilNodes("p", nodes...).Length() + } else { + sel.NextFilteredUntilNodes("p", nodes...) + } + } + if n != 22 { + b.Fatalf("want 22, got %d", n) + } +} + +func BenchmarkPrevFilteredUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevFilteredUntil("p", "div").Length() + } else { + sel.PrevFilteredUntil("p", "div") + } + } + if n != 20 { + b.Fatalf("want 20, got %d", n) + } +} + +func BenchmarkPrevFilteredUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("div") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevFilteredUntilSelection("p", sel2).Length() + } else { + sel.PrevFilteredUntilSelection("p", sel2) + } + } + if n != 20 { + b.Fatalf("want 20, got %d", n) + } +} + +func BenchmarkPrevFilteredUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Find("h2") + sel2 := DocW().Find("div") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.PrevFilteredUntilNodes("p", nodes...).Length() + } else { + sel.PrevFilteredUntilNodes("p", nodes...) + } + } + if n != 20 { + b.Fatalf("want 20, got %d", n) + } +} + +func BenchmarkClosest(b *testing.B) { + var n int + + b.StopTimer() + sel := Doc().Find(".container-fluid") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Closest(".pvk-content").Length() + } else { + sel.Closest(".pvk-content") + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkClosestSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".pvk-content") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ClosestSelection(sel2).Length() + } else { + sel.ClosestSelection(sel2) + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} + +func BenchmarkClosestNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := Doc().Find(".container-fluid") + nodes := Doc().Find(".pvk-content").Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ClosestNodes(nodes...).Length() + } else { + sel.ClosestNodes(nodes...) + } + } + if n != 2 { + b.Fatalf("want 2, got %d", n) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/doc.go b/vendor/github.com/PuerkitoBio/goquery/doc.go new file mode 100644 index 0000000..71146a7 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/doc.go @@ -0,0 +1,123 @@ +// Copyright (c) 2012-2016, Martin Angers & Contributors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation and/or +// other materials provided with the distribution. +// * Neither the name of the author nor the names of its contributors may be used to +// endorse or promote products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY +// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* +Package goquery implements features similar to jQuery, including the chainable +syntax, to manipulate and query an HTML document. + +It brings a syntax and a set of features similar to jQuery to the Go language. +It is based on Go's net/html package and the CSS Selector library cascadia. +Since the net/html parser returns nodes, and not a full-featured DOM +tree, jQuery's stateful manipulation functions (like height(), css(), detach()) +have been left off. + +Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is +the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. +See the repository's wiki for various options on how to do this. + +Syntax-wise, it is as close as possible to jQuery, with the same method names when +possible, and that warm and fuzzy chainable interface. jQuery being the +ultra-popular library that it is, writing a similar HTML-manipulating +library was better to follow its API than to start anew (in the same spirit as +Go's fmt package), even though some of its methods are less than intuitive (looking +at you, index()...). + +It is hosted on GitHub, along with additional documentation in the README.md +file: https://github.com/puerkitobio/goquery + +Please note that because of the net/html dependency, goquery requires Go1.1+. + +The various methods are split into files based on the category of behavior. +The three dots (...) indicate that various "overloads" are available. + +* array.go : array-like positional manipulation of the selection. + - Eq() + - First() + - Get() + - Index...() + - Last() + - Slice() + +* expand.go : methods that expand or augment the selection's set. + - Add...() + - AndSelf() + - Union(), which is an alias for AddSelection() + +* filter.go : filtering methods, that reduce the selection's set. + - End() + - Filter...() + - Has...() + - Intersection(), which is an alias of FilterSelection() + - Not...() + +* iteration.go : methods to loop over the selection's nodes. + - Each() + - EachWithBreak() + - Map() + +* manipulation.go : methods for modifying the document + - After...() + - Append...() + - Before...() + - Clone() + - Empty() + - Prepend...() + - Remove...() + - ReplaceWith...() + - Unwrap() + - Wrap...() + - WrapAll...() + - WrapInner...() + +* property.go : methods that inspect and get the node's properties values. + - Attr*(), RemoveAttr(), SetAttr() + - AddClass(), HasClass(), RemoveClass(), ToggleClass() + - Html() + - Length() + - Size(), which is an alias for Length() + - Text() + +* query.go : methods that query, or reflect, a node's identity. + - Contains() + - Is...() + +* traversal.go : methods to traverse the HTML document tree. + - Children...() + - Contents() + - Find...() + - Next...() + - Parent[s]...() + - Prev...() + - Siblings...() + +* type.go : definition of the types exposed by goquery. + - Document + - Selection + - Matcher + +* utilities.go : definition of helper functions (and not methods on a *Selection) +that are not part of jQuery, but are useful to goquery. + - NodeName + - OuterHtml +*/ +package goquery diff --git a/vendor/github.com/PuerkitoBio/goquery/example_test.go b/vendor/github.com/PuerkitoBio/goquery/example_test.go new file mode 100644 index 0000000..bc97f05 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/example_test.go @@ -0,0 +1,82 @@ +package goquery_test + +import ( + "fmt" + "log" + "net/http" + "os" + "strings" + + "github.com/PuerkitoBio/goquery" +) + +// This example scrapes the reviews shown on the home page of metalsucks.net. +func Example() { + // Request the HTML page. + res, err := http.Get("http://metalsucks.net") + if err != nil { + log.Fatal(err) + } + defer res.Body.Close() + if res.StatusCode != 200 { + log.Fatalf("status code error: %d %s", res.StatusCode, res.Status) + } + + // Load the HTML document + doc, err := goquery.NewDocumentFromReader(res.Body) + if err != nil { + log.Fatal(err) + } + + // Find the review items + doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) { + // For each item found, get the band and title + band := s.Find("a").Text() + title := s.Find("i").Text() + fmt.Printf("Review %d: %s - %s\n", i, band, title) + }) + // To see the output of the Example while running the test suite (go test), simply + // remove the leading "x" before Output on the next line. This will cause the + // example to fail (all the "real" tests should pass). + + // xOutput: voluntarily fail the Example output. +} + +// This example shows how to use NewDocumentFromReader from a file. +func ExampleNewDocumentFromReader_file() { + // create from a file + f, err := os.Open("some/file.html") + if err != nil { + log.Fatal(err) + } + defer f.Close() + doc, err := goquery.NewDocumentFromReader(f) + if err != nil { + log.Fatal(err) + } + // use the goquery document... + _ = doc.Find("h1") +} + +// This example shows how to use NewDocumentFromReader from a string. +func ExampleNewDocumentFromReader_string() { + // create from a string + data := ` + + + My document + + +

Header

+ +` + + doc, err := goquery.NewDocumentFromReader(strings.NewReader(data)) + if err != nil { + log.Fatal(err) + } + header := doc.Find("h1").Text() + fmt.Println(header) + + // Output: Header +} diff --git a/vendor/github.com/PuerkitoBio/goquery/expand.go b/vendor/github.com/PuerkitoBio/goquery/expand.go new file mode 100644 index 0000000..7caade5 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/expand.go @@ -0,0 +1,70 @@ +package goquery + +import "golang.org/x/net/html" + +// Add adds the selector string's matching nodes to those in the current +// selection and returns a new Selection object. +// The selector string is run in the context of the document of the current +// Selection object. +func (s *Selection) Add(selector string) *Selection { + return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...) +} + +// AddMatcher adds the matcher's matching nodes to those in the current +// selection and returns a new Selection object. +// The matcher is run in the context of the document of the current +// Selection object. +func (s *Selection) AddMatcher(m Matcher) *Selection { + return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...) +} + +// AddSelection adds the specified Selection object's nodes to those in the +// current selection and returns a new Selection object. +func (s *Selection) AddSelection(sel *Selection) *Selection { + if sel == nil { + return s.AddNodes() + } + return s.AddNodes(sel.Nodes...) +} + +// Union is an alias for AddSelection. +func (s *Selection) Union(sel *Selection) *Selection { + return s.AddSelection(sel) +} + +// AddNodes adds the specified nodes to those in the +// current selection and returns a new Selection object. +func (s *Selection) AddNodes(nodes ...*html.Node) *Selection { + return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil)) +} + +// AndSelf adds the previous set of elements on the stack to the current set. +// It returns a new Selection object containing the current Selection combined +// with the previous one. +// Deprecated: This function has been deprecated and is now an alias for AddBack(). +func (s *Selection) AndSelf() *Selection { + return s.AddBack() +} + +// AddBack adds the previous set of elements on the stack to the current set. +// It returns a new Selection object containing the current Selection combined +// with the previous one. +func (s *Selection) AddBack() *Selection { + return s.AddSelection(s.prevSel) +} + +// AddBackFiltered reduces the previous set of elements on the stack to those that +// match the selector string, and adds them to the current set. +// It returns a new Selection object containing the current Selection combined +// with the filtered previous one +func (s *Selection) AddBackFiltered(selector string) *Selection { + return s.AddSelection(s.prevSel.Filter(selector)) +} + +// AddBackMatcher reduces the previous set of elements on the stack to those that match +// the mateher, and adds them to the curernt set. +// It returns a new Selection object containing the current Selection combined +// with the filtered previous one +func (s *Selection) AddBackMatcher(m Matcher) *Selection { + return s.AddSelection(s.prevSel.FilterMatcher(m)) +} diff --git a/vendor/github.com/PuerkitoBio/goquery/expand_test.go b/vendor/github.com/PuerkitoBio/goquery/expand_test.go new file mode 100644 index 0000000..c034dc6 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/expand_test.go @@ -0,0 +1,118 @@ +package goquery + +import ( + "testing" +) + +func TestAdd(t *testing.T) { + sel := Doc().Find("div.row-fluid").Add("a") + assertLength(t, sel.Nodes, 19) +} + +func TestAddInvalid(t *testing.T) { + sel1 := Doc().Find("div.row-fluid") + sel2 := sel1.Add("") + assertLength(t, sel1.Nodes, 9) + assertLength(t, sel2.Nodes, 9) + if sel1 == sel2 { + t.Errorf("selections should not be the same") + } +} + +func TestAddRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Add("a").End() + assertEqual(t, sel, sel2) +} + +func TestAddSelection(t *testing.T) { + sel := Doc().Find("div.row-fluid") + sel2 := Doc().Find("a") + sel = sel.AddSelection(sel2) + assertLength(t, sel.Nodes, 19) +} + +func TestAddSelectionNil(t *testing.T) { + sel := Doc().Find("div.row-fluid") + assertLength(t, sel.Nodes, 9) + + sel = sel.AddSelection(nil) + assertLength(t, sel.Nodes, 9) +} + +func TestAddSelectionRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Find("a") + sel2 = sel.AddSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestAddNodes(t *testing.T) { + sel := Doc().Find("div.pvk-gutter") + sel2 := Doc().Find(".pvk-content") + sel = sel.AddNodes(sel2.Nodes...) + assertLength(t, sel.Nodes, 9) +} + +func TestAddNodesNone(t *testing.T) { + sel := Doc().Find("div.pvk-gutter").AddNodes() + assertLength(t, sel.Nodes, 6) +} + +func TestAddNodesRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Find("a") + sel2 = sel.AddNodes(sel2.Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestAddNodesBig(t *testing.T) { + doc := DocW() + sel := doc.Find("li") + assertLength(t, sel.Nodes, 373) + sel2 := doc.Find("xyz") + assertLength(t, sel2.Nodes, 0) + + nodes := sel.Nodes + sel2 = sel2.AddNodes(nodes...) + assertLength(t, sel2.Nodes, 373) + nodes2 := append(nodes, nodes...) + sel2 = sel2.End().AddNodes(nodes2...) + assertLength(t, sel2.Nodes, 373) + nodes3 := append(nodes2, nodes...) + sel2 = sel2.End().AddNodes(nodes3...) + assertLength(t, sel2.Nodes, 373) +} + +func TestAndSelf(t *testing.T) { + sel := Doc().Find(".span12").Last().AndSelf() + assertLength(t, sel.Nodes, 2) +} + +func TestAndSelfRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Find("a").AndSelf().End().End() + assertEqual(t, sel, sel2) +} + +func TestAddBack(t *testing.T) { + sel := Doc().Find(".span12").Last().AddBack() + assertLength(t, sel.Nodes, 2) +} + +func TestAddBackRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Find("a").AddBack().End().End() + assertEqual(t, sel, sel2) +} + +func TestAddBackFiltered(t *testing.T) { + sel := Doc().Find(".span12, .footer").Find("h1").AddBackFiltered(".footer") + assertLength(t, sel.Nodes, 2) +} + +func TestAddBackFilteredRollback(t *testing.T) { + sel := Doc().Find(".span12, .footer") + sel2 := sel.Find("h1").AddBackFiltered(".footer").End().End() + assertEqual(t, sel, sel2) +} diff --git a/vendor/github.com/PuerkitoBio/goquery/filter.go b/vendor/github.com/PuerkitoBio/goquery/filter.go new file mode 100644 index 0000000..9138ffb --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/filter.go @@ -0,0 +1,163 @@ +package goquery + +import "golang.org/x/net/html" + +// Filter reduces the set of matched elements to those that match the selector string. +// It returns a new Selection object for this subset of matching elements. +func (s *Selection) Filter(selector string) *Selection { + return s.FilterMatcher(compileMatcher(selector)) +} + +// FilterMatcher reduces the set of matched elements to those that match +// the given matcher. It returns a new Selection object for this subset +// of matching elements. +func (s *Selection) FilterMatcher(m Matcher) *Selection { + return pushStack(s, winnow(s, m, true)) +} + +// Not removes elements from the Selection that match the selector string. +// It returns a new Selection object with the matching elements removed. +func (s *Selection) Not(selector string) *Selection { + return s.NotMatcher(compileMatcher(selector)) +} + +// NotMatcher removes elements from the Selection that match the given matcher. +// It returns a new Selection object with the matching elements removed. +func (s *Selection) NotMatcher(m Matcher) *Selection { + return pushStack(s, winnow(s, m, false)) +} + +// FilterFunction reduces the set of matched elements to those that pass the function's test. +// It returns a new Selection object for this subset of elements. +func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection { + return pushStack(s, winnowFunction(s, f, true)) +} + +// NotFunction removes elements from the Selection that pass the function's test. +// It returns a new Selection object with the matching elements removed. +func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection { + return pushStack(s, winnowFunction(s, f, false)) +} + +// FilterNodes reduces the set of matched elements to those that match the specified nodes. +// It returns a new Selection object for this subset of elements. +func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection { + return pushStack(s, winnowNodes(s, nodes, true)) +} + +// NotNodes removes elements from the Selection that match the specified nodes. +// It returns a new Selection object with the matching elements removed. +func (s *Selection) NotNodes(nodes ...*html.Node) *Selection { + return pushStack(s, winnowNodes(s, nodes, false)) +} + +// FilterSelection reduces the set of matched elements to those that match a +// node in the specified Selection object. +// It returns a new Selection object for this subset of elements. +func (s *Selection) FilterSelection(sel *Selection) *Selection { + if sel == nil { + return pushStack(s, winnowNodes(s, nil, true)) + } + return pushStack(s, winnowNodes(s, sel.Nodes, true)) +} + +// NotSelection removes elements from the Selection that match a node in the specified +// Selection object. It returns a new Selection object with the matching elements removed. +func (s *Selection) NotSelection(sel *Selection) *Selection { + if sel == nil { + return pushStack(s, winnowNodes(s, nil, false)) + } + return pushStack(s, winnowNodes(s, sel.Nodes, false)) +} + +// Intersection is an alias for FilterSelection. +func (s *Selection) Intersection(sel *Selection) *Selection { + return s.FilterSelection(sel) +} + +// Has reduces the set of matched elements to those that have a descendant +// that matches the selector. +// It returns a new Selection object with the matching elements. +func (s *Selection) Has(selector string) *Selection { + return s.HasSelection(s.document.Find(selector)) +} + +// HasMatcher reduces the set of matched elements to those that have a descendant +// that matches the matcher. +// It returns a new Selection object with the matching elements. +func (s *Selection) HasMatcher(m Matcher) *Selection { + return s.HasSelection(s.document.FindMatcher(m)) +} + +// HasNodes reduces the set of matched elements to those that have a +// descendant that matches one of the nodes. +// It returns a new Selection object with the matching elements. +func (s *Selection) HasNodes(nodes ...*html.Node) *Selection { + return s.FilterFunction(func(_ int, sel *Selection) bool { + // Add all nodes that contain one of the specified nodes + for _, n := range nodes { + if sel.Contains(n) { + return true + } + } + return false + }) +} + +// HasSelection reduces the set of matched elements to those that have a +// descendant that matches one of the nodes of the specified Selection object. +// It returns a new Selection object with the matching elements. +func (s *Selection) HasSelection(sel *Selection) *Selection { + if sel == nil { + return s.HasNodes() + } + return s.HasNodes(sel.Nodes...) +} + +// End ends the most recent filtering operation in the current chain and +// returns the set of matched elements to its previous state. +func (s *Selection) End() *Selection { + if s.prevSel != nil { + return s.prevSel + } + return newEmptySelection(s.document) +} + +// Filter based on the matcher, and the indicator to keep (Filter) or +// to get rid of (Not) the matching elements. +func winnow(sel *Selection, m Matcher, keep bool) []*html.Node { + // Optimize if keep is requested + if keep { + return m.Filter(sel.Nodes) + } + // Use grep + return grep(sel, func(i int, s *Selection) bool { + return !m.Match(s.Get(0)) + }) +} + +// Filter based on an array of nodes, and the indicator to keep (Filter) or +// to get rid of (Not) the matching elements. +func winnowNodes(sel *Selection, nodes []*html.Node, keep bool) []*html.Node { + if len(nodes)+len(sel.Nodes) < minNodesForSet { + return grep(sel, func(i int, s *Selection) bool { + return isInSlice(nodes, s.Get(0)) == keep + }) + } + + set := make(map[*html.Node]bool) + for _, n := range nodes { + set[n] = true + } + return grep(sel, func(i int, s *Selection) bool { + return set[s.Get(0)] == keep + }) +} + +// Filter based on a function test, and the indicator to keep (Filter) or +// to get rid of (Not) the matching elements. +func winnowFunction(sel *Selection, f func(int, *Selection) bool, keep bool) []*html.Node { + return grep(sel, func(i int, s *Selection) bool { + return f(i, s) == keep + }) +} diff --git a/vendor/github.com/PuerkitoBio/goquery/filter_test.go b/vendor/github.com/PuerkitoBio/goquery/filter_test.go new file mode 100644 index 0000000..f663c08 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/filter_test.go @@ -0,0 +1,206 @@ +package goquery + +import ( + "testing" +) + +func TestFilter(t *testing.T) { + sel := Doc().Find(".span12").Filter(".alert") + assertLength(t, sel.Nodes, 1) +} + +func TestFilterNone(t *testing.T) { + sel := Doc().Find(".span12").Filter(".zzalert") + assertLength(t, sel.Nodes, 0) +} + +func TestFilterInvalid(t *testing.T) { + sel := Doc().Find(".span12").Filter("") + assertLength(t, sel.Nodes, 0) +} + +func TestFilterRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Filter(".alert").End() + assertEqual(t, sel, sel2) +} + +func TestFilterFunction(t *testing.T) { + sel := Doc().Find(".pvk-content").FilterFunction(func(i int, s *Selection) bool { + return i > 0 + }) + assertLength(t, sel.Nodes, 2) +} + +func TestFilterFunctionRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.FilterFunction(func(i int, s *Selection) bool { + return i > 0 + }).End() + assertEqual(t, sel, sel2) +} + +func TestFilterNode(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.FilterNodes(sel.Nodes[2]) + assertLength(t, sel2.Nodes, 1) +} + +func TestFilterNodeRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.FilterNodes(sel.Nodes[2]).End() + assertEqual(t, sel, sel2) +} + +func TestFilterSelection(t *testing.T) { + sel := Doc().Find(".link") + sel2 := Doc().Find("a[ng-click]") + sel3 := sel.FilterSelection(sel2) + assertLength(t, sel3.Nodes, 1) +} + +func TestFilterSelectionRollback(t *testing.T) { + sel := Doc().Find(".link") + sel2 := Doc().Find("a[ng-click]") + sel2 = sel.FilterSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestFilterSelectionNil(t *testing.T) { + var sel2 *Selection + + sel := Doc().Find(".link") + sel3 := sel.FilterSelection(sel2) + assertLength(t, sel3.Nodes, 0) +} + +func TestNot(t *testing.T) { + sel := Doc().Find(".span12").Not(".alert") + assertLength(t, sel.Nodes, 1) +} + +func TestNotInvalid(t *testing.T) { + sel := Doc().Find(".span12").Not("") + assertLength(t, sel.Nodes, 2) +} + +func TestNotRollback(t *testing.T) { + sel := Doc().Find(".span12") + sel2 := sel.Not(".alert").End() + assertEqual(t, sel, sel2) +} + +func TestNotNone(t *testing.T) { + sel := Doc().Find(".span12").Not(".zzalert") + assertLength(t, sel.Nodes, 2) +} + +func TestNotFunction(t *testing.T) { + sel := Doc().Find(".pvk-content").NotFunction(func(i int, s *Selection) bool { + return i > 0 + }) + assertLength(t, sel.Nodes, 1) +} + +func TestNotFunctionRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.NotFunction(func(i int, s *Selection) bool { + return i > 0 + }).End() + assertEqual(t, sel, sel2) +} + +func TestNotNode(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.NotNodes(sel.Nodes[2]) + assertLength(t, sel2.Nodes, 2) +} + +func TestNotNodeRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.NotNodes(sel.Nodes[2]).End() + assertEqual(t, sel, sel2) +} + +func TestNotSelection(t *testing.T) { + sel := Doc().Find(".link") + sel2 := Doc().Find("a[ng-click]") + sel3 := sel.NotSelection(sel2) + assertLength(t, sel3.Nodes, 6) +} + +func TestNotSelectionRollback(t *testing.T) { + sel := Doc().Find(".link") + sel2 := Doc().Find("a[ng-click]") + sel2 = sel.NotSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestIntersection(t *testing.T) { + sel := Doc().Find(".pvk-gutter") + sel2 := Doc().Find("div").Intersection(sel) + assertLength(t, sel2.Nodes, 6) +} + +func TestIntersectionRollback(t *testing.T) { + sel := Doc().Find(".pvk-gutter") + sel2 := Doc().Find("div") + sel2 = sel.Intersection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestHas(t *testing.T) { + sel := Doc().Find(".container-fluid").Has(".center-content") + assertLength(t, sel.Nodes, 2) + // Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content +} + +func TestHasInvalid(t *testing.T) { + sel := Doc().Find(".container-fluid").Has("") + assertLength(t, sel.Nodes, 0) +} + +func TestHasRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.Has(".center-content").End() + assertEqual(t, sel, sel2) +} + +func TestHasNodes(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".center-content") + sel = sel.HasNodes(sel2.Nodes...) + assertLength(t, sel.Nodes, 2) + // Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content +} + +func TestHasNodesRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".center-content") + sel2 = sel.HasNodes(sel2.Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestHasSelection(t *testing.T) { + sel := Doc().Find("p") + sel2 := Doc().Find("small") + sel = sel.HasSelection(sel2) + assertLength(t, sel.Nodes, 1) +} + +func TestHasSelectionRollback(t *testing.T) { + sel := Doc().Find("p") + sel2 := Doc().Find("small") + sel2 = sel.HasSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestEnd(t *testing.T) { + sel := Doc().Find("p").Has("small").End() + assertLength(t, sel.Nodes, 4) +} + +func TestEndToTop(t *testing.T) { + sel := Doc().Find("p").Has("small").End().End().End() + assertLength(t, sel.Nodes, 0) +} diff --git a/vendor/github.com/PuerkitoBio/goquery/go.mod b/vendor/github.com/PuerkitoBio/goquery/go.mod new file mode 100644 index 0000000..2fa1332 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/go.mod @@ -0,0 +1,6 @@ +module github.com/PuerkitoBio/goquery + +require ( + github.com/andybalholm/cascadia v1.0.0 + golang.org/x/net v0.0.0-20181114220301-adae6a3d119a +) diff --git a/vendor/github.com/PuerkitoBio/goquery/go.sum b/vendor/github.com/PuerkitoBio/goquery/go.sum new file mode 100644 index 0000000..11c5757 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/go.sum @@ -0,0 +1,5 @@ +github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o= +github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/vendor/github.com/PuerkitoBio/goquery/iteration.go b/vendor/github.com/PuerkitoBio/goquery/iteration.go new file mode 100644 index 0000000..e246f2e --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/iteration.go @@ -0,0 +1,39 @@ +package goquery + +// Each iterates over a Selection object, executing a function for each +// matched element. It returns the current Selection object. The function +// f is called for each element in the selection with the index of the +// element in that selection starting at 0, and a *Selection that contains +// only that element. +func (s *Selection) Each(f func(int, *Selection)) *Selection { + for i, n := range s.Nodes { + f(i, newSingleSelection(n, s.document)) + } + return s +} + +// EachWithBreak iterates over a Selection object, executing a function for each +// matched element. It is identical to Each except that it is possible to break +// out of the loop by returning false in the callback function. It returns the +// current Selection object. +func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { + for i, n := range s.Nodes { + if !f(i, newSingleSelection(n, s.document)) { + return s + } + } + return s +} + +// Map passes each element in the current matched set through a function, +// producing a slice of string holding the returned values. The function +// f is called for each element in the selection with the index of the +// element in that selection starting at 0, and a *Selection that contains +// only that element. +func (s *Selection) Map(f func(int, *Selection) string) (result []string) { + for i, n := range s.Nodes { + result = append(result, f(i, newSingleSelection(n, s.document))) + } + + return result +} diff --git a/vendor/github.com/PuerkitoBio/goquery/iteration_test.go b/vendor/github.com/PuerkitoBio/goquery/iteration_test.go new file mode 100644 index 0000000..9b6aafb --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/iteration_test.go @@ -0,0 +1,88 @@ +package goquery + +import ( + "testing" + + "golang.org/x/net/html" +) + +func TestEach(t *testing.T) { + var cnt int + + sel := Doc().Find(".hero-unit .row-fluid").Each(func(i int, n *Selection) { + cnt++ + t.Logf("At index %v, node %v", i, n.Nodes[0].Data) + }).Find("a") + + if cnt != 4 { + t.Errorf("Expected Each() to call function 4 times, got %v times.", cnt) + } + assertLength(t, sel.Nodes, 6) +} + +func TestEachWithBreak(t *testing.T) { + var cnt int + + sel := Doc().Find(".hero-unit .row-fluid").EachWithBreak(func(i int, n *Selection) bool { + cnt++ + t.Logf("At index %v, node %v", i, n.Nodes[0].Data) + return false + }).Find("a") + + if cnt != 1 { + t.Errorf("Expected Each() to call function 1 time, got %v times.", cnt) + } + assertLength(t, sel.Nodes, 6) +} + +func TestEachEmptySelection(t *testing.T) { + var cnt int + + sel := Doc().Find("zzzz") + sel.Each(func(i int, n *Selection) { + cnt++ + }) + if cnt > 0 { + t.Error("Expected Each() to not be called on empty Selection.") + } + sel2 := sel.Find("div") + assertLength(t, sel2.Nodes, 0) +} + +func TestMap(t *testing.T) { + sel := Doc().Find(".pvk-content") + vals := sel.Map(func(i int, s *Selection) string { + n := s.Get(0) + if n.Type == html.ElementNode { + return n.Data + } + return "" + }) + for _, v := range vals { + if v != "div" { + t.Error("Expected Map array result to be all 'div's.") + } + } + if len(vals) != 3 { + t.Errorf("Expected Map array result to have a length of 3, found %v.", len(vals)) + } +} + +func TestForRange(t *testing.T) { + sel := Doc().Find(".pvk-content") + initLen := sel.Length() + for i := range sel.Nodes { + single := sel.Eq(i) + //h, err := single.Html() + //if err != nil { + // t.Fatal(err) + //} + //fmt.Println(i, h) + if single.Length() != 1 { + t.Errorf("%d: expected length of 1, got %d", i, single.Length()) + } + } + if sel.Length() != initLen { + t.Errorf("expected initial selection to still have length %d, got %d", initLen, sel.Length()) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/manipulation.go b/vendor/github.com/PuerkitoBio/goquery/manipulation.go new file mode 100644 index 0000000..34eb757 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/manipulation.go @@ -0,0 +1,574 @@ +package goquery + +import ( + "strings" + + "golang.org/x/net/html" +) + +// After applies the selector from the root document and inserts the matched elements +// after the elements in the set of matched elements. +// +// If one of the matched elements in the selection is not currently in the +// document, it's impossible to insert nodes after it, so it will be ignored. +// +// This follows the same rules as Selection.Append. +func (s *Selection) After(selector string) *Selection { + return s.AfterMatcher(compileMatcher(selector)) +} + +// AfterMatcher applies the matcher from the root document and inserts the matched elements +// after the elements in the set of matched elements. +// +// If one of the matched elements in the selection is not currently in the +// document, it's impossible to insert nodes after it, so it will be ignored. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AfterMatcher(m Matcher) *Selection { + return s.AfterNodes(m.MatchAll(s.document.rootNode)...) +} + +// AfterSelection inserts the elements in the selection after each element in the set of matched +// elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AfterSelection(sel *Selection) *Selection { + return s.AfterNodes(sel.Nodes...) +} + +// AfterHtml parses the html and inserts it after the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AfterHtml(html string) *Selection { + return s.AfterNodes(parseHtml(html)...) +} + +// AfterNodes inserts the nodes after each element in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AfterNodes(ns ...*html.Node) *Selection { + return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) { + if sn.Parent != nil { + sn.Parent.InsertBefore(n, sn.NextSibling) + } + }) +} + +// Append appends the elements specified by the selector to the end of each element +// in the set of matched elements, following those rules: +// +// 1) The selector is applied to the root document. +// +// 2) Elements that are part of the document will be moved to the new location. +// +// 3) If there are multiple locations to append to, cloned nodes will be +// appended to all target locations except the last one, which will be moved +// as noted in (2). +func (s *Selection) Append(selector string) *Selection { + return s.AppendMatcher(compileMatcher(selector)) +} + +// AppendMatcher appends the elements specified by the matcher to the end of each element +// in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AppendMatcher(m Matcher) *Selection { + return s.AppendNodes(m.MatchAll(s.document.rootNode)...) +} + +// AppendSelection appends the elements in the selection to the end of each element +// in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AppendSelection(sel *Selection) *Selection { + return s.AppendNodes(sel.Nodes...) +} + +// AppendHtml parses the html and appends it to the set of matched elements. +func (s *Selection) AppendHtml(html string) *Selection { + return s.AppendNodes(parseHtml(html)...) +} + +// AppendNodes appends the specified nodes to each node in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) AppendNodes(ns ...*html.Node) *Selection { + return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) { + sn.AppendChild(n) + }) +} + +// Before inserts the matched elements before each element in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) Before(selector string) *Selection { + return s.BeforeMatcher(compileMatcher(selector)) +} + +// BeforeMatcher inserts the matched elements before each element in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) BeforeMatcher(m Matcher) *Selection { + return s.BeforeNodes(m.MatchAll(s.document.rootNode)...) +} + +// BeforeSelection inserts the elements in the selection before each element in the set of matched +// elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) BeforeSelection(sel *Selection) *Selection { + return s.BeforeNodes(sel.Nodes...) +} + +// BeforeHtml parses the html and inserts it before the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) BeforeHtml(html string) *Selection { + return s.BeforeNodes(parseHtml(html)...) +} + +// BeforeNodes inserts the nodes before each element in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection { + return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) { + if sn.Parent != nil { + sn.Parent.InsertBefore(n, sn) + } + }) +} + +// Clone creates a deep copy of the set of matched nodes. The new nodes will not be +// attached to the document. +func (s *Selection) Clone() *Selection { + ns := newEmptySelection(s.document) + ns.Nodes = cloneNodes(s.Nodes) + return ns +} + +// Empty removes all children nodes from the set of matched elements. +// It returns the children nodes in a new Selection. +func (s *Selection) Empty() *Selection { + var nodes []*html.Node + + for _, n := range s.Nodes { + for c := n.FirstChild; c != nil; c = n.FirstChild { + n.RemoveChild(c) + nodes = append(nodes, c) + } + } + + return pushStack(s, nodes) +} + +// Prepend prepends the elements specified by the selector to each element in +// the set of matched elements, following the same rules as Append. +func (s *Selection) Prepend(selector string) *Selection { + return s.PrependMatcher(compileMatcher(selector)) +} + +// PrependMatcher prepends the elements specified by the matcher to each +// element in the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) PrependMatcher(m Matcher) *Selection { + return s.PrependNodes(m.MatchAll(s.document.rootNode)...) +} + +// PrependSelection prepends the elements in the selection to each element in +// the set of matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) PrependSelection(sel *Selection) *Selection { + return s.PrependNodes(sel.Nodes...) +} + +// PrependHtml parses the html and prepends it to the set of matched elements. +func (s *Selection) PrependHtml(html string) *Selection { + return s.PrependNodes(parseHtml(html)...) +} + +// PrependNodes prepends the specified nodes to each node in the set of +// matched elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) PrependNodes(ns ...*html.Node) *Selection { + return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) { + // sn.FirstChild may be nil, in which case this functions like + // sn.AppendChild() + sn.InsertBefore(n, sn.FirstChild) + }) +} + +// Remove removes the set of matched elements from the document. +// It returns the same selection, now consisting of nodes not in the document. +func (s *Selection) Remove() *Selection { + for _, n := range s.Nodes { + if n.Parent != nil { + n.Parent.RemoveChild(n) + } + } + + return s +} + +// RemoveFiltered removes the set of matched elements by selector. +// It returns the Selection of removed nodes. +func (s *Selection) RemoveFiltered(selector string) *Selection { + return s.RemoveMatcher(compileMatcher(selector)) +} + +// RemoveMatcher removes the set of matched elements. +// It returns the Selection of removed nodes. +func (s *Selection) RemoveMatcher(m Matcher) *Selection { + return s.FilterMatcher(m).Remove() +} + +// ReplaceWith replaces each element in the set of matched elements with the +// nodes matched by the given selector. +// It returns the removed elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) ReplaceWith(selector string) *Selection { + return s.ReplaceWithMatcher(compileMatcher(selector)) +} + +// ReplaceWithMatcher replaces each element in the set of matched elements with +// the nodes matched by the given Matcher. +// It returns the removed elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) ReplaceWithMatcher(m Matcher) *Selection { + return s.ReplaceWithNodes(m.MatchAll(s.document.rootNode)...) +} + +// ReplaceWithSelection replaces each element in the set of matched elements with +// the nodes from the given Selection. +// It returns the removed elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) ReplaceWithSelection(sel *Selection) *Selection { + return s.ReplaceWithNodes(sel.Nodes...) +} + +// ReplaceWithHtml replaces each element in the set of matched elements with +// the parsed HTML. +// It returns the removed elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) ReplaceWithHtml(html string) *Selection { + return s.ReplaceWithNodes(parseHtml(html)...) +} + +// ReplaceWithNodes replaces each element in the set of matched elements with +// the given nodes. +// It returns the removed elements. +// +// This follows the same rules as Selection.Append. +func (s *Selection) ReplaceWithNodes(ns ...*html.Node) *Selection { + s.AfterNodes(ns...) + return s.Remove() +} + +// SetHtml sets the html content of each element in the selection to +// specified html string. +func (s *Selection) SetHtml(html string) *Selection { + return setHtmlNodes(s, parseHtml(html)...) +} + +// SetText sets the content of each element in the selection to specified content. +// The provided text string is escaped. +func (s *Selection) SetText(text string) *Selection { + return s.SetHtml(html.EscapeString(text)) +} + +// Unwrap removes the parents of the set of matched elements, leaving the matched +// elements (and their siblings, if any) in their place. +// It returns the original selection. +func (s *Selection) Unwrap() *Selection { + s.Parent().Each(func(i int, ss *Selection) { + // For some reason, jquery allows unwrap to remove the element, so + // allowing it here too. Same for . Why it allows those elements to + // be unwrapped while not allowing body is a mystery to me. + if ss.Nodes[0].Data != "body" { + ss.ReplaceWithSelection(ss.Contents()) + } + }) + + return s +} + +// Wrap wraps each element in the set of matched elements inside the first +// element matched by the given selector. The matched child is cloned before +// being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) Wrap(selector string) *Selection { + return s.WrapMatcher(compileMatcher(selector)) +} + +// WrapMatcher wraps each element in the set of matched elements inside the +// first element matched by the given matcher. The matched child is cloned +// before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapMatcher(m Matcher) *Selection { + return s.wrapNodes(m.MatchAll(s.document.rootNode)...) +} + +// WrapSelection wraps each element in the set of matched elements inside the +// first element in the given Selection. The element is cloned before being +// inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapSelection(sel *Selection) *Selection { + return s.wrapNodes(sel.Nodes...) +} + +// WrapHtml wraps each element in the set of matched elements inside the inner- +// most child of the given HTML. +// +// It returns the original set of elements. +func (s *Selection) WrapHtml(html string) *Selection { + return s.wrapNodes(parseHtml(html)...) +} + +// WrapNode wraps each element in the set of matched elements inside the inner- +// most child of the given node. The given node is copied before being inserted +// into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapNode(n *html.Node) *Selection { + return s.wrapNodes(n) +} + +func (s *Selection) wrapNodes(ns ...*html.Node) *Selection { + s.Each(func(i int, ss *Selection) { + ss.wrapAllNodes(ns...) + }) + + return s +} + +// WrapAll wraps a single HTML structure, matched by the given selector, around +// all elements in the set of matched elements. The matched child is cloned +// before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapAll(selector string) *Selection { + return s.WrapAllMatcher(compileMatcher(selector)) +} + +// WrapAllMatcher wraps a single HTML structure, matched by the given Matcher, +// around all elements in the set of matched elements. The matched child is +// cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapAllMatcher(m Matcher) *Selection { + return s.wrapAllNodes(m.MatchAll(s.document.rootNode)...) +} + +// WrapAllSelection wraps a single HTML structure, the first node of the given +// Selection, around all elements in the set of matched elements. The matched +// child is cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapAllSelection(sel *Selection) *Selection { + return s.wrapAllNodes(sel.Nodes...) +} + +// WrapAllHtml wraps the given HTML structure around all elements in the set of +// matched elements. The matched child is cloned before being inserted into the +// document. +// +// It returns the original set of elements. +func (s *Selection) WrapAllHtml(html string) *Selection { + return s.wrapAllNodes(parseHtml(html)...) +} + +func (s *Selection) wrapAllNodes(ns ...*html.Node) *Selection { + if len(ns) > 0 { + return s.WrapAllNode(ns[0]) + } + return s +} + +// WrapAllNode wraps the given node around the first element in the Selection, +// making all other nodes in the Selection children of the given node. The node +// is cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapAllNode(n *html.Node) *Selection { + if s.Size() == 0 { + return s + } + + wrap := cloneNode(n) + + first := s.Nodes[0] + if first.Parent != nil { + first.Parent.InsertBefore(wrap, first) + first.Parent.RemoveChild(first) + } + + for c := getFirstChildEl(wrap); c != nil; c = getFirstChildEl(wrap) { + wrap = c + } + + newSingleSelection(wrap, s.document).AppendSelection(s) + + return s +} + +// WrapInner wraps an HTML structure, matched by the given selector, around the +// content of element in the set of matched elements. The matched child is +// cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapInner(selector string) *Selection { + return s.WrapInnerMatcher(compileMatcher(selector)) +} + +// WrapInnerMatcher wraps an HTML structure, matched by the given selector, +// around the content of element in the set of matched elements. The matched +// child is cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapInnerMatcher(m Matcher) *Selection { + return s.wrapInnerNodes(m.MatchAll(s.document.rootNode)...) +} + +// WrapInnerSelection wraps an HTML structure, matched by the given selector, +// around the content of element in the set of matched elements. The matched +// child is cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapInnerSelection(sel *Selection) *Selection { + return s.wrapInnerNodes(sel.Nodes...) +} + +// WrapInnerHtml wraps an HTML structure, matched by the given selector, around +// the content of element in the set of matched elements. The matched child is +// cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapInnerHtml(html string) *Selection { + return s.wrapInnerNodes(parseHtml(html)...) +} + +// WrapInnerNode wraps an HTML structure, matched by the given selector, around +// the content of element in the set of matched elements. The matched child is +// cloned before being inserted into the document. +// +// It returns the original set of elements. +func (s *Selection) WrapInnerNode(n *html.Node) *Selection { + return s.wrapInnerNodes(n) +} + +func (s *Selection) wrapInnerNodes(ns ...*html.Node) *Selection { + if len(ns) == 0 { + return s + } + + s.Each(func(i int, s *Selection) { + contents := s.Contents() + + if contents.Size() > 0 { + contents.wrapAllNodes(ns...) + } else { + s.AppendNodes(cloneNode(ns[0])) + } + }) + + return s +} + +func parseHtml(h string) []*html.Node { + // Errors are only returned when the io.Reader returns any error besides + // EOF, but strings.Reader never will + nodes, err := html.ParseFragment(strings.NewReader(h), &html.Node{Type: html.ElementNode}) + if err != nil { + panic("goquery: failed to parse HTML: " + err.Error()) + } + return nodes +} + +func setHtmlNodes(s *Selection, ns ...*html.Node) *Selection { + for _, n := range s.Nodes { + for c := n.FirstChild; c != nil; c = n.FirstChild { + n.RemoveChild(c) + } + for _, c := range ns { + n.AppendChild(cloneNode(c)) + } + } + return s +} + +// Get the first child that is an ElementNode +func getFirstChildEl(n *html.Node) *html.Node { + c := n.FirstChild + for c != nil && c.Type != html.ElementNode { + c = c.NextSibling + } + return c +} + +// Deep copy a slice of nodes. +func cloneNodes(ns []*html.Node) []*html.Node { + cns := make([]*html.Node, 0, len(ns)) + + for _, n := range ns { + cns = append(cns, cloneNode(n)) + } + + return cns +} + +// Deep copy a node. The new node has clones of all the original node's +// children but none of its parents or siblings. +func cloneNode(n *html.Node) *html.Node { + nn := &html.Node{ + Type: n.Type, + DataAtom: n.DataAtom, + Data: n.Data, + Attr: make([]html.Attribute, len(n.Attr)), + } + + copy(nn.Attr, n.Attr) + for c := n.FirstChild; c != nil; c = c.NextSibling { + nn.AppendChild(cloneNode(c)) + } + + return nn +} + +func (s *Selection) manipulateNodes(ns []*html.Node, reverse bool, + f func(sn *html.Node, n *html.Node)) *Selection { + + lasti := s.Size() - 1 + + // net.Html doesn't provide document fragments for insertion, so to get + // things in the correct order with After() and Prepend(), the callback + // needs to be called on the reverse of the nodes. + if reverse { + for i, j := 0, len(ns)-1; i < j; i, j = i+1, j-1 { + ns[i], ns[j] = ns[j], ns[i] + } + } + + for i, sn := range s.Nodes { + for _, n := range ns { + if i != lasti { + f(sn, cloneNode(n)) + } else { + if n.Parent != nil { + n.Parent.RemoveChild(n) + } + f(sn, n) + } + } + } + + return s +} diff --git a/vendor/github.com/PuerkitoBio/goquery/manipulation_test.go b/vendor/github.com/PuerkitoBio/goquery/manipulation_test.go new file mode 100644 index 0000000..c5f5022 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/manipulation_test.go @@ -0,0 +1,513 @@ +package goquery + +import ( + "testing" +) + +const ( + wrapHtml = "
test string

" +) + +func TestAfter(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").After("#nf6") + + assertLength(t, doc.Find("#main #nf6").Nodes, 0) + assertLength(t, doc.Find("#foot #nf6").Nodes, 0) + assertLength(t, doc.Find("#main + #nf6").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestAfterMany(t *testing.T) { + doc := Doc2Clone() + doc.Find(".one").After("#nf6") + + assertLength(t, doc.Find("#foot #nf6").Nodes, 1) + assertLength(t, doc.Find("#main #nf6").Nodes, 1) + assertLength(t, doc.Find(".one + #nf6").Nodes, 2) + printSel(t, doc.Selection) +} + +func TestAfterWithRemoved(t *testing.T) { + doc := Doc2Clone() + s := doc.Find("#main").Remove() + s.After("#nf6") + + assertLength(t, s.Find("#nf6").Nodes, 0) + assertLength(t, doc.Find("#nf6").Nodes, 0) + printSel(t, doc.Selection) +} + +func TestAfterSelection(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").AfterSelection(doc.Find("#nf1, #nf2")) + + assertLength(t, doc.Find("#main #nf1, #main #nf2").Nodes, 0) + assertLength(t, doc.Find("#foot #nf1, #foot #nf2").Nodes, 0) + assertLength(t, doc.Find("#main + #nf1, #nf1 + #nf2").Nodes, 2) + printSel(t, doc.Selection) +} + +func TestAfterHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").AfterHtml("new node") + + assertLength(t, doc.Find("#main + strong").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestAppend(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").Append("#nf6") + + assertLength(t, doc.Find("#foot #nf6").Nodes, 0) + assertLength(t, doc.Find("#main #nf6").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestAppendBody(t *testing.T) { + doc := Doc2Clone() + doc.Find("body").Append("#nf6") + + assertLength(t, doc.Find("#foot #nf6").Nodes, 0) + assertLength(t, doc.Find("#main #nf6").Nodes, 0) + assertLength(t, doc.Find("body > #nf6").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestAppendSelection(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").AppendSelection(doc.Find("#nf1, #nf2")) + + assertLength(t, doc.Find("#foot #nf1").Nodes, 0) + assertLength(t, doc.Find("#foot #nf2").Nodes, 0) + assertLength(t, doc.Find("#main #nf1").Nodes, 1) + assertLength(t, doc.Find("#main #nf2").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestAppendSelectionExisting(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").AppendSelection(doc.Find("#n1, #n2")) + + assertClass(t, doc.Find("#main :nth-child(1)"), "three") + assertClass(t, doc.Find("#main :nth-child(5)"), "one") + assertClass(t, doc.Find("#main :nth-child(6)"), "two") + printSel(t, doc.Selection) +} + +func TestAppendClone(t *testing.T) { + doc := Doc2Clone() + doc.Find("#n1").AppendSelection(doc.Find("#nf1").Clone()) + + assertLength(t, doc.Find("#foot #nf1").Nodes, 1) + assertLength(t, doc.Find("#main #nf1").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestAppendHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find("div").AppendHtml("new node") + + assertLength(t, doc.Find("strong").Nodes, 14) + printSel(t, doc.Selection) +} + +func TestBefore(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").Before("#nf6") + + assertLength(t, doc.Find("#main #nf6").Nodes, 0) + assertLength(t, doc.Find("#foot #nf6").Nodes, 0) + assertLength(t, doc.Find("body > #nf6:first-child").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestBeforeWithRemoved(t *testing.T) { + doc := Doc2Clone() + s := doc.Find("#main").Remove() + s.Before("#nf6") + + assertLength(t, s.Find("#nf6").Nodes, 0) + assertLength(t, doc.Find("#nf6").Nodes, 0) + printSel(t, doc.Selection) +} + +func TestBeforeSelection(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").BeforeSelection(doc.Find("#nf1, #nf2")) + + assertLength(t, doc.Find("#main #nf1, #main #nf2").Nodes, 0) + assertLength(t, doc.Find("#foot #nf1, #foot #nf2").Nodes, 0) + assertLength(t, doc.Find("body > #nf1:first-child, #nf1 + #nf2").Nodes, 2) + printSel(t, doc.Selection) +} + +func TestBeforeHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").BeforeHtml("new node") + + assertLength(t, doc.Find("body > strong:first-child").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestEmpty(t *testing.T) { + doc := Doc2Clone() + s := doc.Find("#main").Empty() + + assertLength(t, doc.Find("#main").Children().Nodes, 0) + assertLength(t, s.Filter("div").Nodes, 6) + printSel(t, doc.Selection) +} + +func TestPrepend(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").Prepend("#nf6") + + assertLength(t, doc.Find("#foot #nf6").Nodes, 0) + assertLength(t, doc.Find("#main #nf6:first-child").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestPrependBody(t *testing.T) { + doc := Doc2Clone() + doc.Find("body").Prepend("#nf6") + + assertLength(t, doc.Find("#foot #nf6").Nodes, 0) + assertLength(t, doc.Find("#main #nf6").Nodes, 0) + assertLength(t, doc.Find("body > #nf6:first-child").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestPrependSelection(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").PrependSelection(doc.Find("#nf1, #nf2")) + + assertLength(t, doc.Find("#foot #nf1").Nodes, 0) + assertLength(t, doc.Find("#foot #nf2").Nodes, 0) + assertLength(t, doc.Find("#main #nf1:first-child").Nodes, 1) + assertLength(t, doc.Find("#main #nf2:nth-child(2)").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestPrependSelectionExisting(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main").PrependSelection(doc.Find("#n5, #n6")) + + assertClass(t, doc.Find("#main :nth-child(1)"), "five") + assertClass(t, doc.Find("#main :nth-child(2)"), "six") + assertClass(t, doc.Find("#main :nth-child(5)"), "three") + assertClass(t, doc.Find("#main :nth-child(6)"), "four") + printSel(t, doc.Selection) +} + +func TestPrependClone(t *testing.T) { + doc := Doc2Clone() + doc.Find("#n1").PrependSelection(doc.Find("#nf1").Clone()) + + assertLength(t, doc.Find("#foot #nf1:first-child").Nodes, 1) + assertLength(t, doc.Find("#main #nf1:first-child").Nodes, 1) + printSel(t, doc.Selection) +} + +func TestPrependHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find("div").PrependHtml("new node") + + assertLength(t, doc.Find("strong:first-child").Nodes, 14) + printSel(t, doc.Selection) +} + +func TestRemove(t *testing.T) { + doc := Doc2Clone() + doc.Find("#nf1").Remove() + + assertLength(t, doc.Find("#foot #nf1").Nodes, 0) + printSel(t, doc.Selection) +} + +func TestRemoveAll(t *testing.T) { + doc := Doc2Clone() + doc.Find("*").Remove() + + assertLength(t, doc.Find("*").Nodes, 0) + printSel(t, doc.Selection) +} + +func TestRemoveRoot(t *testing.T) { + doc := Doc2Clone() + doc.Find("html").Remove() + + assertLength(t, doc.Find("html").Nodes, 0) + printSel(t, doc.Selection) +} + +func TestRemoveFiltered(t *testing.T) { + doc := Doc2Clone() + nf6 := doc.Find("#nf6") + s := doc.Find("div").RemoveFiltered("#nf6") + + assertLength(t, doc.Find("#nf6").Nodes, 0) + assertLength(t, s.Nodes, 1) + if nf6.Nodes[0] != s.Nodes[0] { + t.Error("Removed node does not match original") + } + printSel(t, doc.Selection) +} + +func TestReplaceWith(t *testing.T) { + doc := Doc2Clone() + + doc.Find("#nf6").ReplaceWith("#main") + assertLength(t, doc.Find("#foot #main:last-child").Nodes, 1) + printSel(t, doc.Selection) + + doc.Find("#foot").ReplaceWith("#main") + assertLength(t, doc.Find("#foot").Nodes, 0) + assertLength(t, doc.Find("#main").Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestReplaceWithHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find("#main, #foot").ReplaceWithHtml("
") + + assertLength(t, doc.Find("#replace").Nodes, 2) + + printSel(t, doc.Selection) +} + +func TestSetHtml(t *testing.T) { + doc := Doc2Clone() + q := doc.Find("#main, #foot") + q.SetHtml(`
test
`) + + assertLength(t, doc.Find("#replace").Nodes, 2) + assertLength(t, doc.Find("#main, #foot").Nodes, 2) + + if q.Text() != "testtest" { + t.Errorf("Expected text to be %v, found %v", "testtest", q.Text()) + } + + printSel(t, doc.Selection) +} + +func TestSetHtmlNoMatch(t *testing.T) { + doc := Doc2Clone() + q := doc.Find("#notthere") + q.SetHtml(`
test
`) + + assertLength(t, doc.Find("#replace").Nodes, 0) + + printSel(t, doc.Selection) +} + +func TestSetHtmlEmpty(t *testing.T) { + doc := Doc2Clone() + q := doc.Find("#main") + q.SetHtml(``) + + assertLength(t, doc.Find("#main").Nodes, 1) + assertLength(t, doc.Find("#main").Children().Nodes, 0) + printSel(t, doc.Selection) +} + +func TestSetText(t *testing.T) { + doc := Doc2Clone() + q := doc.Find("#main, #foot") + repl := "
test
" + q.SetText(repl) + + assertLength(t, doc.Find("#replace").Nodes, 0) + assertLength(t, doc.Find("#main, #foot").Nodes, 2) + + if q.Text() != (repl + repl) { + t.Errorf("Expected text to be %v, found %v", (repl + repl), q.Text()) + } + + h, err := q.Html() + if err != nil { + t.Errorf("Error: %v", err) + } + esc := "<div id="replace">test</div>" + if h != esc { + t.Errorf("Expected html to be %v, found %v", esc, h) + } + + printSel(t, doc.Selection) +} + +func TestReplaceWithSelection(t *testing.T) { + doc := Doc2Clone() + sel := doc.Find("#nf6").ReplaceWithSelection(doc.Find("#nf5")) + + assertSelectionIs(t, sel, "#nf6") + assertLength(t, doc.Find("#nf6").Nodes, 0) + assertLength(t, doc.Find("#nf5").Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestUnwrap(t *testing.T) { + doc := Doc2Clone() + + doc.Find("#nf5").Unwrap() + assertLength(t, doc.Find("#foot").Nodes, 0) + assertLength(t, doc.Find("body > #nf1").Nodes, 1) + assertLength(t, doc.Find("body > #nf5").Nodes, 1) + + printSel(t, doc.Selection) + + doc = Doc2Clone() + + doc.Find("#nf5, #n1").Unwrap() + assertLength(t, doc.Find("#foot").Nodes, 0) + assertLength(t, doc.Find("#main").Nodes, 0) + assertLength(t, doc.Find("body > #n1").Nodes, 1) + assertLength(t, doc.Find("body > #nf5").Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestUnwrapBody(t *testing.T) { + doc := Doc2Clone() + + doc.Find("#main").Unwrap() + assertLength(t, doc.Find("body").Nodes, 1) + assertLength(t, doc.Find("body > #main").Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestUnwrapHead(t *testing.T) { + doc := Doc2Clone() + + doc.Find("title").Unwrap() + assertLength(t, doc.Find("head").Nodes, 0) + assertLength(t, doc.Find("head > title").Nodes, 0) + assertLength(t, doc.Find("title").Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestUnwrapHtml(t *testing.T) { + doc := Doc2Clone() + + doc.Find("head").Unwrap() + assertLength(t, doc.Find("html").Nodes, 0) + assertLength(t, doc.Find("html head").Nodes, 0) + assertLength(t, doc.Find("head").Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestWrap(t *testing.T) { + doc := Doc2Clone() + doc.Find("#nf1").Wrap("#nf2") + nf1 := doc.Find("#foot #nf2 #nf1") + assertLength(t, nf1.Nodes, 1) + + nf2 := doc.Find("#nf2") + assertLength(t, nf2.Nodes, 2) + + printSel(t, doc.Selection) +} + +func TestWrapEmpty(t *testing.T) { + doc := Doc2Clone() + doc.Find("#nf1").Wrap("#doesnt-exist") + + origHtml, _ := Doc2().Html() + newHtml, _ := doc.Html() + + if origHtml != newHtml { + t.Error("Expected the two documents to be identical.") + } + + printSel(t, doc.Selection) +} + +func TestWrapHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find(".odd").WrapHtml(wrapHtml) + nf2 := doc.Find("#ins #nf2") + assertLength(t, nf2.Nodes, 1) + printSel(t, doc.Selection) +} + +func TestWrapSelection(t *testing.T) { + doc := Doc2Clone() + doc.Find("#nf1").WrapSelection(doc.Find("#nf2")) + nf1 := doc.Find("#foot #nf2 #nf1") + assertLength(t, nf1.Nodes, 1) + + nf2 := doc.Find("#nf2") + assertLength(t, nf2.Nodes, 2) + + printSel(t, doc.Selection) +} + +func TestWrapAll(t *testing.T) { + doc := Doc2Clone() + doc.Find(".odd").WrapAll("#nf1") + nf1 := doc.Find("#main #nf1") + assertLength(t, nf1.Nodes, 1) + + sel := nf1.Find("#n2 ~ #n4 ~ #n6 ~ #nf2 ~ #nf4 ~ #nf6") + assertLength(t, sel.Nodes, 1) + + printSel(t, doc.Selection) +} + +func TestWrapAllHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find(".odd").WrapAllHtml(wrapHtml) + nf1 := doc.Find("#main div#ins div p em b #n2 ~ #n4 ~ #n6 ~ #nf2 ~ #nf4 ~ #nf6") + assertLength(t, nf1.Nodes, 1) + printSel(t, doc.Selection) +} + +func TestWrapInnerNoContent(t *testing.T) { + doc := Doc2Clone() + doc.Find(".one").WrapInner(".two") + + twos := doc.Find(".two") + assertLength(t, twos.Nodes, 4) + assertLength(t, doc.Find(".one .two").Nodes, 2) + + printSel(t, doc.Selection) +} + +func TestWrapInnerWithContent(t *testing.T) { + doc := Doc3Clone() + doc.Find(".one").WrapInner(".two") + + twos := doc.Find(".two") + assertLength(t, twos.Nodes, 4) + assertLength(t, doc.Find(".one .two").Nodes, 2) + + printSel(t, doc.Selection) +} + +func TestWrapInnerNoWrapper(t *testing.T) { + doc := Doc2Clone() + doc.Find(".one").WrapInner(".not-exist") + + twos := doc.Find(".two") + assertLength(t, twos.Nodes, 2) + assertLength(t, doc.Find(".one").Nodes, 2) + assertLength(t, doc.Find(".one .two").Nodes, 0) + + printSel(t, doc.Selection) +} + +func TestWrapInnerHtml(t *testing.T) { + doc := Doc2Clone() + doc.Find("#foot").WrapInnerHtml(wrapHtml) + + foot := doc.Find("#foot div#ins div p em b #nf1 ~ #nf2 ~ #nf3") + assertLength(t, foot.Nodes, 1) + + printSel(t, doc.Selection) +} diff --git a/vendor/github.com/PuerkitoBio/goquery/property.go b/vendor/github.com/PuerkitoBio/goquery/property.go new file mode 100644 index 0000000..411126d --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/property.go @@ -0,0 +1,275 @@ +package goquery + +import ( + "bytes" + "regexp" + "strings" + + "golang.org/x/net/html" +) + +var rxClassTrim = regexp.MustCompile("[\t\r\n]") + +// Attr gets the specified attribute's value for the first element in the +// Selection. To get the value for each element individually, use a looping +// construct such as Each or Map method. +func (s *Selection) Attr(attrName string) (val string, exists bool) { + if len(s.Nodes) == 0 { + return + } + return getAttributeValue(attrName, s.Nodes[0]) +} + +// AttrOr works like Attr but returns default value if attribute is not present. +func (s *Selection) AttrOr(attrName, defaultValue string) string { + if len(s.Nodes) == 0 { + return defaultValue + } + + val, exists := getAttributeValue(attrName, s.Nodes[0]) + if !exists { + return defaultValue + } + + return val +} + +// RemoveAttr removes the named attribute from each element in the set of matched elements. +func (s *Selection) RemoveAttr(attrName string) *Selection { + for _, n := range s.Nodes { + removeAttr(n, attrName) + } + + return s +} + +// SetAttr sets the given attribute on each element in the set of matched elements. +func (s *Selection) SetAttr(attrName, val string) *Selection { + for _, n := range s.Nodes { + attr := getAttributePtr(attrName, n) + if attr == nil { + n.Attr = append(n.Attr, html.Attribute{Key: attrName, Val: val}) + } else { + attr.Val = val + } + } + + return s +} + +// Text gets the combined text contents of each element in the set of matched +// elements, including their descendants. +func (s *Selection) Text() string { + var buf bytes.Buffer + + // Slightly optimized vs calling Each: no single selection object created + var f func(*html.Node) + f = func(n *html.Node) { + if n.Type == html.TextNode { + // Keep newlines and spaces, like jQuery + buf.WriteString(n.Data) + } + if n.FirstChild != nil { + for c := n.FirstChild; c != nil; c = c.NextSibling { + f(c) + } + } + } + for _, n := range s.Nodes { + f(n) + } + + return buf.String() +} + +// Size is an alias for Length. +func (s *Selection) Size() int { + return s.Length() +} + +// Length returns the number of elements in the Selection object. +func (s *Selection) Length() int { + return len(s.Nodes) +} + +// Html gets the HTML contents of the first element in the set of matched +// elements. It includes text and comment nodes. +func (s *Selection) Html() (ret string, e error) { + // Since there is no .innerHtml, the HTML content must be re-created from + // the nodes using html.Render. + var buf bytes.Buffer + + if len(s.Nodes) > 0 { + for c := s.Nodes[0].FirstChild; c != nil; c = c.NextSibling { + e = html.Render(&buf, c) + if e != nil { + return + } + } + ret = buf.String() + } + + return +} + +// AddClass adds the given class(es) to each element in the set of matched elements. +// Multiple class names can be specified, separated by a space or via multiple arguments. +func (s *Selection) AddClass(class ...string) *Selection { + classStr := strings.TrimSpace(strings.Join(class, " ")) + + if classStr == "" { + return s + } + + tcls := getClassesSlice(classStr) + for _, n := range s.Nodes { + curClasses, attr := getClassesAndAttr(n, true) + for _, newClass := range tcls { + if !strings.Contains(curClasses, " "+newClass+" ") { + curClasses += newClass + " " + } + } + + setClasses(n, attr, curClasses) + } + + return s +} + +// HasClass determines whether any of the matched elements are assigned the +// given class. +func (s *Selection) HasClass(class string) bool { + class = " " + class + " " + for _, n := range s.Nodes { + classes, _ := getClassesAndAttr(n, false) + if strings.Contains(classes, class) { + return true + } + } + return false +} + +// RemoveClass removes the given class(es) from each element in the set of matched elements. +// Multiple class names can be specified, separated by a space or via multiple arguments. +// If no class name is provided, all classes are removed. +func (s *Selection) RemoveClass(class ...string) *Selection { + var rclasses []string + + classStr := strings.TrimSpace(strings.Join(class, " ")) + remove := classStr == "" + + if !remove { + rclasses = getClassesSlice(classStr) + } + + for _, n := range s.Nodes { + if remove { + removeAttr(n, "class") + } else { + classes, attr := getClassesAndAttr(n, true) + for _, rcl := range rclasses { + classes = strings.Replace(classes, " "+rcl+" ", " ", -1) + } + + setClasses(n, attr, classes) + } + } + + return s +} + +// ToggleClass adds or removes the given class(es) for each element in the set of matched elements. +// Multiple class names can be specified, separated by a space or via multiple arguments. +func (s *Selection) ToggleClass(class ...string) *Selection { + classStr := strings.TrimSpace(strings.Join(class, " ")) + + if classStr == "" { + return s + } + + tcls := getClassesSlice(classStr) + + for _, n := range s.Nodes { + classes, attr := getClassesAndAttr(n, true) + for _, tcl := range tcls { + if strings.Contains(classes, " "+tcl+" ") { + classes = strings.Replace(classes, " "+tcl+" ", " ", -1) + } else { + classes += tcl + " " + } + } + + setClasses(n, attr, classes) + } + + return s +} + +func getAttributePtr(attrName string, n *html.Node) *html.Attribute { + if n == nil { + return nil + } + + for i, a := range n.Attr { + if a.Key == attrName { + return &n.Attr[i] + } + } + return nil +} + +// Private function to get the specified attribute's value from a node. +func getAttributeValue(attrName string, n *html.Node) (val string, exists bool) { + if a := getAttributePtr(attrName, n); a != nil { + val = a.Val + exists = true + } + return +} + +// Get and normalize the "class" attribute from the node. +func getClassesAndAttr(n *html.Node, create bool) (classes string, attr *html.Attribute) { + // Applies only to element nodes + if n.Type == html.ElementNode { + attr = getAttributePtr("class", n) + if attr == nil && create { + n.Attr = append(n.Attr, html.Attribute{ + Key: "class", + Val: "", + }) + attr = &n.Attr[len(n.Attr)-1] + } + } + + if attr == nil { + classes = " " + } else { + classes = rxClassTrim.ReplaceAllString(" "+attr.Val+" ", " ") + } + + return +} + +func getClassesSlice(classes string) []string { + return strings.Split(rxClassTrim.ReplaceAllString(" "+classes+" ", " "), " ") +} + +func removeAttr(n *html.Node, attrName string) { + for i, a := range n.Attr { + if a.Key == attrName { + n.Attr[i], n.Attr[len(n.Attr)-1], n.Attr = + n.Attr[len(n.Attr)-1], html.Attribute{}, n.Attr[:len(n.Attr)-1] + return + } + } +} + +func setClasses(n *html.Node, attr *html.Attribute, classes string) { + classes = strings.TrimSpace(classes) + if classes == "" { + removeAttr(n, "class") + return + } + + attr.Val = classes +} diff --git a/vendor/github.com/PuerkitoBio/goquery/property_test.go b/vendor/github.com/PuerkitoBio/goquery/property_test.go new file mode 100644 index 0000000..1095dcc --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/property_test.go @@ -0,0 +1,252 @@ +package goquery + +import ( + "regexp" + "strings" + "testing" +) + +func TestAttrExists(t *testing.T) { + if val, ok := Doc().Find("a").Attr("href"); !ok { + t.Error("Expected a value for the href attribute.") + } else { + t.Logf("Href of first anchor: %v.", val) + } +} + +func TestAttrOr(t *testing.T) { + if val := Doc().Find("a").AttrOr("fake-attribute", "alternative"); val != "alternative" { + t.Error("Expected an alternative value for 'fake-attribute' attribute.") + } else { + t.Logf("Value returned for not existing attribute: %v.", val) + } + if val := Doc().Find("zz").AttrOr("fake-attribute", "alternative"); val != "alternative" { + t.Error("Expected an alternative value for 'fake-attribute' on an empty selection.") + } else { + t.Logf("Value returned for empty selection: %v.", val) + } +} + +func TestAttrNotExist(t *testing.T) { + if val, ok := Doc().Find("div.row-fluid").Attr("href"); ok { + t.Errorf("Expected no value for the href attribute, got %v.", val) + } +} + +func TestRemoveAttr(t *testing.T) { + sel := Doc2Clone().Find("div") + + sel.RemoveAttr("id") + + _, ok := sel.Attr("id") + if ok { + t.Error("Expected there to be no id attributes set") + } +} + +func TestSetAttr(t *testing.T) { + sel := Doc2Clone().Find("#main") + + sel.SetAttr("id", "not-main") + + val, ok := sel.Attr("id") + if !ok { + t.Error("Expected an id attribute on main") + } + + if val != "not-main" { + t.Errorf("Expected an attribute id to be not-main, got %s", val) + } +} + +func TestSetAttr2(t *testing.T) { + sel := Doc2Clone().Find("#main") + + sel.SetAttr("foo", "bar") + + val, ok := sel.Attr("foo") + if !ok { + t.Error("Expected an 'foo' attribute on main") + } + + if val != "bar" { + t.Errorf("Expected an attribute 'foo' to be 'bar', got '%s'", val) + } +} + +func TestText(t *testing.T) { + txt := Doc().Find("h1").Text() + if strings.Trim(txt, " \n\r\t") != "Provok.in" { + t.Errorf("Expected text to be Provok.in, found %s.", txt) + } +} + +func TestText2(t *testing.T) { + txt := Doc().Find(".hero-unit .container-fluid .row-fluid:nth-child(1)").Text() + if ok, e := regexp.MatchString(`^\s+Provok\.in\s+Prove your point.\s+$`, txt); !ok || e != nil { + t.Errorf("Expected text to be Provok.in Prove your point., found %s.", txt) + if e != nil { + t.Logf("Error: %s.", e.Error()) + } + } +} + +func TestText3(t *testing.T) { + txt := Doc().Find(".pvk-gutter").First().Text() + // There's an   character in there... + if ok, e := regexp.MatchString(`^[\s\x{00A0}]+$`, txt); !ok || e != nil { + t.Errorf("Expected spaces, found <%v>.", txt) + if e != nil { + t.Logf("Error: %s.", e.Error()) + } + } +} + +func TestHtml(t *testing.T) { + txt, e := Doc().Find("h1").Html() + if e != nil { + t.Errorf("Error: %s.", e) + } + + if ok, e := regexp.MatchString(`^\s*Provok\.in\s*$`, txt); !ok || e != nil { + t.Errorf("Unexpected HTML content, found %s.", txt) + if e != nil { + t.Logf("Error: %s.", e.Error()) + } + } +} + +func TestNbsp(t *testing.T) { + src := `

Some text

` + 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.go b/vendor/github.com/PuerkitoBio/goquery/query.go new file mode 100644 index 0000000..fe86bf0 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/query.go @@ -0,0 +1,49 @@ +package goquery + +import "golang.org/x/net/html" + +// Is checks the current matched set of elements against a selector and +// returns true if at least one of these elements matches. +func (s *Selection) Is(selector string) bool { + return s.IsMatcher(compileMatcher(selector)) +} + +// IsMatcher checks the current matched set of elements against a matcher and +// returns true if at least one of these elements matches. +func (s *Selection) IsMatcher(m Matcher) bool { + if len(s.Nodes) > 0 { + if len(s.Nodes) == 1 { + return m.Match(s.Nodes[0]) + } + return len(m.Filter(s.Nodes)) > 0 + } + + return false +} + +// IsFunction checks the current matched set of elements against a predicate and +// returns true if at least one of these elements matches. +func (s *Selection) IsFunction(f func(int, *Selection) bool) bool { + return s.FilterFunction(f).Length() > 0 +} + +// IsSelection checks the current matched set of elements against a Selection object +// and returns true if at least one of these elements matches. +func (s *Selection) IsSelection(sel *Selection) bool { + return s.FilterSelection(sel).Length() > 0 +} + +// IsNodes checks the current matched set of elements against the specified nodes +// and returns true if at least one of these elements matches. +func (s *Selection) IsNodes(nodes ...*html.Node) bool { + return s.FilterNodes(nodes...).Length() > 0 +} + +// Contains returns true if the specified Node is within, +// at any depth, one of the nodes in the Selection object. +// It is NOT inclusive, to behave like jQuery's implementation, and +// unlike Javascript's .contains, so if the contained +// node is itself in the selection, it returns false. +func (s *Selection) Contains(n *html.Node) bool { + return sliceContains(s.Nodes, n) +} 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 0000000..54b2a2e --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/query_test.go @@ -0,0 +1,103 @@ +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 TestIsInvalid(t *testing.T) { + sel := Doc().Find(".footer p:nth-child(1)") + if sel.Is("") { + t.Error("Is should not succeed with invalid selector string") + } +} + +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 0000000..ba5348f --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/testdata/gotesting.html @@ -0,0 +1,855 @@ + + + + + + testing - The Go Programming Language + + + + + + + + + + +
+ +
+ + +
+ +
+ +
+ + +
+

Package testing

+ + + + + + + + + + +
+
+
import "testing"
+
+
+
Overview
+
Index
+ + +
Subdirectories
+ +
+
+ +
+ +
+

Overview â–¾

+

+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: +

+
func ExampleHello() {
+        fmt.Println("hello")
+        // Output: hello
+}
+
+func ExampleSalutations() {
+        fmt.Println("hello, and")
+        fmt.Println("goodbye")
+        // Output:
+        // hello, and
+        // goodbye
+}
+
+

+Example functions without output comments are compiled but not executed. +

+

+The naming convention to declare examples for a function F, a type T and +method M on type T are: +

+
func ExampleF() { ... }
+func ExampleT() { ... }
+func ExampleT_M() { ... }
+
+

+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. +

+
func ExampleF_suffix() { ... }
+func ExampleT_suffix() { ... }
+func ExampleT_M_suffix() { ... }
+
+

+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. +

+ +
+
+ + +

Index

+ +
+
+ + + + +
func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample)
+ + +
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark)
+ + +
func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool)
+ + +
func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool)
+ + +
func Short() bool
+ + + +
type B
+ + + +
    func (c *B) Error(args ...interface{})
+ + +
    func (c *B) Errorf(format string, args ...interface{})
+ + +
    func (c *B) Fail()
+ + +
    func (c *B) FailNow()
+ + +
    func (c *B) Failed() bool
+ + +
    func (c *B) Fatal(args ...interface{})
+ + +
    func (c *B) Fatalf(format string, args ...interface{})
+ + +
    func (c *B) Log(args ...interface{})
+ + +
    func (c *B) Logf(format string, args ...interface{})
+ + +
    func (b *B) ResetTimer()
+ + +
    func (b *B) SetBytes(n int64)
+ + +
    func (b *B) StartTimer()
+ + +
    func (b *B) StopTimer()
+ + + +
type BenchmarkResult
+ + +
    func Benchmark(f func(b *B)) BenchmarkResult
+ + + +
    func (r BenchmarkResult) NsPerOp() int64
+ + +
    func (r BenchmarkResult) String() string
+ + + +
type InternalBenchmark
+ + + + +
type InternalExample
+ + + + +
type InternalTest
+ + + + +
type T
+ + + +
    func (c *T) Error(args ...interface{})
+ + +
    func (c *T) Errorf(format string, args ...interface{})
+ + +
    func (c *T) Fail()
+ + +
    func (c *T) FailNow()
+ + +
    func (c *T) Failed() bool
+ + +
    func (c *T) Fatal(args ...interface{})
+ + +
    func (c *T) Fatalf(format string, args ...interface{})
+ + +
    func (c *T) Log(args ...interface{})
+ + +
    func (c *T) Logf(format string, args ...interface{})
+ + +
    func (t *T) Parallel()
+ + + +
+ + + + +

Package files

+

+ + + benchmark.go + + example.go + + testing.go + + +

+ + + + + + + +

func Main

+
func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample)
+

+An internal function but exported because it is cross-package; part of the implementation +of the "go test" command. +

+ + + + + +

func RunBenchmarks

+
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark)
+

+An internal function but exported because it is cross-package; part of the implementation +of the "go test" command. +

+ + + + + +

func RunExamples

+
func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool)
+ + + + + +

func RunTests

+
func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool)
+ + + + + +

func Short

+
func Short() bool
+

+Short reports whether the -test.short flag is set. +

+ + + + + + +

type B

+
type B struct {
+    N int
+    // contains filtered or unexported fields
+}
+

+B is a type passed to Benchmark functions to manage benchmark +timing and to specify the number of iterations to run. +

+ + + + + + + + + + + + +

func (*B) Error

+
func (c *B) Error(args ...interface{})
+

+Error is equivalent to Log() followed by Fail(). +

+ + + + + +

func (*B) Errorf

+
func (c *B) Errorf(format string, args ...interface{})
+

+Errorf is equivalent to Logf() followed by Fail(). +

+ + + + + +

func (*B) Fail

+
func (c *B) Fail()
+

+Fail marks the function as having failed but continues execution. +

+ + + + + +

func (*B) FailNow

+
func (c *B) FailNow()
+

+FailNow marks the function as having failed and stops its execution. +Execution will continue at the next test or benchmark. +

+ + + + + +

func (*B) Failed

+
func (c *B) Failed() bool
+

+Failed returns whether the function has failed. +

+ + + + + +

func (*B) Fatal

+
func (c *B) Fatal(args ...interface{})
+

+Fatal is equivalent to Log() followed by FailNow(). +

+ + + + + +

func (*B) Fatalf

+
func (c *B) Fatalf(format string, args ...interface{})
+

+Fatalf is equivalent to Logf() followed by FailNow(). +

+ + + + + +

func (*B) Log

+
func (c *B) Log(args ...interface{})
+

+Log formats its arguments using default formatting, analogous to Println(), +and records the text in the error log. +

+ + + + + +

func (*B) Logf

+
func (c *B) Logf(format string, args ...interface{})
+

+Logf formats its arguments according to the format, analogous to Printf(), +and records the text in the error log. +

+ + + + + +

func (*B) ResetTimer

+
func (b *B) ResetTimer()
+

+ResetTimer sets the elapsed benchmark time to zero. +It does not affect whether the timer is running. +

+ + + + + +

func (*B) SetBytes

+
func (b *B) SetBytes(n int64)
+

+SetBytes records the number of bytes processed in a single operation. +If this is called, the benchmark will report ns/op and MB/s. +

+ + + + + +

func (*B) StartTimer

+
func (b *B) StartTimer()
+

+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. +

+ + + + + +

func (*B) StopTimer

+
func (b *B) StopTimer()
+

+StopTimer stops timing a test. This can be used to pause the timer +while performing complex initialization that you don't +want to measure. +

+ + + + + + + +

type BenchmarkResult

+
type BenchmarkResult struct {
+    N     int           // The number of iterations.
+    T     time.Duration // The total time taken.
+    Bytes int64         // Bytes processed in one iteration.
+}
+

+The results of a benchmark run. +

+ + + + + + + + + + +

func Benchmark

+
func Benchmark(f func(b *B)) BenchmarkResult
+

+Benchmark benchmarks a single function. Useful for creating +custom benchmarks that do not use the "go test" command. +

+ + + + + + +

func (BenchmarkResult) NsPerOp

+
func (r BenchmarkResult) NsPerOp() int64
+ + + + + +

func (BenchmarkResult) String

+
func (r BenchmarkResult) String() string
+ + + + + + + +

type InternalBenchmark

+
type InternalBenchmark struct {
+    Name string
+    F    func(b *B)
+}
+

+An internal type but exported because it is cross-package; part of the implementation +of the "go test" command. +

+ + + + + + + + + + + + + + +

type InternalExample

+
type InternalExample struct {
+    Name   string
+    F      func()
+    Output string
+}
+ + + + + + + + + + + + + + +

type InternalTest

+
type InternalTest struct {
+    Name string
+    F    func(*T)
+}
+

+An internal type but exported because it is cross-package; part of the implementation +of the "go test" command. +

+ + + + + + + + + + + + + + +

type T

+
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. +

+ + + + + + + + + + + + +

func (*T) Error

+
func (c *T) Error(args ...interface{})
+

+Error is equivalent to Log() followed by Fail(). +

+ + + + + +

func (*T) Errorf

+
func (c *T) Errorf(format string, args ...interface{})
+

+Errorf is equivalent to Logf() followed by Fail(). +

+ + + + + +

func (*T) Fail

+
func (c *T) Fail()
+

+Fail marks the function as having failed but continues execution. +

+ + + + + +

func (*T) FailNow

+
func (c *T) FailNow()
+

+FailNow marks the function as having failed and stops its execution. +Execution will continue at the next test or benchmark. +

+ + + + + +

func (*T) Failed

+
func (c *T) Failed() bool
+

+Failed returns whether the function has failed. +

+ + + + + +

func (*T) Fatal

+
func (c *T) Fatal(args ...interface{})
+

+Fatal is equivalent to Log() followed by FailNow(). +

+ + + + + +

func (*T) Fatalf

+
func (c *T) Fatalf(format string, args ...interface{})
+

+Fatalf is equivalent to Logf() followed by FailNow(). +

+ + + + + +

func (*T) Log

+
func (c *T) Log(args ...interface{})
+

+Log formats its arguments using default formatting, analogous to Println(), +and records the text in the error log. +

+ + + + + +

func (*T) Logf

+
func (c *T) Logf(format string, args ...interface{})
+

+Logf formats its arguments according to the format, analogous to Printf(), +and records the text in the error log. +

+ + + + + +

func (*T) Parallel

+
func (t *T) Parallel()
+

+Parallel signals that this test is to be run in parallel with (and only with) +other parallel tests in this CPU group. +

+ + + + + +
+ + + + + + + + + + + + +

Subdirectories

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name    Synopsis
..
iotest    Package iotest implements Readers and Writers useful mainly for testing.
quick    Package quick implements utility functions to help with black box testing.
+ + + + +
+ + + + + + + + diff --git a/vendor/github.com/PuerkitoBio/goquery/testdata/gowiki.html b/vendor/github.com/PuerkitoBio/goquery/testdata/gowiki.html new file mode 100644 index 0000000..2ed6bb7 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/testdata/gowiki.html @@ -0,0 +1,1214 @@ + + + +Go (programming language) - Wikipedia, the free encyclopedia + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + +
+ + +

Go (programming language)

+ + +
+ +
From Wikipedia, the free encyclopedia
+ + +
  (Redirected from Golang)
+ + +
+ Jump to: navigation, search +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Go
Golang.png
Paradigm(s)compiled, concurrent, imperative, structured
Appeared in2009
Designed byRobert Griesemer
+Rob Pike
+Ken Thompson
DeveloperGoogle Inc.
Stable releaseversion 1.0.2[1] (14 June 2012; 2 months ago (2012-06-14))
Typing disciplinestrong, static
Major implementationsgc (8g, 6g, 5g), gccgo
Influenced byC, Limbo, Modula, Newsqueak, Oberon, Pascal,[2] Python
OSLinux, Mac OS X, FreeBSD, OpenBSD, MS Windows, Plan 9[3]
LicenseBSD-style[4] + Patent grant[5]
Usual filename extensions.go
Websitegolang.org
+

Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.[6]

+

The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.[2] Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being used "for real stuff" at Google.[7] Go's "gc" compiler targets the Linux, Mac OS X, FreeBSD, OpenBSD, Plan 9, and Microsoft Windows operating systems and the i386, amd64, and ARM processor architectures.[8]

+ + + + +
+
+

Contents

+
+ +
+

[edit] Goals

+

Go aims to provide the efficiency of a statically typed compiled language with the ease of programming of a dynamic language.[9] Other goals include:

+
    +
  • Safety: Type-safe and memory-safe.
  • +
  • Good support for concurrency and communication.
  • +
  • Efficient, latency-free garbage collection.
  • +
  • High-speed compilation.
  • +
+

[edit] Description

+

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's CSP. 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]

+

[edit] Type system

+

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.

+

Consider the following example:

+
+
+
+type Sequence []int
+ 
+func (s Sequence) Len() int {
+    return len(s)
+}
+ 
+type HasLength interface {
+    Len() int
+}
+ 
+func Foo (o HasLength) {
+    ...
+}
+
+
+

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.

+

[edit] Name visibility

+

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]

+

[edit] Concurrency

+

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.

+

[edit] Implementations

+

There are currently two Go compilers:

+
    +
  • 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]

+

[edit] Examples

+

[edit] Hello world

+

The following is a Hello world program in Go:

+
+
+
+package main
+ 
+import "fmt"
+ 
+func main() {
+        fmt.Println("Hello, World")
+}
+
+
+

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]

+

[edit] Echo

+

Example illustrating how to write a program like the Unix echo command in Go:[19]

+
+
+
+package main
+ 
+import (
+        "os"
+        "flag"  // command line option parser
+)
+ 
+var omitNewline = flag.Bool("n", false, "don't print final newline")
+ 
+const (
+        Space = " "
+        Newline = "\n"
+)
+ 
+func main() {
+        flag.Parse()   // Scans the arg list and sets up flags
+        var s string
+        for i := 0; i < flag.NArg(); i++ {
+                if i > 0 {
+                        s += Space
+                }
+                s += flag.Arg(i)
+        }
+        if !*omitNewline {
+                s += Newline
+        }
+        os.Stdout.WriteString(s)
+}
+
+
+

[edit] Reception

+

Go's initial release led to much discussion.

+

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 :-(
+
+

Dave Astels at Engine Yard wrote:[21]

+
+
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.
+
+

Go was in 15th place on the TIOBE Programming Community Index of programming language popularity in its first year, 2009,[citation needed] surpassing established languages like Pascal. As of March 2012, it ranked 66th in the index.[23]

+

Bruce Eckel stated:[24]

+
+
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.
+
+

[edit] Naming dispute

+

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]

+

[edit] See also

+ +

[edit] References

+ +
+
    +
  1. ^ "golang-announce: go1.0.2 released". https://groups.google.com/forum/#!msg/golang-announce/9-f_fnXNDzw/MiM3tk0iyjYJ. Retrieved 14 June 2012. 
  2. +
  3. ^ a b c d "Language Design FAQ". golang.org. 16 January 2010. http://golang.org/doc/go_faq.html. Retrieved 27 February 2010. 
  4. +
  5. ^ "Go Porting Efforts". Go Language Resources. cat-v. 12 January 2010. http://go-lang.cat-v.org/os-ports. Retrieved 18 January 2010. 
  6. +
  7. ^ "Text file LICENSE". http://golang.org/LICENSE. Retrieved 27 January 2011. 
  8. +
  9. ^ "Additional IP Rights Grant". http://code.google.com/p/go/source/browse/PATENTS. Retrieved 26 July 2012. 
  10. +
  11. ^ Kincaid, Jason (10 November 2009). "Google’s Go: A New Programming Language That’s Python Meets C++". TechCrunch. http://www.techcrunch.com/2009/11/10/google-go-language/. Retrieved 18 January 2010. 
  12. +
  13. ^ Metz, Cade (20 May 2010). "Google programming Frankenstein is a Go". The Register. http://www.theregister.co.uk/2010/05/20/go_in_production_at_google/. 
  14. +
  15. ^ "Installing Go". golang.org. The Go Authors. 11 June 2010. http://golang.org/doc/install.html#tmp_33. Retrieved 11 June 2010. 
  16. +
  17. ^ Pike, Rob. "The Go Programming Language". YouTube. http://www.youtube.com/watch?v=rKnDgT73v8s&feature=related. Retrieved 1 Jul 2011. 
  18. +
  19. ^ Rob Pike (10 November 2009) (flv). The Go Programming Language (Tech talk). Google. Event occurs at 8:53. http://www.youtube.com/watch?v=rKnDgT73v8s#t=8m53. 
  20. +
  21. ^ a b "The Go Memory Model". Google. http://golang.org/doc/go_mem.html. Retrieved 5 January 2011. 
  22. +
  23. ^ Release notes, 30 March 2010
  24. +
  25. ^ "Proposal for an exception-like mechanism". golang-nuts. 25 March 2010. http://groups.google.com/group/golang-nuts/browse_thread/thread/1ce5cd050bb973e4. Retrieved 25 March 2010. 
  26. +
  27. ^ "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." 
  28. +
  29. ^ "FAQ: Implementation". golang.org. 16 January 2010. http://golang.org/doc/go_faq.html#Implementation. Retrieved 18 January 2010. 
  30. +
  31. ^ "Installing GCC: Configuration". http://gcc.gnu.org/install/configure.html. Retrieved 3 December 2011. "Ada, Go and Objective-C++ are not default languages" 
  32. +
  33. ^ Gerrand, Andrew (1 February 2011). "release.2011-02-01". golang-nuts. Google. http://groups.google.com/group/golang-nuts/browse_thread/thread/b877e34723b543a7. Retrieved 5 February 2011. 
  34. +
  35. ^ "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." 
  36. +
  37. ^ "A Tutorial for the Go Programming Language". golang.org. 16 January 2010. http://golang.org/doc/go_tutorial.html. Retrieved 18 January 2010. 
  38. +
  39. ^ Simionato, Michele (15 November 2009). "Interfaces vs Inheritance (or, watch out for Go!)". artima. http://www.artima.com/weblogs/viewpost.jsp?thread=274019. Retrieved 15 November 2009. 
  40. +
  41. ^ Astels, Dave (9 November 2009). "Ready, Set, Go!". engineyard. http://www.engineyard.com/blog/2009/ready-set-go/. Retrieved 9 November 2009. 
  42. +
  43. ^ Paul, Ryan (10 November 2009). "Go: new open source programming language from Google". Ars Technica. http://arstechnica.com/open-source/news/2009/11/go-new-open-source-programming-language-from-google.ars. Retrieved 13 November 2009. 
  44. +
  45. ^ "TIOBE Programming Community Index for March 2012". TIOBE Software. March 2012. http://es.scribd.com/doc/89569304/TIOBE-Programming-Community-Index-for-March-2012. Retrieved 28 April 2012. 
  46. +
  47. ^ Bruce Eckel (27). "Calling Go from Python via JSON-RPC". http://www.artima.com/weblogs/viewpost.jsp?thread=333589. Retrieved 29 August 2011. 
  48. +
  49. ^ Claburn, Thomas (11 November 2009). "Google 'Go' Name Brings Accusations Of Evil'". InformationWeek. http://www.informationweek.com/news/software/web_services/showArticle.jhtml?articleID=221601351. Retrieved 18 January 2010. 
  50. +
  51. ^ "Issue 9 - go - I have already used the name for *MY* programming language". Google Code. Google Inc.. http://code.google.com/p/go/issues/detail?id=9. Retrieved 12 October 2010. 
  52. +
+
+

[edit] Further reading

+ +

[edit] External links

+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ +
+ + +
+ + +
+
Personal tools
+ +
+ + +
+ + +
+
Namespaces
+ +
+ + + + +
+

+

+
Variants
+ +
+ + +
+
+ + +
+
Views
+ +
+ + + + +
+
Actions
+ +
+ + + + + + + +
+
+ + +
+ + + + + +
+
Navigation
+ +
+ + + + + + + + +
+
Interaction
+ +
+ + + + +
+
Toolbox
+ +
+ + + + +
+
Print/export
+ +
+ + + + +
+
Languages
+ +
+ + +
+ + + + + + + + + + + + + + diff --git a/vendor/github.com/PuerkitoBio/goquery/testdata/metalreview.html b/vendor/github.com/PuerkitoBio/goquery/testdata/metalreview.html new file mode 100644 index 0000000..14e093b --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/testdata/metalreview.html @@ -0,0 +1,413 @@ + + + + + + + + + + + + + + Metal Reviews, News, Blogs, Interviews and Community | Metal Review + + + + + + + + + + +
+
+ + + +
+ + + + +
+
+ + + + +
+
+
+ +
+
+
+
+ + + + + +
+

Reviews

+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    + +
  • +

    + Serpentine Path - Serpentine Path + Serpentine Path
    + Serpentine Path
    + +

    +
  • + +
  • +

    + Hunter + Hunter's Ground
    + No God But the Wild
    + +

    +
  • + +
  • +

    + Blut Aus Nord - 777 - Cosmosophy + Blut Aus Nord
    + 777 - Cosmosophy
    + Black +

    +
  • + +
  • +

    + Ufomammut - Oro: Opus Alter + Ufomammut
    + Oro: Opus Alter
    + Doom +

    +
  • + +
  • +

    + Resurgency - False Enlightenment + Resurgency
    + False Enlightenment
    + Death +

    +
  • + +
  • +

    + Morgoth - Cursed to Live + Morgoth
    + Cursed to Live
    + DeathLive +

    +
  • + +
  • +

    + Krallice - Years Past Matter + Krallice
    + Years Past Matter
    + Black +

    +
  • + +
  • +

    + Murder Construct - Results + Murder Construct
    + Results
    + Grindcore +

    +
  • + +
  • +

    + Grave - Endless Procession of Souls + Grave
    + Endless Procession of Souls
    + Death +

    +
  • + +
  • +

    + Master - The New Elite + Master
    + The New Elite
    + Death +

    +
  • + +
+
+
+
+
+
+
+ Serpentine Path - Serpentine PathHunter's Ground - No God But the WildBlut Aus Nord - 777 - CosmosophyUfomammut - Oro: Opus AlterResurgency - False EnlightenmentMorgoth - Cursed to LiveKrallice - Years Past MatterMurder Construct - ResultsGrave - Endless Procession of SoulsMaster - The New Elite +
+
+
+
+ + + + + + + +
+
+
+
+
+ + + + +
Goto Next Group
+
Goto Previous Group
+ + + + + +
+ +
+ + + + + + + +
+

Lashes

+
NEW Katatonia - Dead End Kings
45 minutes ago by Chaosjunkie
+
Katatonia - Dead End Kings
1 hour ago by Harry Dick Rotten
+
Resurgency - False Enlightenment
3 hours ago by Anonymous
+
Witchcraft - The Alchemist
5 hours ago by Luke_22
+
Katatonia - Dead End Kings
9 hours ago by chaosjunkie
+
Katatonia - Dead End Kings
10 hours ago by Compeller
+
Manetheren - Time
10 hours ago by xpmule
+
Ufomammut - Oro: Opus Alter
16 hours ago by Anonymous
+
Ufomammut - Oro: Opus Alter
17 hours ago by Harry Dick Rotten
+
Katatonia - Dead End Kings
yesterday by Chaosjunkie
+
Katatonia - Dead End Kings
yesterday by Anonymous
+
Katatonia - Dead End Kings
yesterday by Anonymous
+
Katatonia - Dead End Kings
yesterday by Anonymous
+
Katatonia - Dead End Kings
yesterday by frantic
+
Blut Aus Nord - 777 - Cosmosophy
yesterday by Dimensional Bleedthrough
+ +
+ +
+
+
+ + + +
+
+ + + + + + + + + + + diff --git a/vendor/github.com/PuerkitoBio/goquery/testdata/page.html b/vendor/github.com/PuerkitoBio/goquery/testdata/page.html new file mode 100644 index 0000000..92ec74e --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/testdata/page.html @@ -0,0 +1,102 @@ + + + + + + + Provok.in + + + + + + + + + +
+
+
+   +
+
+
+
+
+
+

+ Provok.in +

+

+ Prove your point. +

+
+
+
+
+ Beta Version. Things may change. Or disappear. Or fail miserably. If it's the latter, please file an issue. +
+
+ +
+ Welcome, {{getUserName()}} ( logout ) +
+
+
+
+
+   +
+
+
+
+   +
+
+
+
+
+
+ × +

+ {{ title }} +

+

+ {{ message }} +

+
+
+
+
+
+
+
+
+
+
+   +
+
+
+
+   +
+
+ +
+
+   +
+
+
+ + \ No newline at end of file diff --git a/vendor/github.com/PuerkitoBio/goquery/testdata/page2.html b/vendor/github.com/PuerkitoBio/goquery/testdata/page2.html new file mode 100644 index 0000000..4c2f92f --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/testdata/page2.html @@ -0,0 +1,24 @@ + + + + Tests for siblings + + +
+
+
+
+
+
+
+
+ + + diff --git a/vendor/github.com/PuerkitoBio/goquery/testdata/page3.html b/vendor/github.com/PuerkitoBio/goquery/testdata/page3.html new file mode 100644 index 0000000..17e8624 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/testdata/page3.html @@ -0,0 +1,24 @@ + + + + Tests for siblings + + +
+
hello
+
+
+
+
+
+
+ + + diff --git a/vendor/github.com/PuerkitoBio/goquery/traversal.go b/vendor/github.com/PuerkitoBio/goquery/traversal.go new file mode 100644 index 0000000..5fa5315 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/traversal.go @@ -0,0 +1,698 @@ +package goquery + +import "golang.org/x/net/html" + +type siblingType int + +// Sibling type, used internally when iterating over children at the same +// level (siblings) to specify which nodes are requested. +const ( + siblingPrevUntil siblingType = iota - 3 + siblingPrevAll + siblingPrev + siblingAll + siblingNext + siblingNextAll + siblingNextUntil + siblingAllIncludingNonElements +) + +// Find gets the descendants of each element in the current set of matched +// elements, filtered by a selector. It returns a new Selection object +// containing these matched elements. +func (s *Selection) Find(selector string) *Selection { + return pushStack(s, findWithMatcher(s.Nodes, compileMatcher(selector))) +} + +// FindMatcher gets the descendants of each element in the current set of matched +// elements, filtered by the matcher. It returns a new Selection object +// containing these matched elements. +func (s *Selection) FindMatcher(m Matcher) *Selection { + return pushStack(s, findWithMatcher(s.Nodes, m)) +} + +// FindSelection gets the descendants of each element in the current +// Selection, filtered by a Selection. It returns a new Selection object +// containing these matched elements. +func (s *Selection) FindSelection(sel *Selection) *Selection { + if sel == nil { + return pushStack(s, nil) + } + return s.FindNodes(sel.Nodes...) +} + +// FindNodes gets the descendants of each element in the current +// Selection, filtered by some nodes. It returns a new Selection object +// containing these matched elements. +func (s *Selection) FindNodes(nodes ...*html.Node) *Selection { + return pushStack(s, mapNodes(nodes, func(i int, n *html.Node) []*html.Node { + if sliceContains(s.Nodes, n) { + return []*html.Node{n} + } + return nil + })) +} + +// Contents gets the children of each element in the Selection, +// including text and comment nodes. It returns a new Selection object +// containing these elements. +func (s *Selection) Contents() *Selection { + return pushStack(s, getChildrenNodes(s.Nodes, siblingAllIncludingNonElements)) +} + +// ContentsFiltered gets the children of each element in the Selection, +// filtered by the specified selector. It returns a new Selection +// object containing these elements. Since selectors only act on Element nodes, +// this function is an alias to ChildrenFiltered unless the selector is empty, +// in which case it is an alias to Contents. +func (s *Selection) ContentsFiltered(selector string) *Selection { + if selector != "" { + return s.ChildrenFiltered(selector) + } + return s.Contents() +} + +// ContentsMatcher gets the children of each element in the Selection, +// filtered by the specified matcher. It returns a new Selection +// object containing these elements. Since matchers only act on Element nodes, +// this function is an alias to ChildrenMatcher. +func (s *Selection) ContentsMatcher(m Matcher) *Selection { + return s.ChildrenMatcher(m) +} + +// Children gets the child elements of each element in the Selection. +// It returns a new Selection object containing these elements. +func (s *Selection) Children() *Selection { + return pushStack(s, getChildrenNodes(s.Nodes, siblingAll)) +} + +// ChildrenFiltered gets the child elements of each element in the Selection, +// filtered by the specified selector. It returns a new +// Selection object containing these elements. +func (s *Selection) ChildrenFiltered(selector string) *Selection { + return filterAndPush(s, getChildrenNodes(s.Nodes, siblingAll), compileMatcher(selector)) +} + +// ChildrenMatcher gets the child elements of each element in the Selection, +// filtered by the specified matcher. It returns a new +// Selection object containing these elements. +func (s *Selection) ChildrenMatcher(m Matcher) *Selection { + return filterAndPush(s, getChildrenNodes(s.Nodes, siblingAll), m) +} + +// Parent gets the parent of each element in the Selection. It returns a +// new Selection object containing the matched elements. +func (s *Selection) Parent() *Selection { + return pushStack(s, getParentNodes(s.Nodes)) +} + +// ParentFiltered gets the parent of each element in the Selection filtered by a +// selector. It returns a new Selection object containing the matched elements. +func (s *Selection) ParentFiltered(selector string) *Selection { + return filterAndPush(s, getParentNodes(s.Nodes), compileMatcher(selector)) +} + +// ParentMatcher gets the parent of each element in the Selection filtered by a +// matcher. It returns a new Selection object containing the matched elements. +func (s *Selection) ParentMatcher(m Matcher) *Selection { + return filterAndPush(s, getParentNodes(s.Nodes), m) +} + +// Closest gets the first element that matches the selector by testing the +// element itself and traversing up through its ancestors in the DOM tree. +func (s *Selection) Closest(selector string) *Selection { + cs := compileMatcher(selector) + return s.ClosestMatcher(cs) +} + +// ClosestMatcher gets the first element that matches the matcher by testing the +// element itself and traversing up through its ancestors in the DOM tree. +func (s *Selection) ClosestMatcher(m Matcher) *Selection { + return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node { + // For each node in the selection, test the node itself, then each parent + // until a match is found. + for ; n != nil; n = n.Parent { + if m.Match(n) { + return []*html.Node{n} + } + } + return nil + })) +} + +// ClosestNodes gets the first element that matches one of the nodes by testing the +// element itself and traversing up through its ancestors in the DOM tree. +func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection { + set := make(map[*html.Node]bool) + for _, n := range nodes { + set[n] = true + } + return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node { + // For each node in the selection, test the node itself, then each parent + // until a match is found. + for ; n != nil; n = n.Parent { + if set[n] { + return []*html.Node{n} + } + } + return nil + })) +} + +// ClosestSelection gets the first element that matches one of the nodes in the +// Selection by testing the element itself and traversing up through its ancestors +// in the DOM tree. +func (s *Selection) ClosestSelection(sel *Selection) *Selection { + if sel == nil { + return pushStack(s, nil) + } + return s.ClosestNodes(sel.Nodes...) +} + +// Parents gets the ancestors of each element in the current Selection. It +// returns a new Selection object with the matched elements. +func (s *Selection) Parents() *Selection { + return pushStack(s, getParentsNodes(s.Nodes, nil, nil)) +} + +// ParentsFiltered gets the ancestors of each element in the current +// Selection. It returns a new Selection object with the matched elements. +func (s *Selection) ParentsFiltered(selector string) *Selection { + return filterAndPush(s, getParentsNodes(s.Nodes, nil, nil), compileMatcher(selector)) +} + +// ParentsMatcher gets the ancestors of each element in the current +// Selection. It returns a new Selection object with the matched elements. +func (s *Selection) ParentsMatcher(m Matcher) *Selection { + return filterAndPush(s, getParentsNodes(s.Nodes, nil, nil), m) +} + +// ParentsUntil gets the ancestors of each element in the Selection, up to but +// not including the element matched by the selector. It returns a new Selection +// object containing the matched elements. +func (s *Selection) ParentsUntil(selector string) *Selection { + return pushStack(s, getParentsNodes(s.Nodes, compileMatcher(selector), nil)) +} + +// ParentsUntilMatcher gets the ancestors of each element in the Selection, up to but +// not including the element matched by the matcher. It returns a new Selection +// object containing the matched elements. +func (s *Selection) ParentsUntilMatcher(m Matcher) *Selection { + return pushStack(s, getParentsNodes(s.Nodes, m, nil)) +} + +// ParentsUntilSelection gets the ancestors of each element in the Selection, +// up to but not including the elements in the specified Selection. It returns a +// new Selection object containing the matched elements. +func (s *Selection) ParentsUntilSelection(sel *Selection) *Selection { + if sel == nil { + return s.Parents() + } + return s.ParentsUntilNodes(sel.Nodes...) +} + +// ParentsUntilNodes gets the ancestors of each element in the Selection, +// up to but not including the specified nodes. It returns a +// new Selection object containing the matched elements. +func (s *Selection) ParentsUntilNodes(nodes ...*html.Node) *Selection { + return pushStack(s, getParentsNodes(s.Nodes, nil, nodes)) +} + +// ParentsFilteredUntil is like ParentsUntil, with the option to filter the +// results based on a selector string. It returns a new Selection +// object containing the matched elements. +func (s *Selection) ParentsFilteredUntil(filterSelector, untilSelector string) *Selection { + return filterAndPush(s, getParentsNodes(s.Nodes, compileMatcher(untilSelector), nil), compileMatcher(filterSelector)) +} + +// ParentsFilteredUntilMatcher is like ParentsUntilMatcher, with the option to filter the +// results based on a matcher. It returns a new Selection object containing the matched elements. +func (s *Selection) ParentsFilteredUntilMatcher(filter, until Matcher) *Selection { + return filterAndPush(s, getParentsNodes(s.Nodes, until, nil), filter) +} + +// ParentsFilteredUntilSelection is like ParentsUntilSelection, with the +// option to filter the results based on a selector string. It returns a new +// Selection object containing the matched elements. +func (s *Selection) ParentsFilteredUntilSelection(filterSelector string, sel *Selection) *Selection { + return s.ParentsMatcherUntilSelection(compileMatcher(filterSelector), sel) +} + +// ParentsMatcherUntilSelection is like ParentsUntilSelection, with the +// option to filter the results based on a matcher. It returns a new +// Selection object containing the matched elements. +func (s *Selection) ParentsMatcherUntilSelection(filter Matcher, sel *Selection) *Selection { + if sel == nil { + return s.ParentsMatcher(filter) + } + return s.ParentsMatcherUntilNodes(filter, sel.Nodes...) +} + +// ParentsFilteredUntilNodes is like ParentsUntilNodes, with the +// option to filter the results based on a selector string. It returns a new +// Selection object containing the matched elements. +func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection { + return filterAndPush(s, getParentsNodes(s.Nodes, nil, nodes), compileMatcher(filterSelector)) +} + +// ParentsMatcherUntilNodes is like ParentsUntilNodes, with the +// option to filter the results based on a matcher. It returns a new +// Selection object containing the matched elements. +func (s *Selection) ParentsMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection { + return filterAndPush(s, getParentsNodes(s.Nodes, nil, nodes), filter) +} + +// Siblings gets the siblings of each element in the Selection. It returns +// a new Selection object containing the matched elements. +func (s *Selection) Siblings() *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingAll, nil, nil)) +} + +// SiblingsFiltered gets the siblings of each element in the Selection +// filtered by a selector. It returns a new Selection object containing the +// matched elements. +func (s *Selection) SiblingsFiltered(selector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingAll, nil, nil), compileMatcher(selector)) +} + +// SiblingsMatcher gets the siblings of each element in the Selection +// filtered by a matcher. It returns a new Selection object containing the +// matched elements. +func (s *Selection) SiblingsMatcher(m Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingAll, nil, nil), m) +} + +// Next gets the immediately following sibling of each element in the +// Selection. It returns a new Selection object containing the matched elements. +func (s *Selection) Next() *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingNext, nil, nil)) +} + +// NextFiltered gets the immediately following sibling of each element in the +// Selection filtered by a selector. It returns a new Selection object +// containing the matched elements. +func (s *Selection) NextFiltered(selector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNext, nil, nil), compileMatcher(selector)) +} + +// NextMatcher gets the immediately following sibling of each element in the +// Selection filtered by a matcher. It returns a new Selection object +// containing the matched elements. +func (s *Selection) NextMatcher(m Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNext, nil, nil), m) +} + +// NextAll gets all the following siblings of each element in the +// Selection. It returns a new Selection object containing the matched elements. +func (s *Selection) NextAll() *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil)) +} + +// NextAllFiltered gets all the following siblings of each element in the +// Selection filtered by a selector. It returns a new Selection object +// containing the matched elements. +func (s *Selection) NextAllFiltered(selector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil), compileMatcher(selector)) +} + +// NextAllMatcher gets all the following siblings of each element in the +// Selection filtered by a matcher. It returns a new Selection object +// containing the matched elements. +func (s *Selection) NextAllMatcher(m Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil), m) +} + +// Prev gets the immediately preceding sibling of each element in the +// Selection. It returns a new Selection object containing the matched elements. +func (s *Selection) Prev() *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingPrev, nil, nil)) +} + +// PrevFiltered gets the immediately preceding sibling of each element in the +// Selection filtered by a selector. It returns a new Selection object +// containing the matched elements. +func (s *Selection) PrevFiltered(selector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrev, nil, nil), compileMatcher(selector)) +} + +// PrevMatcher gets the immediately preceding sibling of each element in the +// Selection filtered by a matcher. It returns a new Selection object +// containing the matched elements. +func (s *Selection) PrevMatcher(m Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrev, nil, nil), m) +} + +// PrevAll gets all the preceding siblings of each element in the +// Selection. It returns a new Selection object containing the matched elements. +func (s *Selection) PrevAll() *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil)) +} + +// PrevAllFiltered gets all the preceding siblings of each element in the +// Selection filtered by a selector. It returns a new Selection object +// containing the matched elements. +func (s *Selection) PrevAllFiltered(selector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil), compileMatcher(selector)) +} + +// PrevAllMatcher gets all the preceding siblings of each element in the +// Selection filtered by a matcher. It returns a new Selection object +// containing the matched elements. +func (s *Selection) PrevAllMatcher(m Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil), m) +} + +// NextUntil gets all following siblings of each element up to but not +// including the element matched by the selector. It returns a new Selection +// object containing the matched elements. +func (s *Selection) NextUntil(selector string) *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil, + compileMatcher(selector), nil)) +} + +// NextUntilMatcher gets all following siblings of each element up to but not +// including the element matched by the matcher. It returns a new Selection +// object containing the matched elements. +func (s *Selection) NextUntilMatcher(m Matcher) *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil, + m, nil)) +} + +// NextUntilSelection gets all following siblings of each element up to but not +// including the element matched by the Selection. It returns a new Selection +// object containing the matched elements. +func (s *Selection) NextUntilSelection(sel *Selection) *Selection { + if sel == nil { + return s.NextAll() + } + return s.NextUntilNodes(sel.Nodes...) +} + +// NextUntilNodes gets all following siblings of each element up to but not +// including the element matched by the nodes. It returns a new Selection +// object containing the matched elements. +func (s *Selection) NextUntilNodes(nodes ...*html.Node) *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil, + nil, nodes)) +} + +// PrevUntil gets all preceding siblings of each element up to but not +// including the element matched by the selector. It returns a new Selection +// object containing the matched elements. +func (s *Selection) PrevUntil(selector string) *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + compileMatcher(selector), nil)) +} + +// PrevUntilMatcher gets all preceding siblings of each element up to but not +// including the element matched by the matcher. It returns a new Selection +// object containing the matched elements. +func (s *Selection) PrevUntilMatcher(m Matcher) *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + m, nil)) +} + +// PrevUntilSelection gets all preceding siblings of each element up to but not +// including the element matched by the Selection. It returns a new Selection +// object containing the matched elements. +func (s *Selection) PrevUntilSelection(sel *Selection) *Selection { + if sel == nil { + return s.PrevAll() + } + return s.PrevUntilNodes(sel.Nodes...) +} + +// PrevUntilNodes gets all preceding siblings of each element up to but not +// including the element matched by the nodes. It returns a new Selection +// object containing the matched elements. +func (s *Selection) PrevUntilNodes(nodes ...*html.Node) *Selection { + return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + nil, nodes)) +} + +// NextFilteredUntil is like NextUntil, with the option to filter +// the results based on a selector string. +// It returns a new Selection object containing the matched elements. +func (s *Selection) NextFilteredUntil(filterSelector, untilSelector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil, + compileMatcher(untilSelector), nil), compileMatcher(filterSelector)) +} + +// NextFilteredUntilMatcher is like NextUntilMatcher, with the option to filter +// the results based on a matcher. +// It returns a new Selection object containing the matched elements. +func (s *Selection) NextFilteredUntilMatcher(filter, until Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil, + until, nil), filter) +} + +// NextFilteredUntilSelection is like NextUntilSelection, with the +// option to filter the results based on a selector string. It returns a new +// Selection object containing the matched elements. +func (s *Selection) NextFilteredUntilSelection(filterSelector string, sel *Selection) *Selection { + return s.NextMatcherUntilSelection(compileMatcher(filterSelector), sel) +} + +// NextMatcherUntilSelection is like NextUntilSelection, with the +// option to filter the results based on a matcher. It returns a new +// Selection object containing the matched elements. +func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection { + if sel == nil { + return s.NextMatcher(filter) + } + return s.NextMatcherUntilNodes(filter, sel.Nodes...) +} + +// NextFilteredUntilNodes is like NextUntilNodes, with the +// option to filter the results based on a selector string. It returns a new +// Selection object containing the matched elements. +func (s *Selection) NextFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil, + nil, nodes), compileMatcher(filterSelector)) +} + +// NextMatcherUntilNodes is like NextUntilNodes, with the +// option to filter the results based on a matcher. It returns a new +// Selection object containing the matched elements. +func (s *Selection) NextMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil, + nil, nodes), filter) +} + +// PrevFilteredUntil is like PrevUntil, with the option to filter +// the results based on a selector string. +// It returns a new Selection object containing the matched elements. +func (s *Selection) PrevFilteredUntil(filterSelector, untilSelector string) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + compileMatcher(untilSelector), nil), compileMatcher(filterSelector)) +} + +// PrevFilteredUntilMatcher is like PrevUntilMatcher, with the option to filter +// the results based on a matcher. +// It returns a new Selection object containing the matched elements. +func (s *Selection) PrevFilteredUntilMatcher(filter, until Matcher) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + until, nil), filter) +} + +// PrevFilteredUntilSelection is like PrevUntilSelection, with the +// option to filter the results based on a selector string. It returns a new +// Selection object containing the matched elements. +func (s *Selection) PrevFilteredUntilSelection(filterSelector string, sel *Selection) *Selection { + return s.PrevMatcherUntilSelection(compileMatcher(filterSelector), sel) +} + +// PrevMatcherUntilSelection is like PrevUntilSelection, with the +// option to filter the results based on a matcher. It returns a new +// Selection object containing the matched elements. +func (s *Selection) PrevMatcherUntilSelection(filter Matcher, sel *Selection) *Selection { + if sel == nil { + return s.PrevMatcher(filter) + } + return s.PrevMatcherUntilNodes(filter, sel.Nodes...) +} + +// PrevFilteredUntilNodes is like PrevUntilNodes, with the +// option to filter the results based on a selector string. It returns a new +// Selection object containing the matched elements. +func (s *Selection) PrevFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + nil, nodes), compileMatcher(filterSelector)) +} + +// PrevMatcherUntilNodes is like PrevUntilNodes, with the +// option to filter the results based on a matcher. It returns a new +// Selection object containing the matched elements. +func (s *Selection) PrevMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection { + return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil, + nil, nodes), filter) +} + +// Filter and push filters the nodes based on a matcher, and pushes the results +// on the stack, with the srcSel as previous selection. +func filterAndPush(srcSel *Selection, nodes []*html.Node, m Matcher) *Selection { + // Create a temporary Selection with the specified nodes to filter using winnow + sel := &Selection{nodes, srcSel.document, nil} + // Filter based on matcher and push on stack + return pushStack(srcSel, winnow(sel, m, true)) +} + +// Internal implementation of Find that return raw nodes. +func findWithMatcher(nodes []*html.Node, m Matcher) []*html.Node { + // Map nodes to find the matches within the children of each node + return mapNodes(nodes, func(i int, n *html.Node) (result []*html.Node) { + // Go down one level, becausejQuery's Find selects only within descendants + for c := n.FirstChild; c != nil; c = c.NextSibling { + if c.Type == html.ElementNode { + result = append(result, m.MatchAll(c)...) + } + } + return + }) +} + +// Internal implementation to get all parent nodes, stopping at the specified +// node (or nil if no stop). +func getParentsNodes(nodes []*html.Node, stopm Matcher, stopNodes []*html.Node) []*html.Node { + return mapNodes(nodes, func(i int, n *html.Node) (result []*html.Node) { + for p := n.Parent; p != nil; p = p.Parent { + sel := newSingleSelection(p, nil) + if stopm != nil { + if sel.IsMatcher(stopm) { + break + } + } else if len(stopNodes) > 0 { + if sel.IsNodes(stopNodes...) { + break + } + } + if p.Type == html.ElementNode { + result = append(result, p) + } + } + return + }) +} + +// Internal implementation of sibling nodes that return a raw slice of matches. +func getSiblingNodes(nodes []*html.Node, st siblingType, untilm Matcher, untilNodes []*html.Node) []*html.Node { + var f func(*html.Node) bool + + // If the requested siblings are ...Until, create the test function to + // determine if the until condition is reached (returns true if it is) + if st == siblingNextUntil || st == siblingPrevUntil { + f = func(n *html.Node) bool { + if untilm != nil { + // Matcher-based condition + sel := newSingleSelection(n, nil) + return sel.IsMatcher(untilm) + } else if len(untilNodes) > 0 { + // Nodes-based condition + sel := newSingleSelection(n, nil) + return sel.IsNodes(untilNodes...) + } + return false + } + } + + return mapNodes(nodes, func(i int, n *html.Node) []*html.Node { + return getChildrenWithSiblingType(n.Parent, st, n, f) + }) +} + +// Gets the children nodes of each node in the specified slice of nodes, +// based on the sibling type request. +func getChildrenNodes(nodes []*html.Node, st siblingType) []*html.Node { + return mapNodes(nodes, func(i int, n *html.Node) []*html.Node { + return getChildrenWithSiblingType(n, st, nil, nil) + }) +} + +// Gets the children of the specified parent, based on the requested sibling +// type, skipping a specified node if required. +func getChildrenWithSiblingType(parent *html.Node, st siblingType, skipNode *html.Node, + untilFunc func(*html.Node) bool) (result []*html.Node) { + + // Create the iterator function + var iter = func(cur *html.Node) (ret *html.Node) { + // Based on the sibling type requested, iterate the right way + for { + switch st { + case siblingAll, siblingAllIncludingNonElements: + if cur == nil { + // First iteration, start with first child of parent + // Skip node if required + if ret = parent.FirstChild; ret == skipNode && skipNode != nil { + ret = skipNode.NextSibling + } + } else { + // Skip node if required + if ret = cur.NextSibling; ret == skipNode && skipNode != nil { + ret = skipNode.NextSibling + } + } + case siblingPrev, siblingPrevAll, siblingPrevUntil: + if cur == nil { + // Start with previous sibling of the skip node + ret = skipNode.PrevSibling + } else { + ret = cur.PrevSibling + } + case siblingNext, siblingNextAll, siblingNextUntil: + if cur == nil { + // Start with next sibling of the skip node + ret = skipNode.NextSibling + } else { + ret = cur.NextSibling + } + default: + panic("Invalid sibling type.") + } + if ret == nil || ret.Type == html.ElementNode || st == siblingAllIncludingNonElements { + return + } + // Not a valid node, try again from this one + cur = ret + } + } + + for c := iter(nil); c != nil; c = iter(c) { + // If this is an ...Until case, test before append (returns true + // if the until condition is reached) + if st == siblingNextUntil || st == siblingPrevUntil { + if untilFunc(c) { + return + } + } + result = append(result, c) + if st == siblingNext || st == siblingPrev { + // Only one node was requested (immediate next or previous), so exit + return + } + } + return +} + +// Internal implementation of parent nodes that return a raw slice of Nodes. +func getParentNodes(nodes []*html.Node) []*html.Node { + return mapNodes(nodes, func(i int, n *html.Node) []*html.Node { + if n.Parent != nil && n.Parent.Type == html.ElementNode { + return []*html.Node{n.Parent} + } + return nil + }) +} + +// Internal map function used by many traversing methods. Takes the source nodes +// to iterate on and the mapping function that returns an array of nodes. +// Returns an array of nodes mapped by calling the callback function once for +// each node in the source nodes. +func mapNodes(nodes []*html.Node, f func(int, *html.Node) []*html.Node) (result []*html.Node) { + set := make(map[*html.Node]bool) + for i, n := range nodes { + if vals := f(i, n); len(vals) > 0 { + result = appendWithoutDuplicates(result, vals, set) + } + } + return result +} diff --git a/vendor/github.com/PuerkitoBio/goquery/traversal_test.go b/vendor/github.com/PuerkitoBio/goquery/traversal_test.go new file mode 100644 index 0000000..04383a4 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/traversal_test.go @@ -0,0 +1,793 @@ +package goquery + +import ( + "strings" + "testing" +) + +func TestFind(t *testing.T) { + sel := Doc().Find("div.row-fluid") + assertLength(t, sel.Nodes, 9) +} + +func TestFindRollback(t *testing.T) { + sel := Doc().Find("div.row-fluid") + sel2 := sel.Find("a").End() + assertEqual(t, sel, sel2) +} + +func TestFindNotSelf(t *testing.T) { + sel := Doc().Find("h1").Find("h1") + assertLength(t, sel.Nodes, 0) +} + +func TestFindInvalid(t *testing.T) { + sel := Doc().Find(":+ ^") + assertLength(t, sel.Nodes, 0) +} + +func TestFindBig(t *testing.T) { + doc := DocW() + sel := doc.Find("li") + assertLength(t, sel.Nodes, 373) + sel2 := doc.Find("span") + assertLength(t, sel2.Nodes, 448) + sel3 := sel.FindSelection(sel2) + assertLength(t, sel3.Nodes, 248) +} + +func TestChainedFind(t *testing.T) { + sel := Doc().Find("div.hero-unit").Find(".row-fluid") + assertLength(t, sel.Nodes, 4) +} + +func TestChainedFindInvalid(t *testing.T) { + sel := Doc().Find("div.hero-unit").Find("") + assertLength(t, sel.Nodes, 0) +} + +func TestChildren(t *testing.T) { + sel := Doc().Find(".pvk-content").Children() + assertLength(t, sel.Nodes, 5) +} + +func TestChildrenRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Children().End() + assertEqual(t, sel, sel2) +} + +func TestContents(t *testing.T) { + sel := Doc().Find(".pvk-content").Contents() + assertLength(t, sel.Nodes, 13) +} + +func TestContentsRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.Contents().End() + assertEqual(t, sel, sel2) +} + +func TestChildrenFiltered(t *testing.T) { + sel := Doc().Find(".pvk-content").ChildrenFiltered(".hero-unit") + assertLength(t, sel.Nodes, 1) +} + +func TestChildrenFilteredInvalid(t *testing.T) { + sel := Doc().Find(".pvk-content").ChildrenFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestChildrenFilteredRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.ChildrenFiltered(".hero-unit").End() + assertEqual(t, sel, sel2) +} + +func TestContentsFiltered(t *testing.T) { + sel := Doc().Find(".pvk-content").ContentsFiltered(".hero-unit") + assertLength(t, sel.Nodes, 1) +} + +func TestContentsFilteredInvalid(t *testing.T) { + sel := Doc().Find(".pvk-content").ContentsFiltered("~") + assertLength(t, sel.Nodes, 0) +} + +func TestContentsFilteredRollback(t *testing.T) { + sel := Doc().Find(".pvk-content") + sel2 := sel.ContentsFiltered(".hero-unit").End() + assertEqual(t, sel, sel2) +} + +func TestChildrenFilteredNone(t *testing.T) { + sel := Doc().Find(".pvk-content").ChildrenFiltered("a.btn") + assertLength(t, sel.Nodes, 0) +} + +func TestParent(t *testing.T) { + sel := Doc().Find(".container-fluid").Parent() + assertLength(t, sel.Nodes, 3) +} + +func TestParentRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.Parent().End() + assertEqual(t, sel, sel2) +} + +func TestParentBody(t *testing.T) { + sel := Doc().Find("body").Parent() + assertLength(t, sel.Nodes, 1) +} + +func TestParentFiltered(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentFiltered(".hero-unit") + assertLength(t, sel.Nodes, 1) + assertClass(t, sel, "hero-unit") +} + +func TestParentFilteredInvalid(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestParentFilteredRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ParentFiltered(".hero-unit").End() + assertEqual(t, sel, sel2) +} + +func TestParents(t *testing.T) { + sel := Doc().Find(".container-fluid").Parents() + assertLength(t, sel.Nodes, 8) +} + +func TestParentsOrder(t *testing.T) { + sel := Doc().Find("#cf2").Parents() + assertLength(t, sel.Nodes, 6) + assertSelectionIs(t, sel, ".hero-unit", ".pvk-content", "div.row-fluid", "#cf1", "body", "html") +} + +func TestParentsRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.Parents().End() + assertEqual(t, sel, sel2) +} + +func TestParentsFiltered(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentsFiltered("body") + assertLength(t, sel.Nodes, 1) +} + +func TestParentsFilteredInvalid(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentsFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestParentsFilteredRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ParentsFiltered("body").End() + assertEqual(t, sel, sel2) +} + +func TestParentsUntil(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentsUntil("body") + assertLength(t, sel.Nodes, 6) +} + +func TestParentsUntilInvalid(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentsUntil("") + assertLength(t, sel.Nodes, 8) +} + +func TestParentsUntilRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ParentsUntil("body").End() + assertEqual(t, sel, sel2) +} + +func TestParentsUntilSelection(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".pvk-content") + sel = sel.ParentsUntilSelection(sel2) + assertLength(t, sel.Nodes, 3) +} + +func TestParentsUntilSelectionRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".pvk-content") + sel2 = sel.ParentsUntilSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestParentsUntilNodes(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".pvk-content, .hero-unit") + sel = sel.ParentsUntilNodes(sel2.Nodes...) + assertLength(t, sel.Nodes, 2) +} + +func TestParentsUntilNodesRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".pvk-content, .hero-unit") + sel2 = sel.ParentsUntilNodes(sel2.Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestParentsFilteredUntil(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentsFilteredUntil(".pvk-content", "body") + assertLength(t, sel.Nodes, 2) +} + +func TestParentsFilteredUntilInvalid(t *testing.T) { + sel := Doc().Find(".container-fluid").ParentsFilteredUntil("", "") + assertLength(t, sel.Nodes, 0) +} + +func TestParentsFilteredUntilRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ParentsFilteredUntil(".pvk-content", "body").End() + assertEqual(t, sel, sel2) +} + +func TestParentsFilteredUntilSelection(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".row-fluid") + sel = sel.ParentsFilteredUntilSelection("div", sel2) + assertLength(t, sel.Nodes, 3) +} + +func TestParentsFilteredUntilSelectionRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".row-fluid") + sel2 = sel.ParentsFilteredUntilSelection("div", sel2).End() + assertEqual(t, sel, sel2) +} + +func TestParentsFilteredUntilNodes(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".row-fluid") + sel = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...) + assertLength(t, sel.Nodes, 1) +} + +func TestParentsFilteredUntilNodesRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".row-fluid") + sel2 = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestSiblings(t *testing.T) { + sel := Doc().Find("h1").Siblings() + assertLength(t, sel.Nodes, 1) +} + +func TestSiblingsRollback(t *testing.T) { + sel := Doc().Find("h1") + sel2 := sel.Siblings().End() + assertEqual(t, sel, sel2) +} + +func TestSiblings2(t *testing.T) { + sel := Doc().Find(".pvk-gutter").Siblings() + assertLength(t, sel.Nodes, 9) +} + +func TestSiblings3(t *testing.T) { + sel := Doc().Find("body>.container-fluid").Siblings() + assertLength(t, sel.Nodes, 0) +} + +func TestSiblingsFiltered(t *testing.T) { + sel := Doc().Find(".pvk-gutter").SiblingsFiltered(".pvk-content") + assertLength(t, sel.Nodes, 3) +} + +func TestSiblingsFilteredInvalid(t *testing.T) { + sel := Doc().Find(".pvk-gutter").SiblingsFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestSiblingsFilteredRollback(t *testing.T) { + sel := Doc().Find(".pvk-gutter") + sel2 := sel.SiblingsFiltered(".pvk-content").End() + assertEqual(t, sel, sel2) +} + +func TestNext(t *testing.T) { + sel := Doc().Find("h1").Next() + assertLength(t, sel.Nodes, 1) +} + +func TestNextRollback(t *testing.T) { + sel := Doc().Find("h1") + sel2 := sel.Next().End() + assertEqual(t, sel, sel2) +} + +func TestNext2(t *testing.T) { + sel := Doc().Find(".close").Next() + assertLength(t, sel.Nodes, 1) +} + +func TestNextNone(t *testing.T) { + sel := Doc().Find("small").Next() + assertLength(t, sel.Nodes, 0) +} + +func TestNextFiltered(t *testing.T) { + sel := Doc().Find(".container-fluid").NextFiltered("div") + assertLength(t, sel.Nodes, 2) +} + +func TestNextFilteredInvalid(t *testing.T) { + sel := Doc().Find(".container-fluid").NextFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestNextFilteredRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.NextFiltered("div").End() + assertEqual(t, sel, sel2) +} + +func TestNextFiltered2(t *testing.T) { + sel := Doc().Find(".container-fluid").NextFiltered("[ng-view]") + assertLength(t, sel.Nodes, 1) +} + +func TestPrev(t *testing.T) { + sel := Doc().Find(".red").Prev() + assertLength(t, sel.Nodes, 1) + assertClass(t, sel, "green") +} + +func TestPrevRollback(t *testing.T) { + sel := Doc().Find(".red") + sel2 := sel.Prev().End() + assertEqual(t, sel, sel2) +} + +func TestPrev2(t *testing.T) { + sel := Doc().Find(".row-fluid").Prev() + assertLength(t, sel.Nodes, 5) +} + +func TestPrevNone(t *testing.T) { + sel := Doc().Find("h2").Prev() + assertLength(t, sel.Nodes, 0) +} + +func TestPrevFiltered(t *testing.T) { + sel := Doc().Find(".row-fluid").PrevFiltered(".row-fluid") + assertLength(t, sel.Nodes, 5) +} + +func TestPrevFilteredInvalid(t *testing.T) { + sel := Doc().Find(".row-fluid").PrevFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestPrevFilteredRollback(t *testing.T) { + sel := Doc().Find(".row-fluid") + sel2 := sel.PrevFiltered(".row-fluid").End() + assertEqual(t, sel, sel2) +} + +func TestNextAll(t *testing.T) { + sel := Doc().Find("#cf2 div:nth-child(1)").NextAll() + assertLength(t, sel.Nodes, 3) +} + +func TestNextAllRollback(t *testing.T) { + sel := Doc().Find("#cf2 div:nth-child(1)") + sel2 := sel.NextAll().End() + assertEqual(t, sel, sel2) +} + +func TestNextAll2(t *testing.T) { + sel := Doc().Find("div[ng-cloak]").NextAll() + assertLength(t, sel.Nodes, 1) +} + +func TestNextAllNone(t *testing.T) { + sel := Doc().Find(".footer").NextAll() + assertLength(t, sel.Nodes, 0) +} + +func TestNextAllFiltered(t *testing.T) { + sel := Doc().Find("#cf2 .row-fluid").NextAllFiltered("[ng-cloak]") + assertLength(t, sel.Nodes, 2) +} + +func TestNextAllFilteredInvalid(t *testing.T) { + sel := Doc().Find("#cf2 .row-fluid").NextAllFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestNextAllFilteredRollback(t *testing.T) { + sel := Doc().Find("#cf2 .row-fluid") + sel2 := sel.NextAllFiltered("[ng-cloak]").End() + assertEqual(t, sel, sel2) +} + +func TestNextAllFiltered2(t *testing.T) { + sel := Doc().Find(".close").NextAllFiltered("h4") + assertLength(t, sel.Nodes, 1) +} + +func TestPrevAll(t *testing.T) { + sel := Doc().Find("[ng-view]").PrevAll() + assertLength(t, sel.Nodes, 2) +} + +func TestPrevAllOrder(t *testing.T) { + sel := Doc().Find("[ng-view]").PrevAll() + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#cf4", "#cf3") +} + +func TestPrevAllRollback(t *testing.T) { + sel := Doc().Find("[ng-view]") + sel2 := sel.PrevAll().End() + assertEqual(t, sel, sel2) +} + +func TestPrevAll2(t *testing.T) { + sel := Doc().Find(".pvk-gutter").PrevAll() + assertLength(t, sel.Nodes, 6) +} + +func TestPrevAllFiltered(t *testing.T) { + sel := Doc().Find(".pvk-gutter").PrevAllFiltered(".pvk-content") + assertLength(t, sel.Nodes, 3) +} + +func TestPrevAllFilteredInvalid(t *testing.T) { + sel := Doc().Find(".pvk-gutter").PrevAllFiltered("") + assertLength(t, sel.Nodes, 0) +} + +func TestPrevAllFilteredRollback(t *testing.T) { + sel := Doc().Find(".pvk-gutter") + sel2 := sel.PrevAllFiltered(".pvk-content").End() + assertEqual(t, sel, sel2) +} + +func TestNextUntil(t *testing.T) { + sel := Doc().Find(".alert a").NextUntil("p") + assertLength(t, sel.Nodes, 1) + assertSelectionIs(t, sel, "h4") +} + +func TestNextUntilInvalid(t *testing.T) { + sel := Doc().Find(".alert a").NextUntil("") + assertLength(t, sel.Nodes, 2) +} + +func TestNextUntil2(t *testing.T) { + sel := Doc().Find("#cf2-1").NextUntil("[ng-cloak]") + assertLength(t, sel.Nodes, 1) + assertSelectionIs(t, sel, "#cf2-2") +} + +func TestNextUntilOrder(t *testing.T) { + sel := Doc().Find("#cf2-1").NextUntil("#cf2-4") + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#cf2-2", "#cf2-3") +} + +func TestNextUntilRollback(t *testing.T) { + sel := Doc().Find("#cf2-1") + sel2 := sel.PrevUntil("#cf2-4").End() + assertEqual(t, sel, sel2) +} + +func TestNextUntilSelection(t *testing.T) { + sel := Doc2().Find("#n2") + sel2 := Doc2().Find("#n4") + sel2 = sel.NextUntilSelection(sel2) + assertLength(t, sel2.Nodes, 1) + assertSelectionIs(t, sel2, "#n3") +} + +func TestNextUntilSelectionRollback(t *testing.T) { + sel := Doc2().Find("#n2") + sel2 := Doc2().Find("#n4") + sel2 = sel.NextUntilSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestNextUntilNodes(t *testing.T) { + sel := Doc2().Find("#n2") + sel2 := Doc2().Find("#n5") + sel2 = sel.NextUntilNodes(sel2.Nodes...) + assertLength(t, sel2.Nodes, 2) + assertSelectionIs(t, sel2, "#n3", "#n4") +} + +func TestNextUntilNodesRollback(t *testing.T) { + sel := Doc2().Find("#n2") + sel2 := Doc2().Find("#n5") + sel2 = sel.NextUntilNodes(sel2.Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestPrevUntil(t *testing.T) { + sel := Doc().Find(".alert p").PrevUntil("a") + assertLength(t, sel.Nodes, 1) + assertSelectionIs(t, sel, "h4") +} + +func TestPrevUntilInvalid(t *testing.T) { + sel := Doc().Find(".alert p").PrevUntil("") + assertLength(t, sel.Nodes, 2) +} + +func TestPrevUntil2(t *testing.T) { + sel := Doc().Find("[ng-cloak]").PrevUntil(":not([ng-cloak])") + assertLength(t, sel.Nodes, 1) + assertSelectionIs(t, sel, "[ng-cloak]") +} + +func TestPrevUntilOrder(t *testing.T) { + sel := Doc().Find("#cf2-4").PrevUntil("#cf2-1") + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#cf2-3", "#cf2-2") +} + +func TestPrevUntilRollback(t *testing.T) { + sel := Doc().Find("#cf2-4") + sel2 := sel.PrevUntil("#cf2-1").End() + assertEqual(t, sel, sel2) +} + +func TestPrevUntilSelection(t *testing.T) { + sel := Doc2().Find("#n4") + sel2 := Doc2().Find("#n2") + sel2 = sel.PrevUntilSelection(sel2) + assertLength(t, sel2.Nodes, 1) + assertSelectionIs(t, sel2, "#n3") +} + +func TestPrevUntilSelectionRollback(t *testing.T) { + sel := Doc2().Find("#n4") + sel2 := Doc2().Find("#n2") + sel2 = sel.PrevUntilSelection(sel2).End() + assertEqual(t, sel, sel2) +} + +func TestPrevUntilNodes(t *testing.T) { + sel := Doc2().Find("#n5") + sel2 := Doc2().Find("#n2") + sel2 = sel.PrevUntilNodes(sel2.Nodes...) + assertLength(t, sel2.Nodes, 2) + assertSelectionIs(t, sel2, "#n4", "#n3") +} + +func TestPrevUntilNodesRollback(t *testing.T) { + sel := Doc2().Find("#n5") + sel2 := Doc2().Find("#n2") + sel2 = sel.PrevUntilNodes(sel2.Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestNextFilteredUntil(t *testing.T) { + sel := Doc2().Find(".two").NextFilteredUntil(".even", ".six") + assertLength(t, sel.Nodes, 4) + assertSelectionIs(t, sel, "#n3", "#n5", "#nf3", "#nf5") +} + +func TestNextFilteredUntilInvalid(t *testing.T) { + sel := Doc2().Find(".two").NextFilteredUntil("", "") + assertLength(t, sel.Nodes, 0) +} + +func TestNextFilteredUntilRollback(t *testing.T) { + sel := Doc2().Find(".two") + sel2 := sel.NextFilteredUntil(".even", ".six").End() + assertEqual(t, sel, sel2) +} + +func TestNextFilteredUntilSelection(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".five") + sel = sel.NextFilteredUntilSelection(".even", sel2) + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#n3", "#nf3") +} + +func TestNextFilteredUntilSelectionRollback(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".five") + sel3 := sel.NextFilteredUntilSelection(".even", sel2).End() + assertEqual(t, sel, sel3) +} + +func TestNextFilteredUntilNodes(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".four") + sel = sel.NextFilteredUntilNodes(".odd", sel2.Nodes...) + assertLength(t, sel.Nodes, 4) + assertSelectionIs(t, sel, "#n2", "#n6", "#nf2", "#nf6") +} + +func TestNextFilteredUntilNodesRollback(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".four") + sel3 := sel.NextFilteredUntilNodes(".odd", sel2.Nodes...).End() + assertEqual(t, sel, sel3) +} + +func TestPrevFilteredUntil(t *testing.T) { + sel := Doc2().Find(".five").PrevFilteredUntil(".odd", ".one") + assertLength(t, sel.Nodes, 4) + assertSelectionIs(t, sel, "#n4", "#n2", "#nf4", "#nf2") +} + +func TestPrevFilteredUntilInvalid(t *testing.T) { + sel := Doc2().Find(".five").PrevFilteredUntil("", "") + assertLength(t, sel.Nodes, 0) +} + +func TestPrevFilteredUntilRollback(t *testing.T) { + sel := Doc2().Find(".four") + sel2 := sel.PrevFilteredUntil(".odd", ".one").End() + assertEqual(t, sel, sel2) +} + +func TestPrevFilteredUntilSelection(t *testing.T) { + sel := Doc2().Find(".odd") + sel2 := Doc2().Find(".two") + sel = sel.PrevFilteredUntilSelection(".odd", sel2) + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#n4", "#nf4") +} + +func TestPrevFilteredUntilSelectionRollback(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".five") + sel3 := sel.PrevFilteredUntilSelection(".even", sel2).End() + assertEqual(t, sel, sel3) +} + +func TestPrevFilteredUntilNodes(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".four") + sel = sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...) + assertLength(t, sel.Nodes, 2) + assertSelectionIs(t, sel, "#n2", "#nf2") +} + +func TestPrevFilteredUntilNodesRollback(t *testing.T) { + sel := Doc2().Find(".even") + sel2 := Doc2().Find(".four") + sel3 := sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...).End() + assertEqual(t, sel, sel3) +} + +func TestClosestItself(t *testing.T) { + sel := Doc2().Find(".three") + sel2 := sel.Closest(".row") + assertLength(t, sel2.Nodes, sel.Length()) + assertSelectionIs(t, sel2, "#n3", "#nf3") +} + +func TestClosestNoDupes(t *testing.T) { + sel := Doc().Find(".span12") + sel2 := sel.Closest(".pvk-content") + assertLength(t, sel2.Nodes, 1) + assertClass(t, sel2, "pvk-content") +} + +func TestClosestNone(t *testing.T) { + sel := Doc().Find("h4") + sel2 := sel.Closest("a") + assertLength(t, sel2.Nodes, 0) +} + +func TestClosestInvalid(t *testing.T) { + sel := Doc().Find("h4") + sel2 := sel.Closest("") + assertLength(t, sel2.Nodes, 0) +} + +func TestClosestMany(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.Closest(".pvk-content") + assertLength(t, sel2.Nodes, 2) + assertSelectionIs(t, sel2, "#pc1", "#pc2") +} + +func TestClosestRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.Closest(".pvk-content").End() + assertEqual(t, sel, sel2) +} + +func TestClosestSelectionItself(t *testing.T) { + sel := Doc2().Find(".three") + sel2 := sel.ClosestSelection(Doc2().Find(".row")) + assertLength(t, sel2.Nodes, sel.Length()) +} + +func TestClosestSelectionNoDupes(t *testing.T) { + sel := Doc().Find(".span12") + sel2 := sel.ClosestSelection(Doc().Find(".pvk-content")) + assertLength(t, sel2.Nodes, 1) + assertClass(t, sel2, "pvk-content") +} + +func TestClosestSelectionNone(t *testing.T) { + sel := Doc().Find("h4") + sel2 := sel.ClosestSelection(Doc().Find("a")) + assertLength(t, sel2.Nodes, 0) +} + +func TestClosestSelectionMany(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ClosestSelection(Doc().Find(".pvk-content")) + assertLength(t, sel2.Nodes, 2) + assertSelectionIs(t, sel2, "#pc1", "#pc2") +} + +func TestClosestSelectionRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ClosestSelection(Doc().Find(".pvk-content")).End() + assertEqual(t, sel, sel2) +} + +func TestClosestNodesItself(t *testing.T) { + sel := Doc2().Find(".three") + sel2 := sel.ClosestNodes(Doc2().Find(".row").Nodes...) + assertLength(t, sel2.Nodes, sel.Length()) +} + +func TestClosestNodesNoDupes(t *testing.T) { + sel := Doc().Find(".span12") + sel2 := sel.ClosestNodes(Doc().Find(".pvk-content").Nodes...) + assertLength(t, sel2.Nodes, 1) + assertClass(t, sel2, "pvk-content") +} + +func TestClosestNodesNone(t *testing.T) { + sel := Doc().Find("h4") + sel2 := sel.ClosestNodes(Doc().Find("a").Nodes...) + assertLength(t, sel2.Nodes, 0) +} + +func TestClosestNodesMany(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ClosestNodes(Doc().Find(".pvk-content").Nodes...) + assertLength(t, sel2.Nodes, 2) + assertSelectionIs(t, sel2, "#pc1", "#pc2") +} + +func TestClosestNodesRollback(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := sel.ClosestNodes(Doc().Find(".pvk-content").Nodes...).End() + assertEqual(t, sel, sel2) +} + +func TestIssue26(t *testing.T) { + img1 := `150x150` + img2 := `150x150` + cases := []struct { + s string + l int + }{ + {s: img1 + img2, l: 2}, + {s: img1, l: 1}, + {s: img2, l: 1}, + } + for _, c := range cases { + doc, err := NewDocumentFromReader(strings.NewReader(c.s)) + if err != nil { + t.Fatal(err) + } + sel := doc.Find("img[src]") + assertLength(t, sel.Nodes, c.l) + } +} diff --git a/vendor/github.com/PuerkitoBio/goquery/type.go b/vendor/github.com/PuerkitoBio/goquery/type.go new file mode 100644 index 0000000..6ad51db --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/type.go @@ -0,0 +1,141 @@ +package goquery + +import ( + "errors" + "io" + "net/http" + "net/url" + + "github.com/andybalholm/cascadia" + + "golang.org/x/net/html" +) + +// Document represents an HTML document to be manipulated. Unlike jQuery, which +// is loaded as part of a DOM document, and thus acts upon its containing +// document, GoQuery doesn't know which HTML document to act upon. So it needs +// to be told, and that's what the Document class is for. It holds the root +// document node to manipulate, and can make selections on this document. +type Document struct { + *Selection + Url *url.URL + rootNode *html.Node +} + +// NewDocumentFromNode is a Document constructor that takes a root html Node +// as argument. +func NewDocumentFromNode(root *html.Node) *Document { + return newDocument(root, nil) +} + +// NewDocument is a Document constructor that takes a string URL as argument. +// It loads the specified document, parses it, and stores the root Document +// node, ready to be manipulated. +// +// Deprecated: Use the net/http standard library package to make the request +// and validate the response before calling goquery.NewDocumentFromReader +// with the response's body. +func NewDocument(url string) (*Document, error) { + // Load the URL + res, e := http.Get(url) + if e != nil { + return nil, e + } + return NewDocumentFromResponse(res) +} + +// NewDocumentFromReader returns a Document from an io.Reader. +// It returns an error as second value if the reader's data cannot be parsed +// as html. It does not check if the reader is also an io.Closer, the +// provided reader is never closed by this call. It is the responsibility +// of the caller to close it if required. +func NewDocumentFromReader(r io.Reader) (*Document, error) { + root, e := html.Parse(r) + if e != nil { + return nil, e + } + return newDocument(root, nil), nil +} + +// NewDocumentFromResponse is another Document constructor that takes an http response as argument. +// It loads the specified response's document, parses it, and stores the root Document +// node, ready to be manipulated. The response's body is closed on return. +// +// Deprecated: Use goquery.NewDocumentFromReader with the response's body. +func NewDocumentFromResponse(res *http.Response) (*Document, error) { + if res == nil { + return nil, errors.New("Response is nil") + } + defer res.Body.Close() + if res.Request == nil { + return nil, errors.New("Response.Request is nil") + } + + // Parse the HTML into nodes + root, e := html.Parse(res.Body) + if e != nil { + return nil, e + } + + // Create and fill the document + return newDocument(root, res.Request.URL), nil +} + +// CloneDocument creates a deep-clone of a document. +func CloneDocument(doc *Document) *Document { + return newDocument(cloneNode(doc.rootNode), doc.Url) +} + +// Private constructor, make sure all fields are correctly filled. +func newDocument(root *html.Node, url *url.URL) *Document { + // Create and fill the document + d := &Document{nil, url, root} + d.Selection = newSingleSelection(root, d) + return d +} + +// Selection represents a collection of nodes matching some criteria. The +// initial Selection can be created by using Document.Find, and then +// manipulated using the jQuery-like chainable syntax and methods. +type Selection struct { + Nodes []*html.Node + document *Document + prevSel *Selection +} + +// Helper constructor to create an empty selection +func newEmptySelection(doc *Document) *Selection { + return &Selection{nil, doc, nil} +} + +// Helper constructor to create a selection of only one node +func newSingleSelection(node *html.Node, doc *Document) *Selection { + return &Selection{[]*html.Node{node}, doc, nil} +} + +// Matcher is an interface that defines the methods to match +// HTML nodes against a compiled selector string. Cascadia's +// Selector implements this interface. +type Matcher interface { + Match(*html.Node) bool + MatchAll(*html.Node) []*html.Node + Filter([]*html.Node) []*html.Node +} + +// compileMatcher compiles the selector string s and returns +// the corresponding Matcher. If s is an invalid selector string, +// it returns a Matcher that fails all matches. +func compileMatcher(s string) Matcher { + cs, err := cascadia.Compile(s) + if err != nil { + return invalidMatcher{} + } + return cs +} + +// invalidMatcher is a Matcher that always fails to match. +type invalidMatcher struct{} + +func (invalidMatcher) Match(n *html.Node) bool { return false } +func (invalidMatcher) MatchAll(n *html.Node) []*html.Node { return nil } +func (invalidMatcher) Filter(ns []*html.Node) []*html.Node { return nil } diff --git a/vendor/github.com/PuerkitoBio/goquery/type_test.go b/vendor/github.com/PuerkitoBio/goquery/type_test.go new file mode 100644 index 0000000..1e82d5e --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/type_test.go @@ -0,0 +1,202 @@ +package goquery + +import ( + "bytes" + "fmt" + "os" + "strings" + "testing" + + "golang.org/x/net/html" +) + +// Test helper functions and members +var doc *Document +var doc2 *Document +var doc3 *Document +var docB *Document +var docW *Document + +func Doc() *Document { + if doc == nil { + doc = loadDoc("page.html") + } + return doc +} + +func Doc2() *Document { + if doc2 == nil { + doc2 = loadDoc("page2.html") + } + return doc2 +} + +func Doc2Clone() *Document { + return CloneDocument(Doc2()) +} + +func Doc3() *Document { + if doc3 == nil { + doc3 = loadDoc("page3.html") + } + return doc3 +} + +func Doc3Clone() *Document { + return CloneDocument(Doc3()) +} + +func DocB() *Document { + if docB == nil { + docB = loadDoc("gotesting.html") + } + return docB +} + +func DocW() *Document { + if docW == nil { + docW = loadDoc("gowiki.html") + } + return docW +} + +func assertLength(t *testing.T, nodes []*html.Node, length int) { + if len(nodes) != length { + t.Errorf("Expected %d nodes, found %d.", length, len(nodes)) + for i, n := range nodes { + t.Logf("Node %d: %+v.", i, n) + } + } +} + +func assertClass(t *testing.T, sel *Selection, class string) { + if !sel.HasClass(class) { + t.Errorf("Expected node to have class %s, found %+v.", class, sel.Get(0)) + } +} + +func assertPanic(t *testing.T) { + if e := recover(); e == nil { + t.Error("Expected a panic.") + } +} + +func assertEqual(t *testing.T, s1 *Selection, s2 *Selection) { + if s1 != s2 { + t.Error("Expected selection objects to be the same.") + } +} + +func assertSelectionIs(t *testing.T, sel *Selection, is ...string) { + for i := 0; i < sel.Length(); i++ { + if !sel.Eq(i).Is(is[i]) { + t.Errorf("Expected node %d to be %s, found %+v", i, is[i], sel.Get(i)) + } + } +} + +func printSel(t *testing.T, sel *Selection) { + if testing.Verbose() { + h, err := sel.Html() + if err != nil { + t.Fatal(err) + } + t.Log(h) + } +} + +func loadDoc(page string) *Document { + var f *os.File + var e error + + if f, e = os.Open(fmt.Sprintf("./testdata/%s", page)); e != nil { + panic(e.Error()) + } + defer f.Close() + + var node *html.Node + if node, e = html.Parse(f); e != nil { + panic(e.Error()) + } + return NewDocumentFromNode(node) +} + +func TestNewDocument(t *testing.T) { + if f, e := os.Open("./testdata/page.html"); e != nil { + t.Error(e.Error()) + } else { + defer f.Close() + if node, e := html.Parse(f); e != nil { + t.Error(e.Error()) + } else { + doc = NewDocumentFromNode(node) + } + } +} + +func TestNewDocumentFromReader(t *testing.T) { + cases := []struct { + src string + err bool + sel string + cnt int + }{ + 0: { + src: ` + + +Test + +

Hi

+ +`, + sel: "h1", + cnt: 1, + }, + 1: { + // Actually pretty hard to make html.Parse return an error + // based on content... + src: `>>qq>`, + }, + } + buf := bytes.NewBuffer(nil) + + for i, c := range cases { + buf.Reset() + buf.WriteString(c.src) + + d, e := NewDocumentFromReader(buf) + if (e != nil) != c.err { + if c.err { + t.Errorf("[%d] - expected error, got none", i) + } else { + t.Errorf("[%d] - expected no error, got %s", i, e) + } + } + if c.sel != "" { + s := d.Find(c.sel) + if s.Length() != c.cnt { + t.Errorf("[%d] - expected %d nodes, found %d", i, c.cnt, s.Length()) + } + } + } +} + +func TestNewDocumentFromResponseNil(t *testing.T) { + _, e := NewDocumentFromResponse(nil) + if e == nil { + t.Error("Expected error, got none") + } +} + +func TestIssue103(t *testing.T) { + d, err := NewDocumentFromReader(strings.NewReader("Scientists Stored These Images in DNA—Then Flawlessly Retrieved Them")) + if err != nil { + t.Error(err) + } + text := d.Find("title").Text() + for i, r := range text { + t.Logf("%d: %d - %q\n", i, r, string(r)) + } + t.Log(text) +} diff --git a/vendor/github.com/PuerkitoBio/goquery/utilities.go b/vendor/github.com/PuerkitoBio/goquery/utilities.go new file mode 100644 index 0000000..b4c061a --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/utilities.go @@ -0,0 +1,161 @@ +package goquery + +import ( + "bytes" + + "golang.org/x/net/html" +) + +// used to determine if a set (map[*html.Node]bool) should be used +// instead of iterating over a slice. The set uses more memory and +// is slower than slice iteration for small N. +const minNodesForSet = 1000 + +var nodeNames = []string{ + html.ErrorNode: "#error", + html.TextNode: "#text", + html.DocumentNode: "#document", + html.CommentNode: "#comment", +} + +// NodeName returns the node name of the first element in the selection. +// It tries to behave in a similar way as the DOM's nodeName property +// (https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName). +// +// Go's net/html package defines the following node types, listed with +// the corresponding returned value from this function: +// +// ErrorNode : #error +// TextNode : #text +// DocumentNode : #document +// ElementNode : the element's tag name +// CommentNode : #comment +// DoctypeNode : the name of the document type +// +func NodeName(s *Selection) string { + if s.Length() == 0 { + return "" + } + switch n := s.Get(0); n.Type { + case html.ElementNode, html.DoctypeNode: + return n.Data + default: + if n.Type >= 0 && int(n.Type) < len(nodeNames) { + return nodeNames[n.Type] + } + return "" + } +} + +// OuterHtml returns the outer HTML rendering of the first item in +// the selection - that is, the HTML including the first element's +// tag and attributes. +// +// Unlike InnerHtml, this is a function and not a method on the Selection, +// because this is not a jQuery method (in javascript-land, this is +// a property provided by the DOM). +func OuterHtml(s *Selection) (string, error) { + var buf bytes.Buffer + + if s.Length() == 0 { + return "", nil + } + n := s.Get(0) + if err := html.Render(&buf, n); err != nil { + return "", err + } + return buf.String(), nil +} + +// Loop through all container nodes to search for the target node. +func sliceContains(container []*html.Node, contained *html.Node) bool { + for _, n := range container { + if nodeContains(n, contained) { + return true + } + } + + return false +} + +// Checks if the contained node is within the container node. +func nodeContains(container *html.Node, contained *html.Node) bool { + // Check if the parent of the contained node is the container node, traversing + // upward until the top is reached, or the container is found. + for contained = contained.Parent; contained != nil; contained = contained.Parent { + if container == contained { + return true + } + } + return false +} + +// Checks if the target node is in the slice of nodes. +func isInSlice(slice []*html.Node, node *html.Node) bool { + return indexInSlice(slice, node) > -1 +} + +// Returns the index of the target node in the slice, or -1. +func indexInSlice(slice []*html.Node, node *html.Node) int { + if node != nil { + for i, n := range slice { + if n == node { + return i + } + } + } + return -1 +} + +// Appends the new nodes to the target slice, making sure no duplicate is added. +// There is no check to the original state of the target slice, so it may still +// contain duplicates. The target slice is returned because append() may create +// a new underlying array. If targetSet is nil, a local set is created with the +// target if len(target) + len(nodes) is greater than minNodesForSet. +func appendWithoutDuplicates(target []*html.Node, nodes []*html.Node, targetSet map[*html.Node]bool) []*html.Node { + // if there are not that many nodes, don't use the map, faster to just use nested loops + // (unless a non-nil targetSet is passed, in which case the caller knows better). + if targetSet == nil && len(target)+len(nodes) < minNodesForSet { + for _, n := range nodes { + if !isInSlice(target, n) { + target = append(target, n) + } + } + return target + } + + // if a targetSet is passed, then assume it is reliable, otherwise create one + // and initialize it with the current target contents. + if targetSet == nil { + targetSet = make(map[*html.Node]bool, len(target)) + for _, n := range target { + targetSet[n] = true + } + } + for _, n := range nodes { + if !targetSet[n] { + target = append(target, n) + targetSet[n] = true + } + } + + return target +} + +// Loop through a selection, returning only those nodes that pass the predicate +// function. +func grep(sel *Selection, predicate func(i int, s *Selection) bool) (result []*html.Node) { + for i, n := range sel.Nodes { + if predicate(i, newSingleSelection(n, sel.document)) { + result = append(result, n) + } + } + return result +} + +// Creates a new Selection object based on the specified nodes, and keeps the +// source Selection object on the stack (linked list). +func pushStack(fromSel *Selection, nodes []*html.Node) *Selection { + result := &Selection{nodes, fromSel.document, fromSel} + return result +} diff --git a/vendor/github.com/PuerkitoBio/goquery/utilities_test.go b/vendor/github.com/PuerkitoBio/goquery/utilities_test.go new file mode 100644 index 0000000..c8e9d54 --- /dev/null +++ b/vendor/github.com/PuerkitoBio/goquery/utilities_test.go @@ -0,0 +1,128 @@ +package goquery + +import ( + "reflect" + "sort" + "strings" + "testing" + + "golang.org/x/net/html" +) + +var allNodes = ` + + + + + +

+ This is some text. +

+
+

+

+ +` + +func TestNodeName(t *testing.T) { + doc, err := NewDocumentFromReader(strings.NewReader(allNodes)) + if err != nil { + t.Fatal(err) + } + + n0 := doc.Nodes[0] + nDT := n0.FirstChild + sMeta := doc.Find("meta") + nMeta := sMeta.Get(0) + sP := doc.Find("p") + nP := sP.Get(0) + nComment := nP.FirstChild + nText := nComment.NextSibling + + cases := []struct { + node *html.Node + typ html.NodeType + want string + }{ + {n0, html.DocumentNode, nodeNames[html.DocumentNode]}, + {nDT, html.DoctypeNode, "html"}, + {nMeta, html.ElementNode, "meta"}, + {nP, html.ElementNode, "p"}, + {nComment, html.CommentNode, nodeNames[html.CommentNode]}, + {nText, html.TextNode, nodeNames[html.TextNode]}, + } + for i, c := range cases { + got := NodeName(newSingleSelection(c.node, doc)) + if c.node.Type != c.typ { + t.Errorf("%d: want type %v, got %v", i, c.typ, c.node.Type) + } + if got != c.want { + t.Errorf("%d: want %q, got %q", i, c.want, got) + } + } +} + +func TestNodeNameMultiSel(t *testing.T) { + doc, err := NewDocumentFromReader(strings.NewReader(allNodes)) + if err != nil { + t.Fatal(err) + } + + in := []string{"p", "h1", "div"} + var out []string + doc.Find(strings.Join(in, ", ")).Each(func(i int, s *Selection) { + got := NodeName(s) + out = append(out, got) + }) + sort.Strings(in) + sort.Strings(out) + if !reflect.DeepEqual(in, out) { + t.Errorf("want %v, got %v", in, out) + } +} + +func TestOuterHtml(t *testing.T) { + doc, err := NewDocumentFromReader(strings.NewReader(allNodes)) + if err != nil { + t.Fatal(err) + } + + n0 := doc.Nodes[0] + nDT := n0.FirstChild + sMeta := doc.Find("meta") + sP := doc.Find("p") + nP := sP.Get(0) + nComment := nP.FirstChild + nText := nComment.NextSibling + sHeaders := doc.Find(".header") + + cases := []struct { + node *html.Node + sel *Selection + want string + }{ + {nDT, nil, ""}, // render makes DOCTYPE all caps + {nil, sMeta, ``}, // and auto-closes the meta + {nil, sP, `

+ This is some text. +

`}, + {nComment, nil, ""}, + {nText, nil, ` + This is some text. + `}, + {nil, sHeaders, `

`}, + } + for i, c := range cases { + if c.sel == nil { + c.sel = newSingleSelection(c.node, doc) + } + got, err := OuterHtml(c.sel) + if err != nil { + t.Fatal(err) + } + + if got != c.want { + t.Errorf("%d: want %q, got %q", i, c.want, got) + } + } +} diff --git a/vendor/github.com/andybalholm/cascadia/LICENSE b/vendor/github.com/andybalholm/cascadia/LICENSE new file mode 100755 index 0000000..ee5ad35 --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2011 Andy Balholm. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/andybalholm/cascadia/README.md b/vendor/github.com/andybalholm/cascadia/README.md new file mode 100644 index 0000000..26f4c37 --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/README.md @@ -0,0 +1,9 @@ +# cascadia + +[![](https://travis-ci.org/andybalholm/cascadia.svg)](https://travis-ci.org/andybalholm/cascadia) + +The Cascadia package implements CSS selectors for use with the parse trees produced by the html package. + +To test CSS selectors without writing Go code, check out [cascadia](https://github.com/suntong/cascadia) the command line tool, a thin wrapper around this package. + +[Refer to godoc here](https://godoc.org/github.com/andybalholm/cascadia). diff --git a/vendor/github.com/andybalholm/cascadia/benchmark_test.go b/vendor/github.com/andybalholm/cascadia/benchmark_test.go new file mode 100644 index 0000000..42bf500 --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/benchmark_test.go @@ -0,0 +1,53 @@ +package cascadia + +import ( + "strings" + "testing" + + "golang.org/x/net/html" +) + +func MustParseHTML(doc string) *html.Node { + dom, err := html.Parse(strings.NewReader(doc)) + if err != nil { + panic(err) + } + return dom +} + +var selector = MustCompile(`div.matched`) +var doc = ` + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +` +var dom = MustParseHTML(doc) + +func BenchmarkMatchAll(b *testing.B) { + var matches []*html.Node + for i := 0; i < b.N; i++ { + matches = selector.MatchAll(dom) + } + _ = matches +} diff --git a/vendor/github.com/andybalholm/cascadia/go.mod b/vendor/github.com/andybalholm/cascadia/go.mod new file mode 100644 index 0000000..e6febbb --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/go.mod @@ -0,0 +1,3 @@ +module "github.com/andybalholm/cascadia" + +require "golang.org/x/net" v0.0.0-20180218175443-cbe0f9307d01 diff --git a/vendor/github.com/andybalholm/cascadia/parser.go b/vendor/github.com/andybalholm/cascadia/parser.go new file mode 100644 index 0000000..495db9c --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/parser.go @@ -0,0 +1,835 @@ +// Package cascadia is an implementation of CSS selectors. +package cascadia + +import ( + "errors" + "fmt" + "regexp" + "strconv" + "strings" + + "golang.org/x/net/html" +) + +// a parser for CSS selectors +type parser struct { + s string // the source text + i int // the current position +} + +// parseEscape parses a backslash escape. +func (p *parser) parseEscape() (result string, err error) { + if len(p.s) < p.i+2 || p.s[p.i] != '\\' { + return "", errors.New("invalid escape sequence") + } + + start := p.i + 1 + c := p.s[start] + switch { + case c == '\r' || c == '\n' || c == '\f': + return "", errors.New("escaped line ending outside string") + case hexDigit(c): + // unicode escape (hex) + var i int + for i = start; i < p.i+6 && i < len(p.s) && hexDigit(p.s[i]); i++ { + // empty + } + v, _ := strconv.ParseUint(p.s[start:i], 16, 21) + if len(p.s) > i { + switch p.s[i] { + case '\r': + i++ + if len(p.s) > i && p.s[i] == '\n' { + i++ + } + case ' ', '\t', '\n', '\f': + i++ + } + } + p.i = i + return string(rune(v)), nil + } + + // Return the literal character after the backslash. + result = p.s[start : start+1] + p.i += 2 + return result, nil +} + +func hexDigit(c byte) bool { + return '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' +} + +// nameStart returns whether c can be the first character of an identifier +// (not counting an initial hyphen, or an escape sequence). +func nameStart(c byte) bool { + return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_' || c > 127 +} + +// nameChar returns whether c can be a character within an identifier +// (not counting an escape sequence). +func nameChar(c byte) bool { + return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_' || c > 127 || + c == '-' || '0' <= c && c <= '9' +} + +// parseIdentifier parses an identifier. +func (p *parser) parseIdentifier() (result string, err error) { + startingDash := false + if len(p.s) > p.i && p.s[p.i] == '-' { + startingDash = true + p.i++ + } + + if len(p.s) <= p.i { + return "", errors.New("expected identifier, found EOF instead") + } + + if c := p.s[p.i]; !(nameStart(c) || c == '\\') { + return "", fmt.Errorf("expected identifier, found %c instead", c) + } + + result, err = p.parseName() + if startingDash && err == nil { + result = "-" + result + } + return +} + +// parseName parses a name (which is like an identifier, but doesn't have +// extra restrictions on the first character). +func (p *parser) parseName() (result string, err error) { + i := p.i +loop: + for i < len(p.s) { + c := p.s[i] + switch { + case nameChar(c): + start := i + for i < len(p.s) && nameChar(p.s[i]) { + i++ + } + result += p.s[start:i] + case c == '\\': + p.i = i + val, err := p.parseEscape() + if err != nil { + return "", err + } + i = p.i + result += val + default: + break loop + } + } + + if result == "" { + return "", errors.New("expected name, found EOF instead") + } + + p.i = i + return result, nil +} + +// parseString parses a single- or double-quoted string. +func (p *parser) parseString() (result string, err error) { + i := p.i + if len(p.s) < i+2 { + return "", errors.New("expected string, found EOF instead") + } + + quote := p.s[i] + i++ + +loop: + for i < len(p.s) { + switch p.s[i] { + case '\\': + if len(p.s) > i+1 { + switch c := p.s[i+1]; c { + case '\r': + if len(p.s) > i+2 && p.s[i+2] == '\n' { + i += 3 + continue loop + } + fallthrough + case '\n', '\f': + i += 2 + continue loop + } + } + p.i = i + val, err := p.parseEscape() + if err != nil { + return "", err + } + i = p.i + result += val + case quote: + break loop + case '\r', '\n', '\f': + return "", errors.New("unexpected end of line in string") + default: + start := i + for i < len(p.s) { + if c := p.s[i]; c == quote || c == '\\' || c == '\r' || c == '\n' || c == '\f' { + break + } + i++ + } + result += p.s[start:i] + } + } + + if i >= len(p.s) { + return "", errors.New("EOF in string") + } + + // Consume the final quote. + i++ + + p.i = i + return result, nil +} + +// parseRegex parses a regular expression; the end is defined by encountering an +// unmatched closing ')' or ']' which is not consumed +func (p *parser) parseRegex() (rx *regexp.Regexp, err error) { + i := p.i + if len(p.s) < i+2 { + return nil, errors.New("expected regular expression, found EOF instead") + } + + // number of open parens or brackets; + // when it becomes negative, finished parsing regex + open := 0 + +loop: + for i < len(p.s) { + switch p.s[i] { + case '(', '[': + open++ + case ')', ']': + open-- + if open < 0 { + break loop + } + } + i++ + } + + if i >= len(p.s) { + return nil, errors.New("EOF in regular expression") + } + rx, err = regexp.Compile(p.s[p.i:i]) + p.i = i + return rx, err +} + +// skipWhitespace consumes whitespace characters and comments. +// It returns true if there was actually anything to skip. +func (p *parser) skipWhitespace() bool { + i := p.i + for i < len(p.s) { + switch p.s[i] { + case ' ', '\t', '\r', '\n', '\f': + i++ + continue + case '/': + if strings.HasPrefix(p.s[i:], "/*") { + end := strings.Index(p.s[i+len("/*"):], "*/") + if end != -1 { + i += end + len("/**/") + continue + } + } + } + break + } + + if i > p.i { + p.i = i + return true + } + + return false +} + +// consumeParenthesis consumes an opening parenthesis and any following +// whitespace. It returns true if there was actually a parenthesis to skip. +func (p *parser) consumeParenthesis() bool { + if p.i < len(p.s) && p.s[p.i] == '(' { + p.i++ + p.skipWhitespace() + return true + } + return false +} + +// consumeClosingParenthesis consumes a closing parenthesis and any preceding +// whitespace. It returns true if there was actually a parenthesis to skip. +func (p *parser) consumeClosingParenthesis() bool { + i := p.i + p.skipWhitespace() + if p.i < len(p.s) && p.s[p.i] == ')' { + p.i++ + return true + } + p.i = i + return false +} + +// parseTypeSelector parses a type selector (one that matches by tag name). +func (p *parser) parseTypeSelector() (result Selector, err error) { + tag, err := p.parseIdentifier() + if err != nil { + return nil, err + } + + return typeSelector(tag), nil +} + +// parseIDSelector parses a selector that matches by id attribute. +func (p *parser) parseIDSelector() (Selector, error) { + if p.i >= len(p.s) { + return nil, fmt.Errorf("expected id selector (#id), found EOF instead") + } + if p.s[p.i] != '#' { + return nil, fmt.Errorf("expected id selector (#id), found '%c' instead", p.s[p.i]) + } + + p.i++ + id, err := p.parseName() + if err != nil { + return nil, err + } + + return attributeEqualsSelector("id", id), nil +} + +// parseClassSelector parses a selector that matches by class attribute. +func (p *parser) parseClassSelector() (Selector, error) { + if p.i >= len(p.s) { + return nil, fmt.Errorf("expected class selector (.class), found EOF instead") + } + if p.s[p.i] != '.' { + return nil, fmt.Errorf("expected class selector (.class), found '%c' instead", p.s[p.i]) + } + + p.i++ + class, err := p.parseIdentifier() + if err != nil { + return nil, err + } + + return attributeIncludesSelector("class", class), nil +} + +// parseAttributeSelector parses a selector that matches by attribute value. +func (p *parser) parseAttributeSelector() (Selector, error) { + if p.i >= len(p.s) { + return nil, fmt.Errorf("expected attribute selector ([attribute]), found EOF instead") + } + if p.s[p.i] != '[' { + return nil, fmt.Errorf("expected attribute selector ([attribute]), found '%c' instead", p.s[p.i]) + } + + p.i++ + p.skipWhitespace() + key, err := p.parseIdentifier() + if err != nil { + return nil, err + } + + p.skipWhitespace() + if p.i >= len(p.s) { + return nil, errors.New("unexpected EOF in attribute selector") + } + + if p.s[p.i] == ']' { + p.i++ + return attributeExistsSelector(key), nil + } + + if p.i+2 >= len(p.s) { + return nil, errors.New("unexpected EOF in attribute selector") + } + + op := p.s[p.i : p.i+2] + if op[0] == '=' { + op = "=" + } else if op[1] != '=' { + return nil, fmt.Errorf(`expected equality operator, found "%s" instead`, op) + } + p.i += len(op) + + p.skipWhitespace() + if p.i >= len(p.s) { + return nil, errors.New("unexpected EOF in attribute selector") + } + var val string + var rx *regexp.Regexp + if op == "#=" { + rx, err = p.parseRegex() + } else { + switch p.s[p.i] { + case '\'', '"': + val, err = p.parseString() + default: + val, err = p.parseIdentifier() + } + } + if err != nil { + return nil, err + } + + p.skipWhitespace() + if p.i >= len(p.s) { + return nil, errors.New("unexpected EOF in attribute selector") + } + if p.s[p.i] != ']' { + return nil, fmt.Errorf("expected ']', found '%c' instead", p.s[p.i]) + } + p.i++ + + switch op { + case "=": + return attributeEqualsSelector(key, val), nil + case "!=": + return attributeNotEqualSelector(key, val), nil + case "~=": + return attributeIncludesSelector(key, val), nil + case "|=": + return attributeDashmatchSelector(key, val), nil + case "^=": + return attributePrefixSelector(key, val), nil + case "$=": + return attributeSuffixSelector(key, val), nil + case "*=": + return attributeSubstringSelector(key, val), nil + case "#=": + return attributeRegexSelector(key, rx), nil + } + + return nil, fmt.Errorf("attribute operator %q is not supported", op) +} + +var errExpectedParenthesis = errors.New("expected '(' but didn't find it") +var errExpectedClosingParenthesis = errors.New("expected ')' but didn't find it") +var errUnmatchedParenthesis = errors.New("unmatched '('") + +// parsePseudoclassSelector parses a pseudoclass selector like :not(p). +func (p *parser) parsePseudoclassSelector() (Selector, error) { + if p.i >= len(p.s) { + return nil, fmt.Errorf("expected pseudoclass selector (:pseudoclass), found EOF instead") + } + if p.s[p.i] != ':' { + return nil, fmt.Errorf("expected attribute selector (:pseudoclass), found '%c' instead", p.s[p.i]) + } + + p.i++ + name, err := p.parseIdentifier() + if err != nil { + return nil, err + } + name = toLowerASCII(name) + + switch name { + case "not", "has", "haschild": + if !p.consumeParenthesis() { + return nil, errExpectedParenthesis + } + sel, parseErr := p.parseSelectorGroup() + if parseErr != nil { + return nil, parseErr + } + if !p.consumeClosingParenthesis() { + return nil, errExpectedClosingParenthesis + } + + switch name { + case "not": + return negatedSelector(sel), nil + case "has": + return hasDescendantSelector(sel), nil + case "haschild": + return hasChildSelector(sel), nil + } + + case "contains", "containsown": + if !p.consumeParenthesis() { + return nil, errExpectedParenthesis + } + if p.i == len(p.s) { + return nil, errUnmatchedParenthesis + } + var val string + switch p.s[p.i] { + case '\'', '"': + val, err = p.parseString() + default: + val, err = p.parseIdentifier() + } + if err != nil { + return nil, err + } + val = strings.ToLower(val) + p.skipWhitespace() + if p.i >= len(p.s) { + return nil, errors.New("unexpected EOF in pseudo selector") + } + if !p.consumeClosingParenthesis() { + return nil, errExpectedClosingParenthesis + } + + switch name { + case "contains": + return textSubstrSelector(val), nil + case "containsown": + return ownTextSubstrSelector(val), nil + } + + case "matches", "matchesown": + if !p.consumeParenthesis() { + return nil, errExpectedParenthesis + } + rx, err := p.parseRegex() + if err != nil { + return nil, err + } + if p.i >= len(p.s) { + return nil, errors.New("unexpected EOF in pseudo selector") + } + if !p.consumeClosingParenthesis() { + return nil, errExpectedClosingParenthesis + } + + switch name { + case "matches": + return textRegexSelector(rx), nil + case "matchesown": + return ownTextRegexSelector(rx), nil + } + + case "nth-child", "nth-last-child", "nth-of-type", "nth-last-of-type": + if !p.consumeParenthesis() { + return nil, errExpectedParenthesis + } + a, b, err := p.parseNth() + if err != nil { + return nil, err + } + if !p.consumeClosingParenthesis() { + return nil, errExpectedClosingParenthesis + } + if a == 0 { + switch name { + case "nth-child": + return simpleNthChildSelector(b, false), nil + case "nth-of-type": + return simpleNthChildSelector(b, true), nil + case "nth-last-child": + return simpleNthLastChildSelector(b, false), nil + case "nth-last-of-type": + return simpleNthLastChildSelector(b, true), nil + } + } + return nthChildSelector(a, b, + name == "nth-last-child" || name == "nth-last-of-type", + name == "nth-of-type" || name == "nth-last-of-type"), + nil + + case "first-child": + return simpleNthChildSelector(1, false), nil + case "last-child": + return simpleNthLastChildSelector(1, false), nil + case "first-of-type": + return simpleNthChildSelector(1, true), nil + case "last-of-type": + return simpleNthLastChildSelector(1, true), nil + case "only-child": + return onlyChildSelector(false), nil + case "only-of-type": + return onlyChildSelector(true), nil + case "input": + return inputSelector, nil + case "empty": + return emptyElementSelector, nil + case "root": + return rootSelector, nil + } + + return nil, fmt.Errorf("unknown pseudoclass :%s", name) +} + +// parseInteger parses a decimal integer. +func (p *parser) parseInteger() (int, error) { + i := p.i + start := i + for i < len(p.s) && '0' <= p.s[i] && p.s[i] <= '9' { + i++ + } + if i == start { + return 0, errors.New("expected integer, but didn't find it") + } + p.i = i + + val, err := strconv.Atoi(p.s[start:i]) + if err != nil { + return 0, err + } + + return val, nil +} + +// parseNth parses the argument for :nth-child (normally of the form an+b). +func (p *parser) parseNth() (a, b int, err error) { + // initial state + if p.i >= len(p.s) { + goto eof + } + switch p.s[p.i] { + case '-': + p.i++ + goto negativeA + case '+': + p.i++ + goto positiveA + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + goto positiveA + case 'n', 'N': + a = 1 + p.i++ + goto readN + case 'o', 'O', 'e', 'E': + id, nameErr := p.parseName() + if nameErr != nil { + return 0, 0, nameErr + } + id = toLowerASCII(id) + if id == "odd" { + return 2, 1, nil + } + if id == "even" { + return 2, 0, nil + } + return 0, 0, fmt.Errorf("expected 'odd' or 'even', but found '%s' instead", id) + default: + goto invalid + } + +positiveA: + if p.i >= len(p.s) { + goto eof + } + switch p.s[p.i] { + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + a, err = p.parseInteger() + if err != nil { + return 0, 0, err + } + goto readA + case 'n', 'N': + a = 1 + p.i++ + goto readN + default: + goto invalid + } + +negativeA: + if p.i >= len(p.s) { + goto eof + } + switch p.s[p.i] { + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + a, err = p.parseInteger() + if err != nil { + return 0, 0, err + } + a = -a + goto readA + case 'n', 'N': + a = -1 + p.i++ + goto readN + default: + goto invalid + } + +readA: + if p.i >= len(p.s) { + goto eof + } + switch p.s[p.i] { + case 'n', 'N': + p.i++ + goto readN + default: + // The number we read as a is actually b. + return 0, a, nil + } + +readN: + p.skipWhitespace() + if p.i >= len(p.s) { + goto eof + } + switch p.s[p.i] { + case '+': + p.i++ + p.skipWhitespace() + b, err = p.parseInteger() + if err != nil { + return 0, 0, err + } + return a, b, nil + case '-': + p.i++ + p.skipWhitespace() + b, err = p.parseInteger() + if err != nil { + return 0, 0, err + } + return a, -b, nil + default: + return a, 0, nil + } + +eof: + return 0, 0, errors.New("unexpected EOF while attempting to parse expression of form an+b") + +invalid: + return 0, 0, errors.New("unexpected character while attempting to parse expression of form an+b") +} + +// parseSimpleSelectorSequence parses a selector sequence that applies to +// a single element. +func (p *parser) parseSimpleSelectorSequence() (Selector, error) { + var result Selector + + if p.i >= len(p.s) { + return nil, errors.New("expected selector, found EOF instead") + } + + switch p.s[p.i] { + case '*': + // It's the universal selector. Just skip over it, since it doesn't affect the meaning. + p.i++ + case '#', '.', '[', ':': + // There's no type selector. Wait to process the other till the main loop. + default: + r, err := p.parseTypeSelector() + if err != nil { + return nil, err + } + result = r + } + +loop: + for p.i < len(p.s) { + var ns Selector + var err error + switch p.s[p.i] { + case '#': + ns, err = p.parseIDSelector() + case '.': + ns, err = p.parseClassSelector() + case '[': + ns, err = p.parseAttributeSelector() + case ':': + ns, err = p.parsePseudoclassSelector() + default: + break loop + } + if err != nil { + return nil, err + } + if result == nil { + result = ns + } else { + result = intersectionSelector(result, ns) + } + } + + if result == nil { + result = func(n *html.Node) bool { + return n.Type == html.ElementNode + } + } + + return result, nil +} + +// parseSelector parses a selector that may include combinators. +func (p *parser) parseSelector() (result Selector, err error) { + p.skipWhitespace() + result, err = p.parseSimpleSelectorSequence() + if err != nil { + return + } + + for { + var combinator byte + if p.skipWhitespace() { + combinator = ' ' + } + if p.i >= len(p.s) { + return + } + + switch p.s[p.i] { + case '+', '>', '~': + combinator = p.s[p.i] + p.i++ + p.skipWhitespace() + case ',', ')': + // These characters can't begin a selector, but they can legally occur after one. + return + } + + if combinator == 0 { + return + } + + c, err := p.parseSimpleSelectorSequence() + if err != nil { + return nil, err + } + + switch combinator { + case ' ': + result = descendantSelector(result, c) + case '>': + result = childSelector(result, c) + case '+': + result = siblingSelector(result, c, true) + case '~': + result = siblingSelector(result, c, false) + } + } + + panic("unreachable") +} + +// parseSelectorGroup parses a group of selectors, separated by commas. +func (p *parser) parseSelectorGroup() (result Selector, err error) { + result, err = p.parseSelector() + if err != nil { + return + } + + for p.i < len(p.s) { + if p.s[p.i] != ',' { + return result, nil + } + p.i++ + c, err := p.parseSelector() + if err != nil { + return nil, err + } + result = unionSelector(result, c) + } + + return +} diff --git a/vendor/github.com/andybalholm/cascadia/parser_test.go b/vendor/github.com/andybalholm/cascadia/parser_test.go new file mode 100644 index 0000000..47dd4a6 --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/parser_test.go @@ -0,0 +1,86 @@ +package cascadia + +import ( + "testing" +) + +var identifierTests = map[string]string{ + "x": "x", + "96": "", + "-x": "-x", + `r\e9 sumé`: "résumé", + `a\"b`: `a"b`, +} + +func TestParseIdentifier(t *testing.T) { + for source, want := range identifierTests { + p := &parser{s: source} + got, err := p.parseIdentifier() + + if err != nil { + if want == "" { + // It was supposed to be an error. + continue + } + t.Errorf("parsing %q: got error (%s), want %q", source, err, want) + continue + } + + if want == "" { + if err == nil { + t.Errorf("parsing %q: got %q, want error", source, got) + } + continue + } + + if p.i < len(source) { + t.Errorf("parsing %q: %d bytes left over", source, len(source)-p.i) + continue + } + + if got != want { + t.Errorf("parsing %q: got %q, want %q", source, got, want) + } + } +} + +var stringTests = map[string]string{ + `"x"`: "x", + `'x'`: "x", + `'x`: "", + "'x\\\r\nx'": "xx", + `"r\e9 sumé"`: "résumé", + `"a\"b"`: `a"b`, +} + +func TestParseString(t *testing.T) { + for source, want := range stringTests { + p := &parser{s: source} + got, err := p.parseString() + + if err != nil { + if want == "" { + // It was supposed to be an error. + continue + } + t.Errorf("parsing %q: got error (%s), want %q", source, err, want) + continue + } + + if want == "" { + if err == nil { + t.Errorf("parsing %q: got %q, want error", source, got) + } + continue + } + + if p.i < len(source) { + t.Errorf("parsing %q: %d bytes left over", source, len(source)-p.i) + continue + } + + if got != want { + t.Errorf("parsing %q: got %q, want %q", source, got, want) + } + } +} diff --git a/vendor/github.com/andybalholm/cascadia/selector.go b/vendor/github.com/andybalholm/cascadia/selector.go new file mode 100644 index 0000000..9fb05cc --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/selector.go @@ -0,0 +1,622 @@ +package cascadia + +import ( + "bytes" + "fmt" + "regexp" + "strings" + + "golang.org/x/net/html" +) + +// the Selector type, and functions for creating them + +// A Selector is a function which tells whether a node matches or not. +type Selector func(*html.Node) bool + +// hasChildMatch returns whether n has any child that matches a. +func hasChildMatch(n *html.Node, a Selector) bool { + for c := n.FirstChild; c != nil; c = c.NextSibling { + if a(c) { + return true + } + } + return false +} + +// hasDescendantMatch performs a depth-first search of n's descendants, +// testing whether any of them match a. It returns true as soon as a match is +// found, or false if no match is found. +func hasDescendantMatch(n *html.Node, a Selector) bool { + for c := n.FirstChild; c != nil; c = c.NextSibling { + if a(c) || (c.Type == html.ElementNode && hasDescendantMatch(c, a)) { + return true + } + } + return false +} + +// Compile parses a selector and returns, if successful, a Selector object +// that can be used to match against html.Node objects. +func Compile(sel string) (Selector, error) { + p := &parser{s: sel} + compiled, err := p.parseSelectorGroup() + if err != nil { + return nil, err + } + + if p.i < len(sel) { + return nil, fmt.Errorf("parsing %q: %d bytes left over", sel, len(sel)-p.i) + } + + return compiled, nil +} + +// MustCompile is like Compile, but panics instead of returning an error. +func MustCompile(sel string) Selector { + compiled, err := Compile(sel) + if err != nil { + panic(err) + } + return compiled +} + +// MatchAll returns a slice of the nodes that match the selector, +// from n and its children. +func (s Selector) MatchAll(n *html.Node) []*html.Node { + return s.matchAllInto(n, nil) +} + +func (s Selector) matchAllInto(n *html.Node, storage []*html.Node) []*html.Node { + if s(n) { + storage = append(storage, n) + } + + for child := n.FirstChild; child != nil; child = child.NextSibling { + storage = s.matchAllInto(child, storage) + } + + return storage +} + +// Match returns true if the node matches the selector. +func (s Selector) Match(n *html.Node) bool { + return s(n) +} + +// MatchFirst returns the first node that matches s, from n and its children. +func (s Selector) MatchFirst(n *html.Node) *html.Node { + if s.Match(n) { + return n + } + + for c := n.FirstChild; c != nil; c = c.NextSibling { + m := s.MatchFirst(c) + if m != nil { + return m + } + } + return nil +} + +// Filter returns the nodes in nodes that match the selector. +func (s Selector) Filter(nodes []*html.Node) (result []*html.Node) { + for _, n := range nodes { + if s(n) { + result = append(result, n) + } + } + return result +} + +// typeSelector returns a Selector that matches elements with a given tag name. +func typeSelector(tag string) Selector { + tag = toLowerASCII(tag) + return func(n *html.Node) bool { + return n.Type == html.ElementNode && n.Data == tag + } +} + +// toLowerASCII returns s with all ASCII capital letters lowercased. +func toLowerASCII(s string) string { + var b []byte + for i := 0; i < len(s); i++ { + if c := s[i]; 'A' <= c && c <= 'Z' { + if b == nil { + b = make([]byte, len(s)) + copy(b, s) + } + b[i] = s[i] + ('a' - 'A') + } + } + + if b == nil { + return s + } + + return string(b) +} + +// attributeSelector returns a Selector that matches elements +// where the attribute named key satisifes the function f. +func attributeSelector(key string, f func(string) bool) Selector { + key = toLowerASCII(key) + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + for _, a := range n.Attr { + if a.Key == key && f(a.Val) { + return true + } + } + return false + } +} + +// attributeExistsSelector returns a Selector that matches elements that have +// an attribute named key. +func attributeExistsSelector(key string) Selector { + return attributeSelector(key, func(string) bool { return true }) +} + +// attributeEqualsSelector returns a Selector that matches elements where +// the attribute named key has the value val. +func attributeEqualsSelector(key, val string) Selector { + return attributeSelector(key, + func(s string) bool { + return s == val + }) +} + +// attributeNotEqualSelector returns a Selector that matches elements where +// the attribute named key does not have the value val. +func attributeNotEqualSelector(key, val string) Selector { + key = toLowerASCII(key) + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + for _, a := range n.Attr { + if a.Key == key && a.Val == val { + return false + } + } + return true + } +} + +// attributeIncludesSelector returns a Selector that matches elements where +// the attribute named key is a whitespace-separated list that includes val. +func attributeIncludesSelector(key, val string) Selector { + return attributeSelector(key, + func(s string) bool { + for s != "" { + i := strings.IndexAny(s, " \t\r\n\f") + if i == -1 { + return s == val + } + if s[:i] == val { + return true + } + s = s[i+1:] + } + return false + }) +} + +// attributeDashmatchSelector returns a Selector that matches elements where +// the attribute named key equals val or starts with val plus a hyphen. +func attributeDashmatchSelector(key, val string) Selector { + return attributeSelector(key, + func(s string) bool { + if s == val { + return true + } + if len(s) <= len(val) { + return false + } + if s[:len(val)] == val && s[len(val)] == '-' { + return true + } + return false + }) +} + +// attributePrefixSelector returns a Selector that matches elements where +// the attribute named key starts with val. +func attributePrefixSelector(key, val string) Selector { + return attributeSelector(key, + func(s string) bool { + if strings.TrimSpace(s) == "" { + return false + } + return strings.HasPrefix(s, val) + }) +} + +// attributeSuffixSelector returns a Selector that matches elements where +// the attribute named key ends with val. +func attributeSuffixSelector(key, val string) Selector { + return attributeSelector(key, + func(s string) bool { + if strings.TrimSpace(s) == "" { + return false + } + return strings.HasSuffix(s, val) + }) +} + +// attributeSubstringSelector returns a Selector that matches nodes where +// the attribute named key contains val. +func attributeSubstringSelector(key, val string) Selector { + return attributeSelector(key, + func(s string) bool { + if strings.TrimSpace(s) == "" { + return false + } + return strings.Contains(s, val) + }) +} + +// attributeRegexSelector returns a Selector that matches nodes where +// the attribute named key matches the regular expression rx +func attributeRegexSelector(key string, rx *regexp.Regexp) Selector { + return attributeSelector(key, + func(s string) bool { + return rx.MatchString(s) + }) +} + +// intersectionSelector returns a selector that matches nodes that match +// both a and b. +func intersectionSelector(a, b Selector) Selector { + return func(n *html.Node) bool { + return a(n) && b(n) + } +} + +// unionSelector returns a selector that matches elements that match +// either a or b. +func unionSelector(a, b Selector) Selector { + return func(n *html.Node) bool { + return a(n) || b(n) + } +} + +// negatedSelector returns a selector that matches elements that do not match a. +func negatedSelector(a Selector) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + return !a(n) + } +} + +// writeNodeText writes the text contained in n and its descendants to b. +func writeNodeText(n *html.Node, b *bytes.Buffer) { + switch n.Type { + case html.TextNode: + b.WriteString(n.Data) + case html.ElementNode: + for c := n.FirstChild; c != nil; c = c.NextSibling { + writeNodeText(c, b) + } + } +} + +// nodeText returns the text contained in n and its descendants. +func nodeText(n *html.Node) string { + var b bytes.Buffer + writeNodeText(n, &b) + return b.String() +} + +// nodeOwnText returns the contents of the text nodes that are direct +// children of n. +func nodeOwnText(n *html.Node) string { + var b bytes.Buffer + for c := n.FirstChild; c != nil; c = c.NextSibling { + if c.Type == html.TextNode { + b.WriteString(c.Data) + } + } + return b.String() +} + +// textSubstrSelector returns a selector that matches nodes that +// contain the given text. +func textSubstrSelector(val string) Selector { + return func(n *html.Node) bool { + text := strings.ToLower(nodeText(n)) + return strings.Contains(text, val) + } +} + +// ownTextSubstrSelector returns a selector that matches nodes that +// directly contain the given text +func ownTextSubstrSelector(val string) Selector { + return func(n *html.Node) bool { + text := strings.ToLower(nodeOwnText(n)) + return strings.Contains(text, val) + } +} + +// textRegexSelector returns a selector that matches nodes whose text matches +// the specified regular expression +func textRegexSelector(rx *regexp.Regexp) Selector { + return func(n *html.Node) bool { + return rx.MatchString(nodeText(n)) + } +} + +// ownTextRegexSelector returns a selector that matches nodes whose text +// directly matches the specified regular expression +func ownTextRegexSelector(rx *regexp.Regexp) Selector { + return func(n *html.Node) bool { + return rx.MatchString(nodeOwnText(n)) + } +} + +// hasChildSelector returns a selector that matches elements +// with a child that matches a. +func hasChildSelector(a Selector) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + return hasChildMatch(n, a) + } +} + +// hasDescendantSelector returns a selector that matches elements +// with any descendant that matches a. +func hasDescendantSelector(a Selector) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + return hasDescendantMatch(n, a) + } +} + +// nthChildSelector returns a selector that implements :nth-child(an+b). +// If last is true, implements :nth-last-child instead. +// If ofType is true, implements :nth-of-type instead. +func nthChildSelector(a, b int, last, ofType bool) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + parent := n.Parent + if parent == nil { + return false + } + + if parent.Type == html.DocumentNode { + return false + } + + i := -1 + count := 0 + for c := parent.FirstChild; c != nil; c = c.NextSibling { + if (c.Type != html.ElementNode) || (ofType && c.Data != n.Data) { + continue + } + count++ + if c == n { + i = count + if !last { + break + } + } + } + + if i == -1 { + // This shouldn't happen, since n should always be one of its parent's children. + return false + } + + if last { + i = count - i + 1 + } + + i -= b + if a == 0 { + return i == 0 + } + + return i%a == 0 && i/a >= 0 + } +} + +// simpleNthChildSelector returns a selector that implements :nth-child(b). +// If ofType is true, implements :nth-of-type instead. +func simpleNthChildSelector(b int, ofType bool) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + parent := n.Parent + if parent == nil { + return false + } + + if parent.Type == html.DocumentNode { + return false + } + + count := 0 + for c := parent.FirstChild; c != nil; c = c.NextSibling { + if c.Type != html.ElementNode || (ofType && c.Data != n.Data) { + continue + } + count++ + if c == n { + return count == b + } + if count >= b { + return false + } + } + return false + } +} + +// simpleNthLastChildSelector returns a selector that implements +// :nth-last-child(b). If ofType is true, implements :nth-last-of-type +// instead. +func simpleNthLastChildSelector(b int, ofType bool) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + parent := n.Parent + if parent == nil { + return false + } + + if parent.Type == html.DocumentNode { + return false + } + + count := 0 + for c := parent.LastChild; c != nil; c = c.PrevSibling { + if c.Type != html.ElementNode || (ofType && c.Data != n.Data) { + continue + } + count++ + if c == n { + return count == b + } + if count >= b { + return false + } + } + return false + } +} + +// onlyChildSelector returns a selector that implements :only-child. +// If ofType is true, it implements :only-of-type instead. +func onlyChildSelector(ofType bool) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + parent := n.Parent + if parent == nil { + return false + } + + if parent.Type == html.DocumentNode { + return false + } + + count := 0 + for c := parent.FirstChild; c != nil; c = c.NextSibling { + if (c.Type != html.ElementNode) || (ofType && c.Data != n.Data) { + continue + } + count++ + if count > 1 { + return false + } + } + + return count == 1 + } +} + +// inputSelector is a Selector that matches input, select, textarea and button elements. +func inputSelector(n *html.Node) bool { + return n.Type == html.ElementNode && (n.Data == "input" || n.Data == "select" || n.Data == "textarea" || n.Data == "button") +} + +// emptyElementSelector is a Selector that matches empty elements. +func emptyElementSelector(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + for c := n.FirstChild; c != nil; c = c.NextSibling { + switch c.Type { + case html.ElementNode, html.TextNode: + return false + } + } + + return true +} + +// descendantSelector returns a Selector that matches an element if +// it matches d and has an ancestor that matches a. +func descendantSelector(a, d Selector) Selector { + return func(n *html.Node) bool { + if !d(n) { + return false + } + + for p := n.Parent; p != nil; p = p.Parent { + if a(p) { + return true + } + } + + return false + } +} + +// childSelector returns a Selector that matches an element if +// it matches d and its parent matches a. +func childSelector(a, d Selector) Selector { + return func(n *html.Node) bool { + return d(n) && n.Parent != nil && a(n.Parent) + } +} + +// siblingSelector returns a Selector that matches an element +// if it matches s2 and in is preceded by an element that matches s1. +// If adjacent is true, the sibling must be immediately before the element. +func siblingSelector(s1, s2 Selector, adjacent bool) Selector { + return func(n *html.Node) bool { + if !s2(n) { + return false + } + + if adjacent { + for n = n.PrevSibling; n != nil; n = n.PrevSibling { + if n.Type == html.TextNode || n.Type == html.CommentNode { + continue + } + return s1(n) + } + return false + } + + // Walk backwards looking for element that matches s1 + for c := n.PrevSibling; c != nil; c = c.PrevSibling { + if s1(c) { + return true + } + } + + return false + } +} + +// rootSelector implements :root +func rootSelector(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + if n.Parent == nil { + return false + } + return n.Parent.Type == html.DocumentNode +} diff --git a/vendor/github.com/andybalholm/cascadia/selector_test.go b/vendor/github.com/andybalholm/cascadia/selector_test.go new file mode 100644 index 0000000..7ff77e6 --- /dev/null +++ b/vendor/github.com/andybalholm/cascadia/selector_test.go @@ -0,0 +1,654 @@ +package cascadia + +import ( + "bytes" + "strings" + "testing" + + "golang.org/x/net/html" +) + +type selectorTest struct { + HTML, selector string + results []string +} + +func nodeString(n *html.Node) string { + buf := bytes.NewBufferString("") + html.Render(buf, n) + return buf.String() +} + +var selectorTests = []selectorTest{ + { + `
This address...
`, + "address", + []string{ + "
This address...
", + }, + }, + { + `text`, + "*", + []string{ + "text", + "", + "text", + }, + }, + { + ``, + "*", + []string{ + "", + "", + "", + }, + }, + { + `

`, + "#foo", + []string{ + `

`, + }, + }, + { + ` +#errors +Line: 1 Col: 7 Unexpected start tag (table). Expected DOCTYPE. +Line: 1 Col: 20 Unexpected end tag (strong) in table context caused voodoo mode. +Line: 1 Col: 20 End tag (strong) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 24 Unexpected end tag (b) in table context caused voodoo mode. +Line: 1 Col: 24 End tag (b) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 29 Unexpected end tag (em) in table context caused voodoo mode. +Line: 1 Col: 29 End tag (em) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 33 Unexpected end tag (i) in table context caused voodoo mode. +Line: 1 Col: 33 End tag (i) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 37 Unexpected end tag (u) in table context caused voodoo mode. +Line: 1 Col: 37 End tag (u) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 46 Unexpected end tag (strike) in table context caused voodoo mode. +Line: 1 Col: 46 End tag (strike) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 50 Unexpected end tag (s) in table context caused voodoo mode. +Line: 1 Col: 50 End tag (s) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 58 Unexpected end tag (blink) in table context caused voodoo mode. +Line: 1 Col: 58 Unexpected end tag (blink). Ignored. +Line: 1 Col: 63 Unexpected end tag (tt) in table context caused voodoo mode. +Line: 1 Col: 63 End tag (tt) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 69 Unexpected end tag (pre) in table context caused voodoo mode. +Line: 1 Col: 69 End tag (pre) seen too early. Expected other end tag. +Line: 1 Col: 75 Unexpected end tag (big) in table context caused voodoo mode. +Line: 1 Col: 75 End tag (big) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 83 Unexpected end tag (small) in table context caused voodoo mode. +Line: 1 Col: 83 End tag (small) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 90 Unexpected end tag (font) in table context caused voodoo mode. +Line: 1 Col: 90 End tag (font) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 99 Unexpected end tag (select) in table context caused voodoo mode. +Line: 1 Col: 99 Unexpected end tag (select). Ignored. +Line: 1 Col: 104 Unexpected end tag (h1) in table context caused voodoo mode. +Line: 1 Col: 104 End tag (h1) seen too early. Expected other end tag. +Line: 1 Col: 109 Unexpected end tag (h2) in table context caused voodoo mode. +Line: 1 Col: 109 End tag (h2) seen too early. Expected other end tag. +Line: 1 Col: 114 Unexpected end tag (h3) in table context caused voodoo mode. +Line: 1 Col: 114 End tag (h3) seen too early. Expected other end tag. +Line: 1 Col: 119 Unexpected end tag (h4) in table context caused voodoo mode. +Line: 1 Col: 119 End tag (h4) seen too early. Expected other end tag. +Line: 1 Col: 124 Unexpected end tag (h5) in table context caused voodoo mode. +Line: 1 Col: 124 End tag (h5) seen too early. Expected other end tag. +Line: 1 Col: 129 Unexpected end tag (h6) in table context caused voodoo mode. +Line: 1 Col: 129 End tag (h6) seen too early. Expected other end tag. +Line: 1 Col: 136 Unexpected end tag (body) in the table row phase. Ignored. +Line: 1 Col: 141 Unexpected end tag (br) in table context caused voodoo mode. +Line: 1 Col: 141 Unexpected end tag (br). Treated as br element. +Line: 1 Col: 145 Unexpected end tag (a) in table context caused voodoo mode. +Line: 1 Col: 145 End tag (a) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 151 Unexpected end tag (img) in table context caused voodoo mode. +Line: 1 Col: 151 This element (img) has no end tag. +Line: 1 Col: 159 Unexpected end tag (title) in table context caused voodoo mode. +Line: 1 Col: 159 Unexpected end tag (title). Ignored. +Line: 1 Col: 166 Unexpected end tag (span) in table context caused voodoo mode. +Line: 1 Col: 166 Unexpected end tag (span). Ignored. +Line: 1 Col: 174 Unexpected end tag (style) in table context caused voodoo mode. +Line: 1 Col: 174 Unexpected end tag (style). Ignored. +Line: 1 Col: 183 Unexpected end tag (script) in table context caused voodoo mode. +Line: 1 Col: 183 Unexpected end tag (script). Ignored. +Line: 1 Col: 196 Unexpected end tag (th). Ignored. +Line: 1 Col: 201 Unexpected end tag (td). Ignored. +Line: 1 Col: 206 Unexpected end tag (tr). Ignored. +Line: 1 Col: 214 This element (frame) has no end tag. +Line: 1 Col: 221 This element (area) has no end tag. +Line: 1 Col: 228 Unexpected end tag (link). Ignored. +Line: 1 Col: 236 This element (param) has no end tag. +Line: 1 Col: 241 This element (hr) has no end tag. +Line: 1 Col: 249 This element (input) has no end tag. +Line: 1 Col: 255 Unexpected end tag (col). Ignored. +Line: 1 Col: 262 Unexpected end tag (base). Ignored. +Line: 1 Col: 269 Unexpected end tag (meta). Ignored. +Line: 1 Col: 280 This element (basefont) has no end tag. +Line: 1 Col: 290 This element (bgsound) has no end tag. +Line: 1 Col: 298 This element (embed) has no end tag. +Line: 1 Col: 307 This element (spacer) has no end tag. +Line: 1 Col: 311 Unexpected end tag (p). Ignored. +Line: 1 Col: 316 End tag (dd) seen too early. Expected other end tag. +Line: 1 Col: 321 End tag (dt) seen too early. Expected other end tag. +Line: 1 Col: 331 Unexpected end tag (caption). Ignored. +Line: 1 Col: 342 Unexpected end tag (colgroup). Ignored. +Line: 1 Col: 350 Unexpected end tag (tbody). Ignored. +Line: 1 Col: 358 Unexpected end tag (tfoot). Ignored. +Line: 1 Col: 366 Unexpected end tag (thead). Ignored. +Line: 1 Col: 376 End tag (address) seen too early. Expected other end tag. +Line: 1 Col: 389 End tag (blockquote) seen too early. Expected other end tag. +Line: 1 Col: 398 End tag (center) seen too early. Expected other end tag. +Line: 1 Col: 404 Unexpected end tag (dir). Ignored. +Line: 1 Col: 410 End tag (div) seen too early. Expected other end tag. +Line: 1 Col: 415 End tag (dl) seen too early. Expected other end tag. +Line: 1 Col: 426 End tag (fieldset) seen too early. Expected other end tag. +Line: 1 Col: 436 End tag (listing) seen too early. Expected other end tag. +Line: 1 Col: 443 End tag (menu) seen too early. Expected other end tag. +Line: 1 Col: 448 End tag (ol) seen too early. Expected other end tag. +Line: 1 Col: 453 End tag (ul) seen too early. Expected other end tag. +Line: 1 Col: 458 End tag (li) seen too early. Expected other end tag. +Line: 1 Col: 465 End tag (nobr) violates step 1, paragraph 1 of the adoption agency algorithm. +Line: 1 Col: 471 This element (wbr) has no end tag. +Line: 1 Col: 487 End tag (button) seen too early. Expected other end tag. +Line: 1 Col: 497 End tag (marquee) seen too early. Expected other end tag. +Line: 1 Col: 506 End tag (object) seen too early. Expected other end tag. +Line: 1 Col: 524 Unexpected end tag (html). Ignored. +Line: 1 Col: 524 Unexpected end tag (frameset). Ignored. +Line: 1 Col: 531 Unexpected end tag (head). Ignored. +Line: 1 Col: 540 Unexpected end tag (iframe). Ignored. +Line: 1 Col: 548 This element (image) has no end tag. +Line: 1 Col: 558 This element (isindex) has no end tag. +Line: 1 Col: 568 Unexpected end tag (noembed). Ignored. +Line: 1 Col: 579 Unexpected end tag (noframes). Ignored. +Line: 1 Col: 590 Unexpected end tag (noscript). Ignored. +Line: 1 Col: 601 Unexpected end tag (optgroup). Ignored. +Line: 1 Col: 610 Unexpected end tag (option). Ignored. +Line: 1 Col: 622 Unexpected end tag (plaintext). Ignored. +Line: 1 Col: 633 Unexpected end tag (textarea). Ignored. +#document +| +| +| +|
+| +| +| +|

+ +#data + +#errors +Line: 1 Col: 10 Unexpected start tag (frameset). Expected DOCTYPE. +Line: 1 Col: 10 Expected closing tag. Unexpected end of file. +#document +| +| +| diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests10.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests10.dat new file mode 100644 index 0000000..4f8df86 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests10.dat @@ -0,0 +1,799 @@ +#data + +#errors +#document +| +| +| +| +| + +#data +a +#errors +29: Bogus comment +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| + +#data + +#errors +35: Stray “svg†start tag. +42: Stray end tag “svg†+#document +| +| +| +| +| +#errors +43: Stray “svg†start tag. +50: Stray end tag “svg†+#document +| +| +| +| +|

+#errors +34: Start tag “svg†seen in “tableâ€. +41: Stray end tag “svgâ€. +#document +| +| +| +| +| +| + +#data +
foo
+#errors +34: Start tag “svg†seen in “tableâ€. +46: Stray end tag “gâ€. +53: Stray end tag “svgâ€. +#document +| +| +| +| +| +| +| "foo" +| + +#data +
foobar
+#errors +34: Start tag “svg†seen in “tableâ€. +46: Stray end tag “gâ€. +58: Stray end tag “gâ€. +65: Stray end tag “svgâ€. +#document +| +| +| +| +| +| +| "foo" +| +| "bar" +| + +#data +
foobar
+#errors +41: Start tag “svg†seen in “tableâ€. +53: Stray end tag “gâ€. +65: Stray end tag “gâ€. +72: Stray end tag “svgâ€. +#document +| +| +| +| +| +| +| "foo" +| +| "bar" +| +| + +#data +
foobar
+#errors +45: Start tag “svg†seen in “tableâ€. +57: Stray end tag “gâ€. +69: Stray end tag “gâ€. +76: Stray end tag “svgâ€. +#document +| +| +| +| +| +| +| "foo" +| +| "bar" +| +| +| + +#data +
foobar
+#errors +#document +| +| +| +| +| +| +| +|
+| +| +| "foo" +| +| "bar" + +#data +
foobar

baz

+#errors +#document +| +| +| +| +| +| +| +|
+| +| +| "foo" +| +| "bar" +|

+| "baz" + +#data +
foobar

baz

+#errors +#document +| +| +| +| +| +|
+| +| +| "foo" +| +| "bar" +|

+| "baz" + +#data +
foobar

baz

quux +#errors +70: HTML start tag “p†in a foreign namespace context. +81: “table†closed but “caption†was still open. +#document +| +| +| +| +| +|
+| +| +| "foo" +| +| "bar" +|

+| "baz" +|

+| "quux" + +#data +
foobarbaz

quux +#errors +78: “table†closed but “caption†was still open. +78: Unclosed elements on stack. +#document +| +| +| +| +| +|
+| +| +| "foo" +| +| "bar" +| "baz" +|

+| "quux" + +#data +foobar

baz

quux +#errors +44: Start tag “svg†seen in “tableâ€. +56: Stray end tag “gâ€. +68: Stray end tag “gâ€. +71: HTML start tag “p†in a foreign namespace context. +71: Start tag “p†seen in “tableâ€. +#document +| +| +| +| +| +| +| "foo" +| +| "bar" +|

+| "baz" +| +| +|

+| "quux" + +#data +

quux +#errors +50: Stray “svg†start tag. +54: Stray “g†start tag. +62: Stray end tag “g†+66: Stray “g†start tag. +74: Stray end tag “g†+77: Stray “p†start tag. +88: “table†end tag with “select†open. +#document +| +| +| +| +| +| +| +|
+|

quux +#errors +36: Start tag “select†seen in “tableâ€. +42: Stray “svg†start tag. +46: Stray “g†start tag. +54: Stray end tag “g†+58: Stray “g†start tag. +66: Stray end tag “g†+69: Stray “p†start tag. +80: “table†end tag with “select†open. +#document +| +| +| +| +| +|

+| "quux" + +#data +foobar

baz +#errors +41: Stray “svg†start tag. +68: HTML start tag “p†in a foreign namespace context. +#document +| +| +| +| +| +| +| "foo" +| +| "bar" +|

+| "baz" + +#data +foobar

baz +#errors +34: Stray “svg†start tag. +61: HTML start tag “p†in a foreign namespace context. +#document +| +| +| +| +| +| +| "foo" +| +| "bar" +|

+| "baz" + +#data +

+#errors +31: Stray “svg†start tag. +35: Stray “g†start tag. +40: Stray end tag “g†+44: Stray “g†start tag. +49: Stray end tag “g†+52: Stray “p†start tag. +58: Stray “span†start tag. +58: End of file seen and there were open elements. +#document +| +| +| +| + +#data +

+#errors +42: Stray “svg†start tag. +46: Stray “g†start tag. +51: Stray end tag “g†+55: Stray “g†start tag. +60: Stray end tag “g†+63: Stray “p†start tag. +69: Stray “span†start tag. +#document +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| xlink:href="foo" +| +| xlink href="foo" + +#data + +#errors +#document +| +| +| +| +| xlink:href="foo" +| xml:lang="en" +| +| +| xlink href="foo" +| xml lang="en" + +#data + +#errors +#document +| +| +| +| +| xlink:href="foo" +| xml:lang="en" +| +| +| xlink href="foo" +| xml lang="en" + +#data +bar +#errors +#document +| +| +| +| +| xlink:href="foo" +| xml:lang="en" +| +| +| xlink href="foo" +| xml lang="en" +| "bar" + +#data + +#errors +#document +| +| +| +| + +#data +

a +#errors +#document +| +| +| +|
+| +| "a" + +#data +
a +#errors +#document +| +| +| +|
+| +| +| "a" + +#data +
+#errors +#document +| +| +| +|
+| +| +| + +#data +
a +#errors +#document +| +| +| +|
+| +| +| +| +| "a" + +#data +

a +#errors +#document +| +| +| +|

+| +| +| +|

+| "a" + +#data +
    a +#errors +40: HTML start tag “ul†in a foreign namespace context. +41: End of file in a foreign namespace context. +#document +| +| +| +| +| +| +|
    +| +|
      +| "a" + +#data +
        a +#errors +35: HTML start tag “ul†in a foreign namespace context. +36: End of file in a foreign namespace context. +#document +| +| +| +| +| +| +| +|
          +| "a" + +#data +

          +#errors +#document +| +| +| +| +|

          +| +| +|

          + +#data +

          +#errors +#document +| +| +| +| +|

          +| +| +|

          + +#data +

          +#errors +#document +| +| +| +|

          +| +| +| +|

          +|

          + +#data +
          +#errors +#document +| +| +| +| +| +|
          +| +|
          +| +| + +#data +
          +#errors +#document +| +| +| +| +| +| +| +|
          +|
          +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data +

+#errors +#document +| +| +| +| +|
+| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| +| + +#data +
+#errors +#document +| +| +| +| +| +| +| +|
+| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| +| +| +| +| +| +| +| +| diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests11.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests11.dat new file mode 100644 index 0000000..638cde4 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests11.dat @@ -0,0 +1,482 @@ +#data + +#errors +#document +| +| +| +| +| +| attributeName="" +| attributeType="" +| baseFrequency="" +| baseProfile="" +| calcMode="" +| clipPathUnits="" +| contentScriptType="" +| contentStyleType="" +| diffuseConstant="" +| edgeMode="" +| externalResourcesRequired="" +| filterRes="" +| filterUnits="" +| glyphRef="" +| gradientTransform="" +| gradientUnits="" +| kernelMatrix="" +| kernelUnitLength="" +| keyPoints="" +| keySplines="" +| keyTimes="" +| lengthAdjust="" +| limitingConeAngle="" +| markerHeight="" +| markerUnits="" +| markerWidth="" +| maskContentUnits="" +| maskUnits="" +| numOctaves="" +| pathLength="" +| patternContentUnits="" +| patternTransform="" +| patternUnits="" +| pointsAtX="" +| pointsAtY="" +| pointsAtZ="" +| preserveAlpha="" +| preserveAspectRatio="" +| primitiveUnits="" +| refX="" +| refY="" +| repeatCount="" +| repeatDur="" +| requiredExtensions="" +| requiredFeatures="" +| specularConstant="" +| specularExponent="" +| spreadMethod="" +| startOffset="" +| stdDeviation="" +| stitchTiles="" +| surfaceScale="" +| systemLanguage="" +| tableValues="" +| targetX="" +| targetY="" +| textLength="" +| viewBox="" +| viewTarget="" +| xChannelSelector="" +| yChannelSelector="" +| zoomAndPan="" + +#data + +#errors +#document +| +| +| +| +| +| attributeName="" +| attributeType="" +| baseFrequency="" +| baseProfile="" +| calcMode="" +| clipPathUnits="" +| contentScriptType="" +| contentStyleType="" +| diffuseConstant="" +| edgeMode="" +| externalResourcesRequired="" +| filterRes="" +| filterUnits="" +| glyphRef="" +| gradientTransform="" +| gradientUnits="" +| kernelMatrix="" +| kernelUnitLength="" +| keyPoints="" +| keySplines="" +| keyTimes="" +| lengthAdjust="" +| limitingConeAngle="" +| markerHeight="" +| markerUnits="" +| markerWidth="" +| maskContentUnits="" +| maskUnits="" +| numOctaves="" +| pathLength="" +| patternContentUnits="" +| patternTransform="" +| patternUnits="" +| pointsAtX="" +| pointsAtY="" +| pointsAtZ="" +| preserveAlpha="" +| preserveAspectRatio="" +| primitiveUnits="" +| refX="" +| refY="" +| repeatCount="" +| repeatDur="" +| requiredExtensions="" +| requiredFeatures="" +| specularConstant="" +| specularExponent="" +| spreadMethod="" +| startOffset="" +| stdDeviation="" +| stitchTiles="" +| surfaceScale="" +| systemLanguage="" +| tableValues="" +| targetX="" +| targetY="" +| textLength="" +| viewBox="" +| viewTarget="" +| xChannelSelector="" +| yChannelSelector="" +| zoomAndPan="" + +#data + +#errors +#document +| +| +| +| +| +| attributeName="" +| attributeType="" +| baseFrequency="" +| baseProfile="" +| calcMode="" +| clipPathUnits="" +| contentScriptType="" +| contentStyleType="" +| diffuseConstant="" +| edgeMode="" +| externalResourcesRequired="" +| filterRes="" +| filterUnits="" +| glyphRef="" +| gradientTransform="" +| gradientUnits="" +| kernelMatrix="" +| kernelUnitLength="" +| keyPoints="" +| keySplines="" +| keyTimes="" +| lengthAdjust="" +| limitingConeAngle="" +| markerHeight="" +| markerUnits="" +| markerWidth="" +| maskContentUnits="" +| maskUnits="" +| numOctaves="" +| pathLength="" +| patternContentUnits="" +| patternTransform="" +| patternUnits="" +| pointsAtX="" +| pointsAtY="" +| pointsAtZ="" +| preserveAlpha="" +| preserveAspectRatio="" +| primitiveUnits="" +| refX="" +| refY="" +| repeatCount="" +| repeatDur="" +| requiredExtensions="" +| requiredFeatures="" +| specularConstant="" +| specularExponent="" +| spreadMethod="" +| startOffset="" +| stdDeviation="" +| stitchTiles="" +| surfaceScale="" +| systemLanguage="" +| tableValues="" +| targetX="" +| targetY="" +| textLength="" +| viewBox="" +| viewTarget="" +| xChannelSelector="" +| yChannelSelector="" +| zoomAndPan="" + +#data + +#errors +#document +| +| +| +| +| +| attributename="" +| attributetype="" +| basefrequency="" +| baseprofile="" +| calcmode="" +| clippathunits="" +| contentscripttype="" +| contentstyletype="" +| diffuseconstant="" +| edgemode="" +| externalresourcesrequired="" +| filterres="" +| filterunits="" +| glyphref="" +| gradienttransform="" +| gradientunits="" +| kernelmatrix="" +| kernelunitlength="" +| keypoints="" +| keysplines="" +| keytimes="" +| lengthadjust="" +| limitingconeangle="" +| markerheight="" +| markerunits="" +| markerwidth="" +| maskcontentunits="" +| maskunits="" +| numoctaves="" +| pathlength="" +| patterncontentunits="" +| patterntransform="" +| patternunits="" +| pointsatx="" +| pointsaty="" +| pointsatz="" +| preservealpha="" +| preserveaspectratio="" +| primitiveunits="" +| refx="" +| refy="" +| repeatcount="" +| repeatdur="" +| requiredextensions="" +| requiredfeatures="" +| specularconstant="" +| specularexponent="" +| spreadmethod="" +| startoffset="" +| stddeviation="" +| stitchtiles="" +| surfacescale="" +| systemlanguage="" +| tablevalues="" +| targetx="" +| targety="" +| textlength="" +| viewbox="" +| viewtarget="" +| xchannelselector="" +| ychannelselector="" +| zoomandpan="" + +#data + +#errors +#document +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests12.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests12.dat new file mode 100644 index 0000000..63107d2 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests12.dat @@ -0,0 +1,62 @@ +#data +

foobazeggs

spam

quuxbar +#errors +#document +| +| +| +| +|

+| "foo" +| +| +| +| "baz" +| +| +| +| +| "eggs" +| +| +|

+| "spam" +| +| +| +|
+| +| +| "quux" +| "bar" + +#data +foobazeggs

spam
quuxbar +#errors +#document +| +| +| +| +| "foo" +| +| +| +| "baz" +| +| +| +| +| "eggs" +| +| +|

+| "spam" +| +| +| +|
+| +| +| "quux" +| "bar" diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests14.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests14.dat new file mode 100644 index 0000000..b8713f8 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests14.dat @@ -0,0 +1,74 @@ +#data + +#errors +#document +| +| +| +| +| + +#data + +#errors +#document +| +| +| +| +| +| + +#data + +#errors +15: Unexpected start tag html +#document +| +| +| abc:def="gh" +| +| +| + +#data + +#errors +15: Unexpected start tag html +#document +| +| +| xml:lang="bar" +| +| + +#data + +#errors +#document +| +| +| 123="456" +| +| + +#data + +#errors +#document +| +| +| 123="456" +| 789="012" +| +| + +#data + +#errors +#document +| +| +| +| +| 789="012" diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests15.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests15.dat new file mode 100644 index 0000000..6ce1c0d --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests15.dat @@ -0,0 +1,208 @@ +#data +

X +#errors +Line: 1 Col: 31 Unexpected end tag (p). Ignored. +Line: 1 Col: 36 Expected closing tag. Unexpected end of file. +#document +| +| +| +| +|

+| +| +| +| +| +| +| " " +|

+| "X" + +#data +

+

X +#errors +Line: 1 Col: 3 Unexpected start tag (p). Expected DOCTYPE. +Line: 1 Col: 16 Unexpected end tag (p). Ignored. +Line: 2 Col: 4 Expected closing tag. Unexpected end of file. +#document +| +| +| +|

+| +| +| +| +| +| +| " +" +|

+| "X" + +#data + +#errors +Line: 1 Col: 22 Unexpected end tag (html) after the (implied) root element. +#document +| +| +| +| +| " " + +#data + +#errors +Line: 1 Col: 22 Unexpected end tag (body) after the (implied) root element. +#document +| +| +| +| +| + +#data + +#errors +Line: 1 Col: 6 Unexpected start tag (html). Expected DOCTYPE. +Line: 1 Col: 13 Unexpected end tag (html) after the (implied) root element. +#document +| +| +| +| + +#data +X +#errors +Line: 1 Col: 22 Unexpected end tag (body) after the (implied) root element. +#document +| +| +| +| +| +| "X" + +#data +<!doctype html><table> X<meta></table> +#errors +Line: 1 Col: 24 Unexpected non-space characters in table context caused voodoo mode. +Line: 1 Col: 30 Unexpected start tag (meta) in table context caused voodoo mode. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| " X" +| <meta> +| <table> + +#data +<!doctype html><table> x</table> +#errors +Line: 1 Col: 24 Unexpected non-space characters in table context caused voodoo mode. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| " x" +| <table> + +#data +<!doctype html><table> x </table> +#errors +Line: 1 Col: 25 Unexpected non-space characters in table context caused voodoo mode. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| " x " +| <table> + +#data +<!doctype html><table><tr> x</table> +#errors +Line: 1 Col: 28 Unexpected non-space characters in table context caused voodoo mode. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| " x" +| <table> +| <tbody> +| <tr> + +#data +<!doctype html><table>X<style> <tr>x </style> </table> +#errors +Line: 1 Col: 23 Unexpected non-space characters in table context caused voodoo mode. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "X" +| <table> +| <style> +| " <tr>x " +| " " + +#data +<!doctype html><div><table><a>foo</a> <tr><td>bar</td> </tr></table></div> +#errors +Line: 1 Col: 30 Unexpected start tag (a) in table context caused voodoo mode. +Line: 1 Col: 37 Unexpected end tag (a) in table context caused voodoo mode. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <div> +| <a> +| "foo" +| <table> +| " " +| <tbody> +| <tr> +| <td> +| "bar" +| " " + +#data +<frame></frame></frame><frameset><frame><frameset><frame></frameset><noframes></frameset><noframes> +#errors +6: Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>â€. +13: Stray start tag “frameâ€. +21: Stray end tag “frameâ€. +29: Stray end tag “frameâ€. +39: “frameset†start tag after “body†already open. +105: End of file seen inside an [R]CDATA element. +105: End of file seen and there were open elements. +XXX: These errors are wrong, please fix me! +#document +| <html> +| <head> +| <frameset> +| <frame> +| <frameset> +| <frame> +| <noframes> +| "</frameset><noframes>" + +#data +<!DOCTYPE html><object></html> +#errors +1: Expected closing tag. Unexpected end of file +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <object> diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests16.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests16.dat new file mode 100644 index 0000000..c8ef66f --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests16.dat @@ -0,0 +1,2299 @@ +#data +<!doctype html><script> +#errors +Line: 1 Col: 23 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| <body> + +#data +<!doctype html><script>a +#errors +Line: 1 Col: 24 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "a" +| <body> + +#data +<!doctype html><script>< +#errors +Line: 1 Col: 24 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<" +| <body> + +#data +<!doctype html><script></ +#errors +Line: 1 Col: 25 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</" +| <body> + +#data +<!doctype html><script></S +#errors +Line: 1 Col: 26 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</S" +| <body> + +#data +<!doctype html><script></SC +#errors +Line: 1 Col: 27 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</SC" +| <body> + +#data +<!doctype html><script></SCR +#errors +Line: 1 Col: 28 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</SCR" +| <body> + +#data +<!doctype html><script></SCRI +#errors +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</SCRI" +| <body> + +#data +<!doctype html><script></SCRIP +#errors +Line: 1 Col: 30 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</SCRIP" +| <body> + +#data +<!doctype html><script></SCRIPT +#errors +Line: 1 Col: 31 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</SCRIPT" +| <body> + +#data +<!doctype html><script></SCRIPT +#errors +Line: 1 Col: 32 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| <body> + +#data +<!doctype html><script></s +#errors +Line: 1 Col: 26 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</s" +| <body> + +#data +<!doctype html><script></sc +#errors +Line: 1 Col: 27 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</sc" +| <body> + +#data +<!doctype html><script></scr +#errors +Line: 1 Col: 28 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</scr" +| <body> + +#data +<!doctype html><script></scri +#errors +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</scri" +| <body> + +#data +<!doctype html><script></scrip +#errors +Line: 1 Col: 30 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</scrip" +| <body> + +#data +<!doctype html><script></script +#errors +Line: 1 Col: 31 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "</script" +| <body> + +#data +<!doctype html><script></script +#errors +Line: 1 Col: 32 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| <body> + +#data +<!doctype html><script><! +#errors +Line: 1 Col: 25 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!" +| <body> + +#data +<!doctype html><script><!a +#errors +Line: 1 Col: 26 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!a" +| <body> + +#data +<!doctype html><script><!- +#errors +Line: 1 Col: 26 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!-" +| <body> + +#data +<!doctype html><script><!-a +#errors +Line: 1 Col: 27 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!-a" +| <body> + +#data +<!doctype html><script><!-- +#errors +Line: 1 Col: 27 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--" +| <body> + +#data +<!doctype html><script><!--a +#errors +Line: 1 Col: 28 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--a" +| <body> + +#data +<!doctype html><script><!--< +#errors +Line: 1 Col: 28 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<" +| <body> + +#data +<!doctype html><script><!--<a +#errors +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<a" +| <body> + +#data +<!doctype html><script><!--</ +#errors +Line: 1 Col: 27 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--</" +| <body> + +#data +<!doctype html><script><!--</script +#errors +Line: 1 Col: 35 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--</script" +| <body> + +#data +<!doctype html><script><!--</script +#errors +Line: 1 Col: 36 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--" +| <body> + +#data +<!doctype html><script><!--<s +#errors +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<s" +| <body> + +#data +<!doctype html><script><!--<script +#errors +Line: 1 Col: 34 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script" +| <body> + +#data +<!doctype html><script><!--<script +#errors +Line: 1 Col: 35 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script " +| <body> + +#data +<!doctype html><script><!--<script < +#errors +Line: 1 Col: 36 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script <" +| <body> + +#data +<!doctype html><script><!--<script <a +#errors +Line: 1 Col: 37 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script <a" +| <body> + +#data +<!doctype html><script><!--<script </ +#errors +Line: 1 Col: 37 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </" +| <body> + +#data +<!doctype html><script><!--<script </s +#errors +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </s" +| <body> + +#data +<!doctype html><script><!--<script </script +#errors +Line: 1 Col: 43 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script" +| <body> + +#data +<!doctype html><script><!--<script </scripta +#errors +Line: 1 Col: 44 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </scripta" +| <body> + +#data +<!doctype html><script><!--<script </script +#errors +Line: 1 Col: 44 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<!doctype html><script><!--<script </script> +#errors +Line: 1 Col: 44 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script>" +| <body> + +#data +<!doctype html><script><!--<script </script/ +#errors +Line: 1 Col: 44 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script/" +| <body> + +#data +<!doctype html><script><!--<script </script < +#errors +Line: 1 Col: 45 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script <" +| <body> + +#data +<!doctype html><script><!--<script </script <a +#errors +Line: 1 Col: 46 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script <a" +| <body> + +#data +<!doctype html><script><!--<script </script </ +#errors +Line: 1 Col: 46 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script </" +| <body> + +#data +<!doctype html><script><!--<script </script </script +#errors +Line: 1 Col: 52 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script </script" +| <body> + +#data +<!doctype html><script><!--<script </script </script +#errors +Line: 1 Col: 53 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<!doctype html><script><!--<script </script </script/ +#errors +Line: 1 Col: 53 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<!doctype html><script><!--<script </script </script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<!doctype html><script><!--<script - +#errors +Line: 1 Col: 36 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -" +| <body> + +#data +<!doctype html><script><!--<script -a +#errors +Line: 1 Col: 37 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -a" +| <body> + +#data +<!doctype html><script><!--<script -< +#errors +Line: 1 Col: 37 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -<" +| <body> + +#data +<!doctype html><script><!--<script -- +#errors +Line: 1 Col: 37 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script --" +| <body> + +#data +<!doctype html><script><!--<script --a +#errors +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script --a" +| <body> + +#data +<!doctype html><script><!--<script --< +#errors +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script --<" +| <body> + +#data +<!doctype html><script><!--<script --> +#errors +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<!doctype html><script><!--<script -->< +#errors +Line: 1 Col: 39 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script --><" +| <body> + +#data +<!doctype html><script><!--<script --></ +#errors +Line: 1 Col: 40 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script --></" +| <body> + +#data +<!doctype html><script><!--<script --></script +#errors +Line: 1 Col: 46 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script --></script" +| <body> + +#data +<!doctype html><script><!--<script --></script +#errors +Line: 1 Col: 47 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<!doctype html><script><!--<script --></script/ +#errors +Line: 1 Col: 47 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<!doctype html><script><!--<script --></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<!doctype html><script><!--<script><\/script>--></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script><\/script>-->" +| <body> + +#data +<!doctype html><script><!--<script></scr'+'ipt>--></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></scr'+'ipt>-->" +| <body> + +#data +<!doctype html><script><!--<script></script><script></script></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>" +| <body> + +#data +<!doctype html><script><!--<script></script><script></script>--><!--</script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>--><!--" +| <body> + +#data +<!doctype html><script><!--<script></script><script></script>-- ></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>-- >" +| <body> + +#data +<!doctype html><script><!--<script></script><script></script>- -></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>- ->" +| <body> + +#data +<!doctype html><script><!--<script></script><script></script>- - ></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>- - >" +| <body> + +#data +<!doctype html><script><!--<script></script><script></script>-></script> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>->" +| <body> + +#data +<!doctype html><script><!--<script>--!></script>X +#errors +Line: 1 Col: 49 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script>--!></script>X" +| <body> + +#data +<!doctype html><script><!--<scr'+'ipt></script>--></script> +#errors +Line: 1 Col: 59 Unexpected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<scr'+'ipt>" +| <body> +| "-->" + +#data +<!doctype html><script><!--<script></scr'+'ipt></script>X +#errors +Line: 1 Col: 57 Unexpected end of file. Expected end tag (script). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| "<!--<script></scr'+'ipt></script>X" +| <body> + +#data +<!doctype html><style><!--<style></style>--></style> +#errors +Line: 1 Col: 52 Unexpected end tag (style). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "<!--<style>" +| <body> +| "-->" + +#data +<!doctype html><style><!--</style>X +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "<!--" +| <body> +| "X" + +#data +<!doctype html><style><!--...</style>...--></style> +#errors +Line: 1 Col: 51 Unexpected end tag (style). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "<!--..." +| <body> +| "...-->" + +#data +<!doctype html><style><!--<br><html xmlns:v="urn:schemas-microsoft-com:vml"><!--[if !mso]><style></style>X +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "<!--<br><html xmlns:v="urn:schemas-microsoft-com:vml"><!--[if !mso]><style>" +| <body> +| "X" + +#data +<!doctype html><style><!--...<style><!--...--!></style>--></style> +#errors +Line: 1 Col: 66 Unexpected end tag (style). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "<!--...<style><!--...--!>" +| <body> +| "-->" + +#data +<!doctype html><style><!--...</style><!-- --><style>@import ...</style> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "<!--..." +| <!-- --> +| <style> +| "@import ..." +| <body> + +#data +<!doctype html><style>...<style><!--...</style><!-- --></style> +#errors +Line: 1 Col: 63 Unexpected end tag (style). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "...<style><!--..." +| <!-- --> +| <body> + +#data +<!doctype html><style>...<!--[if IE]><style>...</style>X +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <style> +| "...<!--[if IE]><style>..." +| <body> +| "X" + +#data +<!doctype html><title><!--<title>--> +#errors +Line: 1 Col: 52 Unexpected end tag (title). +#document +| +| +| +| +| "<!--<title>" +| <body> +| "-->" + +#data +<!doctype html><title></title> +#errors +#document +| +| +| +| +| "" +| + +#data +foo/title><link></head><body>X +#errors +Line: 1 Col: 52 Unexpected end of file. Expected end tag (title). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <title> +| "foo/title><link></head><body>X" +| <body> + +#data +<!doctype html><noscript><!--<noscript></noscript>--></noscript> +#errors +Line: 1 Col: 64 Unexpected end tag (noscript). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <noscript> +| "<!--<noscript>" +| <body> +| "-->" + +#data +<!doctype html><noscript><!--</noscript>X<noscript>--></noscript> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <noscript> +| "<!--" +| <body> +| "X" +| <noscript> +| "-->" + +#data +<!doctype html><noscript><iframe></noscript>X +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <noscript> +| "<iframe>" +| <body> +| "X" + +#data +<!doctype html><noframes><!--<noframes></noframes>--></noframes> +#errors +Line: 1 Col: 64 Unexpected end tag (noframes). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <noframes> +| "<!--<noframes>" +| <body> +| "-->" + +#data +<!doctype html><noframes><body><script><!--...</script></body></noframes></html> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <noframes> +| "<body><script><!--...</script></body>" +| <body> + +#data +<!doctype html><textarea><!--<textarea></textarea>--></textarea> +#errors +Line: 1 Col: 64 Unexpected end tag (textarea). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <textarea> +| "<!--<textarea>" +| "-->" + +#data +<!doctype html><textarea></textarea></textarea> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <textarea> +| "</textarea>" + +#data +<!doctype html><textarea><</textarea> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <textarea> +| "<" + +#data +<!doctype html><textarea>a<b</textarea> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <textarea> +| "a<b" + +#data +<!doctype html><iframe><!--<iframe></iframe>--></iframe> +#errors +Line: 1 Col: 56 Unexpected end tag (iframe). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <iframe> +| "<!--<iframe>" +| "-->" + +#data +<!doctype html><iframe>...<!--X->...<!--/X->...</iframe> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <iframe> +| "...<!--X->...<!--/X->..." + +#data +<!doctype html><xmp><!--<xmp></xmp>--></xmp> +#errors +Line: 1 Col: 44 Unexpected end tag (xmp). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <xmp> +| "<!--<xmp>" +| "-->" + +#data +<!doctype html><noembed><!--<noembed></noembed>--></noembed> +#errors +Line: 1 Col: 60 Unexpected end tag (noembed). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <noembed> +| "<!--<noembed>" +| "-->" + +#data +<script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 8 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| <body> + +#data +<script>a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 9 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "a" +| <body> + +#data +<script>< +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 9 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<" +| <body> + +#data +<script></ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 10 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</" +| <body> + +#data +<script></S +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</S" +| <body> + +#data +<script></SC +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 12 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</SC" +| <body> + +#data +<script></SCR +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 13 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</SCR" +| <body> + +#data +<script></SCRI +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 14 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</SCRI" +| <body> + +#data +<script></SCRIP +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 15 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</SCRIP" +| <body> + +#data +<script></SCRIPT +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 16 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</SCRIPT" +| <body> + +#data +<script></SCRIPT +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 17 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| <body> + +#data +<script></s +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</s" +| <body> + +#data +<script></sc +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 12 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</sc" +| <body> + +#data +<script></scr +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 13 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</scr" +| <body> + +#data +<script></scri +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 14 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</scri" +| <body> + +#data +<script></scrip +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 15 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</scrip" +| <body> + +#data +<script></script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 16 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</script" +| <body> + +#data +<script></script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 17 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| <body> + +#data +<script><! +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 10 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!" +| <body> + +#data +<script><!a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!a" +| <body> + +#data +<script><!- +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!-" +| <body> + +#data +<script><!-a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 12 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!-a" +| <body> + +#data +<script><!-- +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 12 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--" +| <body> + +#data +<script><!--a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 13 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--a" +| <body> + +#data +<script><!--< +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 13 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<" +| <body> + +#data +<script><!--<a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 14 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<a" +| <body> + +#data +<script><!--</ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 14 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--</" +| <body> + +#data +<script><!--</script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 20 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--</script" +| <body> + +#data +<script><!--</script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 21 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--" +| <body> + +#data +<script><!--<s +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 14 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<s" +| <body> + +#data +<script><!--<script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 19 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script" +| <body> + +#data +<script><!--<script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 20 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script " +| <body> + +#data +<script><!--<script < +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 21 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script <" +| <body> + +#data +<script><!--<script <a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 22 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script <a" +| <body> + +#data +<script><!--<script </ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 22 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </" +| <body> + +#data +<script><!--<script </s +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 23 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </s" +| <body> + +#data +<script><!--<script </script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 28 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script" +| <body> + +#data +<script><!--<script </scripta +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </scripta" +| <body> + +#data +<script><!--<script </script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<script><!--<script </script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script>" +| <body> + +#data +<script><!--<script </script/ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 29 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script/" +| <body> + +#data +<script><!--<script </script < +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 30 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script <" +| <body> + +#data +<script><!--<script </script <a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 31 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script <a" +| <body> + +#data +<script><!--<script </script </ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 31 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script </" +| <body> + +#data +<script><!--<script </script </script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script </script" +| <body> + +#data +<script><!--<script </script </script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<script><!--<script </script </script/ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 38 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<script><!--<script </script </script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script </script " +| <body> + +#data +<script><!--<script - +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 21 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script -" +| <body> + +#data +<script><!--<script -a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 22 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script -a" +| <body> + +#data +<script><!--<script -- +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 22 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script --" +| <body> + +#data +<script><!--<script --a +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 23 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script --a" +| <body> + +#data +<script><!--<script --> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 23 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<script><!--<script -->< +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 24 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script --><" +| <body> + +#data +<script><!--<script --></ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 25 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script --></" +| <body> + +#data +<script><!--<script --></script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 31 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script --></script" +| <body> + +#data +<script><!--<script --></script +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 32 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<script><!--<script --></script/ +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 32 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<script><!--<script --></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script -->" +| <body> + +#data +<script><!--<script><\/script>--></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script><\/script>-->" +| <body> + +#data +<script><!--<script></scr'+'ipt>--></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></scr'+'ipt>-->" +| <body> + +#data +<script><!--<script></script><script></script></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>" +| <body> + +#data +<script><!--<script></script><script></script>--><!--</script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>--><!--" +| <body> + +#data +<script><!--<script></script><script></script>-- ></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>-- >" +| <body> + +#data +<script><!--<script></script><script></script>- -></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>- ->" +| <body> + +#data +<script><!--<script></script><script></script>- - ></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>- - >" +| <body> + +#data +<script><!--<script></script><script></script>-></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +#document +| <html> +| <head> +| <script> +| "<!--<script></script><script></script>->" +| <body> + +#data +<script><!--<script>--!></script>X +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 34 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script>--!></script>X" +| <body> + +#data +<script><!--<scr'+'ipt></script>--></script> +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 44 Unexpected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<scr'+'ipt>" +| <body> +| "-->" + +#data +<script><!--<script></scr'+'ipt></script>X +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 42 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "<!--<script></scr'+'ipt></script>X" +| <body> + +#data +<style><!--<style></style>--></style> +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +Line: 1 Col: 37 Unexpected end tag (style). +#document +| <html> +| <head> +| <style> +| "<!--<style>" +| <body> +| "-->" + +#data +<style><!--</style>X +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| <html> +| <head> +| <style> +| "<!--" +| <body> +| "X" + +#data +<style><!--...</style>...--></style> +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +Line: 1 Col: 36 Unexpected end tag (style). +#document +| <html> +| <head> +| <style> +| "<!--..." +| <body> +| "...-->" + +#data +<style><!--<br><html xmlns:v="urn:schemas-microsoft-com:vml"><!--[if !mso]><style></style>X +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| <html> +| <head> +| <style> +| "<!--<br><html xmlns:v="urn:schemas-microsoft-com:vml"><!--[if !mso]><style>" +| <body> +| "X" + +#data +<style><!--...<style><!--...--!></style>--></style> +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +Line: 1 Col: 51 Unexpected end tag (style). +#document +| <html> +| <head> +| <style> +| "<!--...<style><!--...--!>" +| <body> +| "-->" + +#data +<style><!--...</style><!-- --><style>@import ...</style> +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| <html> +| <head> +| <style> +| "<!--..." +| <!-- --> +| <style> +| "@import ..." +| <body> + +#data +<style>...<style><!--...</style><!-- --></style> +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +Line: 1 Col: 48 Unexpected end tag (style). +#document +| <html> +| <head> +| <style> +| "...<style><!--..." +| <!-- --> +| <body> + +#data +<style>...<!--[if IE]><style>...</style>X +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| <html> +| <head> +| <style> +| "...<!--[if IE]><style>..." +| <body> +| "X" + +#data +<title><!--<title>--> +#errors +Line: 1 Col: 7 Unexpected start tag (title). Expected DOCTYPE. +Line: 1 Col: 37 Unexpected end tag (title). +#document +| +| +| +| "<!--<title>" +| <body> +| "-->" + +#data +<title></title> +#errors +Line: 1 Col: 7 Unexpected start tag (title). Expected DOCTYPE. +#document +| +| +| +| "" +| + +#data +foo/title><link></head><body>X +#errors +Line: 1 Col: 7 Unexpected start tag (title). Expected DOCTYPE. +Line: 1 Col: 37 Unexpected end of file. Expected end tag (title). +#document +| <html> +| <head> +| <title> +| "foo/title><link></head><body>X" +| <body> + +#data +<noscript><!--<noscript></noscript>--></noscript> +#errors +Line: 1 Col: 10 Unexpected start tag (noscript). Expected DOCTYPE. +Line: 1 Col: 49 Unexpected end tag (noscript). +#document +| <html> +| <head> +| <noscript> +| "<!--<noscript>" +| <body> +| "-->" + +#data +<noscript><!--</noscript>X<noscript>--></noscript> +#errors +Line: 1 Col: 10 Unexpected start tag (noscript). Expected DOCTYPE. +#document +| <html> +| <head> +| <noscript> +| "<!--" +| <body> +| "X" +| <noscript> +| "-->" + +#data +<noscript><iframe></noscript>X +#errors +Line: 1 Col: 10 Unexpected start tag (noscript). Expected DOCTYPE. +#document +| <html> +| <head> +| <noscript> +| "<iframe>" +| <body> +| "X" + +#data +<noframes><!--<noframes></noframes>--></noframes> +#errors +Line: 1 Col: 10 Unexpected start tag (noframes). Expected DOCTYPE. +Line: 1 Col: 49 Unexpected end tag (noframes). +#document +| <html> +| <head> +| <noframes> +| "<!--<noframes>" +| <body> +| "-->" + +#data +<noframes><body><script><!--...</script></body></noframes></html> +#errors +Line: 1 Col: 10 Unexpected start tag (noframes). Expected DOCTYPE. +#document +| <html> +| <head> +| <noframes> +| "<body><script><!--...</script></body>" +| <body> + +#data +<textarea><!--<textarea></textarea>--></textarea> +#errors +Line: 1 Col: 10 Unexpected start tag (textarea). Expected DOCTYPE. +Line: 1 Col: 49 Unexpected end tag (textarea). +#document +| <html> +| <head> +| <body> +| <textarea> +| "<!--<textarea>" +| "-->" + +#data +<textarea></textarea></textarea> +#errors +Line: 1 Col: 10 Unexpected start tag (textarea). Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| <textarea> +| "</textarea>" + +#data +<iframe><!--<iframe></iframe>--></iframe> +#errors +Line: 1 Col: 8 Unexpected start tag (iframe). Expected DOCTYPE. +Line: 1 Col: 41 Unexpected end tag (iframe). +#document +| <html> +| <head> +| <body> +| <iframe> +| "<!--<iframe>" +| "-->" + +#data +<iframe>...<!--X->...<!--/X->...</iframe> +#errors +Line: 1 Col: 8 Unexpected start tag (iframe). Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| <iframe> +| "...<!--X->...<!--/X->..." + +#data +<xmp><!--<xmp></xmp>--></xmp> +#errors +Line: 1 Col: 5 Unexpected start tag (xmp). Expected DOCTYPE. +Line: 1 Col: 29 Unexpected end tag (xmp). +#document +| <html> +| <head> +| <body> +| <xmp> +| "<!--<xmp>" +| "-->" + +#data +<noembed><!--<noembed></noembed>--></noembed> +#errors +Line: 1 Col: 9 Unexpected start tag (noembed). Expected DOCTYPE. +Line: 1 Col: 45 Unexpected end tag (noembed). +#document +| <html> +| <head> +| <body> +| <noembed> +| "<!--<noembed>" +| "-->" + +#data +<!doctype html><table> + +#errors +Line 2 Col 0 Unexpected end of file. Expected table content. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| " +" + +#data +<!doctype html><table><td><span><font></span><span> +#errors +Line 1 Col 26 Unexpected table cell start tag (td) in the table body phase. +Line 1 Col 45 Unexpected end tag (span). +Line 1 Col 51 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| <span> +| <font> +| <font> +| <span> + +#data +<!doctype html><form><table></form><form></table></form> +#errors +35: Stray end tag “formâ€. +41: Start tag “form†seen in “tableâ€. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <form> +| <table> +| <form> diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests17.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests17.dat new file mode 100644 index 0000000..7b555f8 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests17.dat @@ -0,0 +1,153 @@ +#data +<!doctype html><table><tbody><select><tr> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <table> +| <tbody> +| <tr> + +#data +<!doctype html><table><tr><select><td> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <table> +| <tbody> +| <tr> +| <td> + +#data +<!doctype html><table><tr><td><select><td> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| <select> +| <td> + +#data +<!doctype html><table><tr><th><select><td> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <th> +| <select> +| <td> + +#data +<!doctype html><table><caption><select><tr> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <caption> +| <select> +| <tbody> +| <tr> + +#data +<!doctype html><select><tr> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><select><td> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><select><th> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><select><tbody> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><select><thead> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><select><tfoot> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><select><caption> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><table><tr></table>a +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| "a" diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests18.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests18.dat new file mode 100644 index 0000000..680e1f0 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests18.dat @@ -0,0 +1,269 @@ +#data +<!doctype html><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <plaintext> +| "</plaintext>" + +#data +<!doctype html><table><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <plaintext> +| "</plaintext>" +| <table> + +#data +<!doctype html><table><tbody><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <plaintext> +| "</plaintext>" +| <table> +| <tbody> + +#data +<!doctype html><table><tbody><tr><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <plaintext> +| "</plaintext>" +| <table> +| <tbody> +| <tr> + +#data +<!doctype html><table><tbody><tr><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <plaintext> +| "</plaintext>" +| <table> +| <tbody> +| <tr> + +#data +<!doctype html><table><td><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| <plaintext> +| "</plaintext>" + +#data +<!doctype html><table><caption><plaintext></plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <caption> +| <plaintext> +| "</plaintext>" + +#data +<!doctype html><table><tr><style></script></style>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "abc" +| <table> +| <tbody> +| <tr> +| <style> +| "</script>" + +#data +<!doctype html><table><tr><script></style></script>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "abc" +| <table> +| <tbody> +| <tr> +| <script> +| "</style>" + +#data +<!doctype html><table><caption><style></script></style>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <caption> +| <style> +| "</script>" +| "abc" + +#data +<!doctype html><table><td><style></script></style>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| <style> +| "</script>" +| "abc" + +#data +<!doctype html><select><script></style></script>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <script> +| "</style>" +| "abc" + +#data +<!doctype html><table><select><script></style></script>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <script> +| "</style>" +| "abc" +| <table> + +#data +<!doctype html><table><tr><select><script></style></script>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <script> +| "</style>" +| "abc" +| <table> +| <tbody> +| <tr> + +#data +<!doctype html><frameset></frameset><noframes>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <noframes> +| "abc" + +#data +<!doctype html><frameset></frameset><noframes>abc</noframes><!--abc--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <noframes> +| "abc" +| <!-- abc --> + +#data +<!doctype html><frameset></frameset></html><noframes>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <noframes> +| "abc" + +#data +<!doctype html><frameset></frameset></html><noframes>abc</noframes><!--abc--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <noframes> +| "abc" +| <!-- abc --> + +#data +<!doctype html><table><tr></tbody><tfoot> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <tfoot> + +#data +<!doctype html><table><td><svg></svg>abc<td> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| <svg svg> +| "abc" +| <td> diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests19.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests19.dat new file mode 100644 index 0000000..0d62f5a --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests19.dat @@ -0,0 +1,1237 @@ +#data +<!doctype html><math><mn DefinitionUrl="foo"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <math math> +| <math mn> +| definitionURL="foo" + +#data +<!doctype html><html></p><!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <!-- foo --> +| <head> +| <body> + +#data +<!doctype html><head></head></p><!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <!-- foo --> +| <body> + +#data +<!doctype html><body><p><pre> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <pre> + +#data +<!doctype html><body><p><listing> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <listing> + +#data +<!doctype html><p><plaintext> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <plaintext> + +#data +<!doctype html><p><h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <h1> + +#data +<!doctype html><form><isindex> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <form> + +#data +<!doctype html><isindex action="POST"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <form> +| action="POST" +| <hr> +| <label> +| "This is a searchable index. Enter search keywords: " +| <input> +| name="isindex" +| <hr> + +#data +<!doctype html><isindex prompt="this is isindex"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <form> +| <hr> +| <label> +| "this is isindex" +| <input> +| name="isindex" +| <hr> + +#data +<!doctype html><isindex type="hidden"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <form> +| <hr> +| <label> +| "This is a searchable index. Enter search keywords: " +| <input> +| name="isindex" +| type="hidden" +| <hr> + +#data +<!doctype html><isindex name="foo"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <form> +| <hr> +| <label> +| "This is a searchable index. Enter search keywords: " +| <input> +| name="isindex" +| <hr> + +#data +<!doctype html><ruby><p><rp> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <ruby> +| <p> +| <rp> + +#data +<!doctype html><ruby><div><span><rp> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <ruby> +| <div> +| <span> +| <rp> + +#data +<!doctype html><ruby><div><p><rp> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <ruby> +| <div> +| <p> +| <rp> + +#data +<!doctype html><ruby><p><rt> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <ruby> +| <p> +| <rt> + +#data +<!doctype html><ruby><div><span><rt> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <ruby> +| <div> +| <span> +| <rt> + +#data +<!doctype html><ruby><div><p><rt> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <ruby> +| <div> +| <p> +| <rt> + +#data +<!doctype html><math/><foo> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <math math> +| <foo> + +#data +<!doctype html><svg/><foo> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <svg svg> +| <foo> + +#data +<!doctype html><div></body><!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <div> +| <!-- foo --> + +#data +<!doctype html><h1><div><h3><span></h1>foo +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <h1> +| <div> +| <h3> +| <span> +| "foo" + +#data +<!doctype html><p></h3>foo +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| "foo" + +#data +<!doctype html><h3><li>abc</h2>foo +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <h3> +| <li> +| "abc" +| "foo" + +#data +<!doctype html><table>abc<!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "abc" +| <table> +| <!-- foo --> + +#data +<!doctype html><table> <!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| " " +| <!-- foo --> + +#data +<!doctype html><table> b <!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| " b " +| <table> +| <!-- foo --> + +#data +<!doctype html><select><option><option> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <option> +| <option> + +#data +<!doctype html><select><option></optgroup> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <option> + +#data +<!doctype html><select><option></optgroup> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <option> + +#data +<!doctype html><p><math><mi><p><h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| <math mi> +| <p> +| <h1> + +#data +<!doctype html><p><math><mo><p><h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| <math mo> +| <p> +| <h1> + +#data +<!doctype html><p><math><mn><p><h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| <math mn> +| <p> +| <h1> + +#data +<!doctype html><p><math><ms><p><h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| <math ms> +| <p> +| <h1> + +#data +<!doctype html><p><math><mtext><p><h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| <math mtext> +| <p> +| <h1> + +#data +<!doctype html><frameset></noframes> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<!doctype html><html c=d><body></html><html a=b> +#errors +#document +| <!DOCTYPE html> +| <html> +| a="b" +| c="d" +| <head> +| <body> + +#data +<!doctype html><html c=d><frameset></frameset></html><html a=b> +#errors +#document +| <!DOCTYPE html> +| <html> +| a="b" +| c="d" +| <head> +| <frameset> + +#data +<!doctype html><html><frameset></frameset></html><!--foo--> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <!-- foo --> + +#data +<!doctype html><html><frameset></frameset></html> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| " " + +#data +<!doctype html><html><frameset></frameset></html>abc +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<!doctype html><html><frameset></frameset></html><p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<!doctype html><html><frameset></frameset></html></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<html><frameset></frameset></html><!doctype html> +#errors +#document +| <html> +| <head> +| <frameset> + +#data +<!doctype html><body><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> + +#data +<!doctype html><p><frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <frame> + +#data +<!doctype html><p>a<frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| "a" + +#data +<!doctype html><p> <frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <frame> + +#data +<!doctype html><pre><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <pre> + +#data +<!doctype html><listing><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <listing> + +#data +<!doctype html><li><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <li> + +#data +<!doctype html><dd><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <dd> + +#data +<!doctype html><dt><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <dt> + +#data +<!doctype html><button><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <button> + +#data +<!doctype html><applet><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <applet> + +#data +<!doctype html><marquee><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <marquee> + +#data +<!doctype html><object><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <object> + +#data +<!doctype html><table><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> + +#data +<!doctype html><area><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <area> + +#data +<!doctype html><basefont><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <basefont> +| <frameset> + +#data +<!doctype html><bgsound><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <bgsound> +| <frameset> + +#data +<!doctype html><br><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <br> + +#data +<!doctype html><embed><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <embed> + +#data +<!doctype html><img><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <img> + +#data +<!doctype html><input><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <input> + +#data +<!doctype html><keygen><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <keygen> + +#data +<!doctype html><wbr><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <wbr> + +#data +<!doctype html><hr><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <hr> + +#data +<!doctype html><textarea></textarea><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <textarea> + +#data +<!doctype html><xmp></xmp><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <xmp> + +#data +<!doctype html><iframe></iframe><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <iframe> + +#data +<!doctype html><select></select><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> + +#data +<!doctype html><svg></svg><frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <frame> + +#data +<!doctype html><math></math><frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <frame> + +#data +<!doctype html><svg><foreignObject><div> <frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <frame> + +#data +<!doctype html><svg>a</svg><frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <svg svg> +| "a" + +#data +<!doctype html><svg> </svg><frameset><frame> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> +| <frame> + +#data +<html>aaa<frameset></frameset> +#errors +#document +| <html> +| <head> +| <body> +| "aaa" + +#data +<html> a <frameset></frameset> +#errors +#document +| <html> +| <head> +| <body> +| "a " + +#data +<!doctype html><div><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<!doctype html><div><body><frameset> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <div> + +#data +<!doctype html><p><math></p>a +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| "a" + +#data +<!doctype html><p><math><mn><span></p>a +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <math math> +| <math mn> +| <span> +| <p> +| "a" + +#data +<!doctype html><math></html> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <math math> + +#data +<!doctype html><meta charset="ascii"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <meta> +| charset="ascii" +| <body> + +#data +<!doctype html><meta http-equiv="content-type" content="text/html;charset=ascii"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <meta> +| content="text/html;charset=ascii" +| http-equiv="content-type" +| <body> + +#data +<!doctype html><head><!--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa--><meta charset="utf8"> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <!-- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --> +| <meta> +| charset="utf8" +| <body> + +#data +<!doctype html><html a=b><head></head><html c=d> +#errors +#document +| <!DOCTYPE html> +| <html> +| a="b" +| c="d" +| <head> +| <body> + +#data +<!doctype html><image/> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <img> + +#data +<!doctype html>a<i>b<table>c<b>d</i>e</b>f +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "a" +| <i> +| "bc" +| <b> +| "de" +| "f" +| <table> + +#data +<!doctype html><table><i>a<b>b<div>c<a>d</i>e</b>f +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <i> +| "a" +| <b> +| "b" +| <b> +| <div> +| <b> +| <i> +| "c" +| <a> +| "d" +| <a> +| "e" +| <a> +| "f" +| <table> + +#data +<!doctype html><i>a<b>b<div>c<a>d</i>e</b>f +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <i> +| "a" +| <b> +| "b" +| <b> +| <div> +| <b> +| <i> +| "c" +| <a> +| "d" +| <a> +| "e" +| <a> +| "f" + +#data +<!doctype html><table><i>a<b>b<div>c</i> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <i> +| "a" +| <b> +| "b" +| <b> +| <div> +| <i> +| "c" +| <table> + +#data +<!doctype html><table><i>a<b>b<div>c<a>d</i>e</b>f +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <i> +| "a" +| <b> +| "b" +| <b> +| <div> +| <b> +| <i> +| "c" +| <a> +| "d" +| <a> +| "e" +| <a> +| "f" +| <table> + +#data +<!doctype html><table><i>a<div>b<tr>c<b>d</i>e +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <i> +| "a" +| <div> +| "b" +| <i> +| "c" +| <b> +| "d" +| <b> +| "e" +| <table> +| <tbody> +| <tr> + +#data +<!doctype html><table><td><table><i>a<div>b<b>c</i>d +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| <i> +| "a" +| <div> +| <i> +| "b" +| <b> +| "c" +| <b> +| "d" +| <table> + +#data +<!doctype html><body><bgsound> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <bgsound> + +#data +<!doctype html><body><basefont> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <basefont> + +#data +<!doctype html><a><b></a><basefont> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <a> +| <b> +| <basefont> + +#data +<!doctype html><a><b></a><bgsound> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <a> +| <b> +| <bgsound> + +#data +<!doctype html><figcaption><article></figcaption>a +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <figcaption> +| <article> +| "a" + +#data +<!doctype html><summary><article></summary>a +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <summary> +| <article> +| "a" + +#data +<!doctype html><p><a><plaintext>b +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <a> +| <plaintext> +| <a> +| "b" + +#data +<!DOCTYPE html><div>a<a></div>b<p>c</p>d +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <div> +| "a" +| <a> +| <a> +| "b" +| <p> +| "c" +| "d" diff --git a/vendor/golang.org/x/net/html/testdata/webkit/tests2.dat b/vendor/golang.org/x/net/html/testdata/webkit/tests2.dat new file mode 100644 index 0000000..60d8592 --- /dev/null +++ b/vendor/golang.org/x/net/html/testdata/webkit/tests2.dat @@ -0,0 +1,763 @@ +#data +<!DOCTYPE html>Test +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "Test" + +#data +<textarea>test</div>test +#errors +Line: 1 Col: 10 Unexpected start tag (textarea). Expected DOCTYPE. +Line: 1 Col: 24 Expected closing tag. Unexpected end of file. +#document +| <html> +| <head> +| <body> +| <textarea> +| "test</div>test" + +#data +<table><td> +#errors +Line: 1 Col: 7 Unexpected start tag (table). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected table cell start tag (td) in the table body phase. +Line: 1 Col: 11 Expected closing tag. Unexpected end of file. +#document +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> + +#data +<table><td>test</tbody></table> +#errors +Line: 1 Col: 7 Unexpected start tag (table). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected table cell start tag (td) in the table body phase. +#document +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <td> +| "test" + +#data +<frame>test +#errors +Line: 1 Col: 7 Unexpected start tag (frame). Expected DOCTYPE. +Line: 1 Col: 7 Unexpected start tag frame. Ignored. +#document +| <html> +| <head> +| <body> +| "test" + +#data +<!DOCTYPE html><frameset>test +#errors +Line: 1 Col: 29 Unepxected characters in the frameset phase. Characters ignored. +Line: 1 Col: 29 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<!DOCTYPE html><frameset><!DOCTYPE html> +#errors +Line: 1 Col: 40 Unexpected DOCTYPE. Ignored. +Line: 1 Col: 40 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <frameset> + +#data +<!DOCTYPE html><font><p><b>test</font> +#errors +Line: 1 Col: 38 End tag (font) violates step 1, paragraph 3 of the adoption agency algorithm. +Line: 1 Col: 38 End tag (font) violates step 1, paragraph 3 of the adoption agency algorithm. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <font> +| <p> +| <font> +| <b> +| "test" + +#data +<!DOCTYPE html><dt><div><dd> +#errors +Line: 1 Col: 28 Missing end tag (div, dt). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <dt> +| <div> +| <dd> + +#data +<script></x +#errors +Line: 1 Col: 8 Unexpected start tag (script). Expected DOCTYPE. +Line: 1 Col: 11 Unexpected end of file. Expected end tag (script). +#document +| <html> +| <head> +| <script> +| "</x" +| <body> + +#data +<table><plaintext><td> +#errors +Line: 1 Col: 7 Unexpected start tag (table). Expected DOCTYPE. +Line: 1 Col: 18 Unexpected start tag (plaintext) in table context caused voodoo mode. +Line: 1 Col: 22 Unexpected end of file. Expected table content. +#document +| <html> +| <head> +| <body> +| <plaintext> +| "<td>" +| <table> + +#data +<plaintext></plaintext> +#errors +Line: 1 Col: 11 Unexpected start tag (plaintext). Expected DOCTYPE. +Line: 1 Col: 23 Expected closing tag. Unexpected end of file. +#document +| <html> +| <head> +| <body> +| <plaintext> +| "</plaintext>" + +#data +<!DOCTYPE html><table><tr>TEST +#errors +Line: 1 Col: 30 Unexpected non-space characters in table context caused voodoo mode. +Line: 1 Col: 30 Unexpected end of file. Expected table content. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "TEST" +| <table> +| <tbody> +| <tr> + +#data +<!DOCTYPE html><body t1=1><body t2=2><body t3=3 t4=4> +#errors +Line: 1 Col: 37 Unexpected start tag (body). +Line: 1 Col: 53 Unexpected start tag (body). +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| t1="1" +| t2="2" +| t3="3" +| t4="4" + +#data +</b test +#errors +Line: 1 Col: 8 Unexpected end of file in attribute name. +Line: 1 Col: 8 End tag contains unexpected attributes. +Line: 1 Col: 8 Unexpected end tag (b). Expected DOCTYPE. +Line: 1 Col: 8 Unexpected end tag (b) after the (implied) root element. +#document +| <html> +| <head> +| <body> + +#data +<!DOCTYPE html></b test<b &=&>X +#errors +Line: 1 Col: 32 Named entity didn't end with ';'. +Line: 1 Col: 33 End tag contains unexpected attributes. +Line: 1 Col: 33 Unexpected end tag (b) after the (implied) root element. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "X" + +#data +<!doctypehtml><scrIPt type=text/x-foobar;baz>X</SCRipt +#errors +Line: 1 Col: 9 No space after literal string 'DOCTYPE'. +Line: 1 Col: 54 Unexpected end of file in the tag name. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <script> +| type="text/x-foobar;baz" +| "X</SCRipt" +| <body> + +#data +& +#errors +Line: 1 Col: 1 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&" + +#data +&# +#errors +Line: 1 Col: 1 Numeric entity expected. Got end of file instead. +Line: 1 Col: 1 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&#" + +#data +&#X +#errors +Line: 1 Col: 3 Numeric entity expected but none found. +Line: 1 Col: 3 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&#X" + +#data +&#x +#errors +Line: 1 Col: 3 Numeric entity expected but none found. +Line: 1 Col: 3 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&#x" + +#data +- +#errors +Line: 1 Col: 4 Numeric entity didn't end with ';'. +Line: 1 Col: 4 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "-" + +#data +&x-test +#errors +Line: 1 Col: 1 Named entity expected. Got none. +Line: 1 Col: 1 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&x-test" + +#data +<!doctypehtml><p><li> +#errors +Line: 1 Col: 9 No space after literal string 'DOCTYPE'. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <li> + +#data +<!doctypehtml><p><dt> +#errors +Line: 1 Col: 9 No space after literal string 'DOCTYPE'. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <dt> + +#data +<!doctypehtml><p><dd> +#errors +Line: 1 Col: 9 No space after literal string 'DOCTYPE'. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <dd> + +#data +<!doctypehtml><p><form> +#errors +Line: 1 Col: 9 No space after literal string 'DOCTYPE'. +Line: 1 Col: 23 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <form> + +#data +<!DOCTYPE html><p></P>X +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| "X" + +#data +& +#errors +Line: 1 Col: 4 Named entity didn't end with ';'. +Line: 1 Col: 4 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&" + +#data +&AMp; +#errors +Line: 1 Col: 1 Named entity expected. Got none. +Line: 1 Col: 1 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "&AMp;" + +#data +<!DOCTYPE html><html><head></head><body><thisISasillyTESTelementNameToMakeSureCrazyTagNamesArePARSEDcorrectLY> +#errors +Line: 1 Col: 110 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <thisisasillytestelementnametomakesurecrazytagnamesareparsedcorrectly> + +#data +<!DOCTYPE html>X</body>X +#errors +Line: 1 Col: 24 Unexpected non-space characters in the after body phase. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "XX" + +#data +<!DOCTYPE html><!-- X +#errors +Line: 1 Col: 21 Unexpected end of file in comment. +#document +| <!DOCTYPE html> +| <!-- X --> +| <html> +| <head> +| <body> + +#data +<!DOCTYPE html><table><caption>test TEST</caption><td>test +#errors +Line: 1 Col: 54 Unexpected table cell start tag (td) in the table body phase. +Line: 1 Col: 58 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <table> +| <caption> +| "test TEST" +| <tbody> +| <tr> +| <td> +| "test" + +#data +<!DOCTYPE html><select><option><optgroup> +#errors +Line: 1 Col: 41 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <option> +| <optgroup> + +#data +<!DOCTYPE html><select><optgroup><option></optgroup><option><select><option> +#errors +Line: 1 Col: 68 Unexpected select start tag in the select phase treated as select end tag. +Line: 1 Col: 76 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <optgroup> +| <option> +| <option> +| <option> + +#data +<!DOCTYPE html><select><optgroup><option><optgroup> +#errors +Line: 1 Col: 51 Expected closing tag. Unexpected end of file. +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <optgroup> +| <option> +| <optgroup> + +#data +<!DOCTYPE html><datalist><option>foo</datalist>bar +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <datalist> +| <option> +| "foo" +| "bar" + +#data +<!DOCTYPE html><font><input><input></font> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <font> +| <input> +| <input> + +#data +<!DOCTYPE html><!-- XXX - XXX --> +#errors +#document +| <!DOCTYPE html> +| <!-- XXX - XXX --> +| <html> +| <head> +| <body> + +#data +<!DOCTYPE html><!-- XXX - XXX +#errors +Line: 1 Col: 29 Unexpected end of file in comment (-) +#document +| <!DOCTYPE html> +| <!-- XXX - XXX --> +| <html> +| <head> +| <body> + +#data +<!DOCTYPE html><!-- XXX - XXX - XXX --> +#errors +#document +| <!DOCTYPE html> +| <!-- XXX - XXX - XXX --> +| <html> +| <head> +| <body> + +#data +<isindex test=x name=x> +#errors +Line: 1 Col: 23 Unexpected start tag (isindex). Expected DOCTYPE. +Line: 1 Col: 23 Unexpected start tag isindex. Don't use it! +#document +| <html> +| <head> +| <body> +| <form> +| <hr> +| <label> +| "This is a searchable index. Enter search keywords: " +| <input> +| name="isindex" +| test="x" +| <hr> + +#data +test +test +#errors +Line: 2 Col: 4 Unexpected non-space characters. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> +| "test +test" + +#data +<!DOCTYPE html><body><title>test</body> +#errors +#document +| +| +| +| +| +| "test</body>" + +#data +<!DOCTYPE html><body><title>X +#errors +#document +| +| +| +| +| +| "X" +| <meta> +| name="z" +| <link> +| rel="foo" +| <style> +| " +x { content:"</style" } " + +#data +<!DOCTYPE html><select><optgroup></optgroup></select> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <select> +| <optgroup> + +#data + + +#errors +Line: 2 Col: 1 Unexpected End of file. Expected DOCTYPE. +#document +| <html> +| <head> +| <body> + +#data +<!DOCTYPE html> <html> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> + +#data +<!DOCTYPE html><script> +</script> <title>x +#errors +#document +| +| +| +| +#errors +Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE. +Line: 1 Col: 21 Unexpected start tag (script) that can be in head. Moved. +#document +| +| +| +#errors +Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE. +Line: 1 Col: 28 Unexpected start tag (style) that can be in head. Moved. +#document +| +| +| +#errors +Line: 1 Col: 6 Unexpected start tag (head). Expected DOCTYPE. +#document +| +| +| +| +| "x" +| x +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +Line: 1 Col: 22 Unexpected end of file. Expected end tag (style). +#document +| +| +| --> x +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| +| +| x +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| +| +| x +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| +| +| x +#errors +Line: 1 Col: 7 Unexpected start tag (style). Expected DOCTYPE. +#document +| +| +|

+#errors +#document +| +| +| +| +| +| ddd +#errors +#document +| +| +| +#errors +#document +| +| +| +| +|
  • +| +| ", + "