Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / xml / read_test.go
blob9ec1065c23d953b781bfd1d1a6d37f75680953da
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package xml
7 import (
8 "reflect"
9 "testing"
12 // Stripped down Atom feed data structures.
14 func TestUnmarshalFeed(t *testing.T) {
15 var f Feed
16 if err := Unmarshal(StringReader(rssFeedString), &f); err != nil {
17 t.Fatalf("Unmarshal: %s", err)
19 if !reflect.DeepEqual(f, rssFeed) {
20 t.Fatalf("have %#v\nwant %#v", f, rssFeed)
24 // hget http://codereview.appspot.com/rss/mine/rsc
25 const rssFeedString = `
26 <?xml version="1.0" encoding="utf-8"?>
27 <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><title>Code Review - My issues</title><link href="http://codereview.appspot.com/" rel="alternate"></link><li-nk href="http://codereview.appspot.com/rss/mine/rsc" rel="self"></li-nk><id>http://codereview.appspot.com/</id><updated>2009-10-04T01:35:58+00:00</updated><author><name>rietveld&lt;&gt;</name></author><entry><title>rietveld: an attempt at pubsubhubbub
28 </title><link hre-f="http://codereview.appspot.com/126085" rel="alternate"></link><updated>2009-10-04T01:35:58+00:00</updated><author><name>email-address-removed</name></author><id>urn:md5:134d9179c41f806be79b3a5f7877d19a</id><summary type="html">
29 An attempt at adding pubsubhubbub support to Rietveld.
30 http://code.google.com/p/pubsubhubbub
31 http://code.google.com/p/rietveld/issues/detail?id=155
33 The server side of the protocol is trivial:
34 1. add a &amp;lt;link rel=&amp;quot;hub&amp;quot; href=&amp;quot;hub-server&amp;quot;&amp;gt; tag to all
35 feeds that will be pubsubhubbubbed.
36 2. every time one of those feeds changes, tell the hub
37 with a simple POST request.
39 I have tested this by adding debug prints to a local hub
40 server and checking that the server got the right publish
41 requests.
43 I can&amp;#39;t quite get the server to work, but I think the bug
44 is not in my code. I think that the server expects to be
45 able to grab the feed and see the feed&amp;#39;s actual URL in
46 the link rel=&amp;quot;self&amp;quot;, but the default value for that drops
47 the :port from the URL, and I cannot for the life of me
48 figure out how to get the Atom generator deep inside
49 django not to do that, or even where it is doing that,
50 or even what code is running to generate the Atom feed.
51 (I thought I knew but I added some assert False statements
52 and it kept running!)
54 Ignoring that particular problem, I would appreciate
55 feedback on the right way to get the two values at
56 the top of feeds.py marked NOTE(rsc).
59 </summary></entry><entry><title>rietveld: correct tab handling
60 </title><link href="http://codereview.appspot.com/124106" rel="alternate"></link><updated>2009-10-03T23:02:17+00:00</updated><author><name>email-address-removed</name></author><id>urn:md5:0a2a4f19bb815101f0ba2904aed7c35a</id><summary type="html">
61 This fixes the buggy tab rendering that can be seen at
62 http://codereview.appspot.com/116075/diff/1/2
64 The fundamental problem was that the tab code was
65 not being told what column the text began in, so it
66 didn&amp;#39;t know where to put the tab stops. Another problem
67 was that some of the code assumed that string byte
68 offsets were the same as column offsets, which is only
69 true if there are no tabs.
71 In the process of fixing this, I cleaned up the arguments
72 to Fold and ExpandTabs and renamed them Break and
73 _ExpandTabs so that I could be sure that I found all the
74 call sites. I also wanted to verify that ExpandTabs was
75 not being used from outside intra_region_diff.py.
78 </summary></entry></feed> `
80 type Feed struct {
81 XMLName Name "http://www.w3.org/2005/Atom feed"
82 Title string
83 Id string
84 Link []Link
85 Updated Time
86 Author Person
87 Entry []Entry
90 type Entry struct {
91 Title string
92 Id string
93 Link []Link
94 Updated Time
95 Author Person
96 Summary Text
99 type Link struct {
100 Rel string "attr"
101 Href string "attr"
104 type Person struct {
105 Name string
106 URI string
107 Email string
108 InnerXML string "innerxml"
111 type Text struct {
112 Type string "attr"
113 Body string "chardata"
116 type Time string
118 var rssFeed = Feed{
119 XMLName: Name{"http://www.w3.org/2005/Atom", "feed"},
120 Title: "Code Review - My issues",
121 Link: []Link{
122 {Rel: "alternate", Href: "http://codereview.appspot.com/"},
123 {Rel: "self", Href: "http://codereview.appspot.com/rss/mine/rsc"},
125 Id: "http://codereview.appspot.com/",
126 Updated: "2009-10-04T01:35:58+00:00",
127 Author: Person{
128 Name: "rietveld<>",
129 InnerXML: "<name>rietveld&lt;&gt;</name>",
131 Entry: []Entry{
133 Title: "rietveld: an attempt at pubsubhubbub\n",
134 Link: []Link{
135 {Rel: "alternate", Href: "http://codereview.appspot.com/126085"},
137 Updated: "2009-10-04T01:35:58+00:00",
138 Author: Person{
139 Name: "email-address-removed",
140 InnerXML: "<name>email-address-removed</name>",
142 Id: "urn:md5:134d9179c41f806be79b3a5f7877d19a",
143 Summary: Text{
144 Type: "html",
145 Body: `
146 An attempt at adding pubsubhubbub support to Rietveld.
147 http://code.google.com/p/pubsubhubbub
148 http://code.google.com/p/rietveld/issues/detail?id=155
150 The server side of the protocol is trivial:
151 1. add a &lt;link rel=&quot;hub&quot; href=&quot;hub-server&quot;&gt; tag to all
152 feeds that will be pubsubhubbubbed.
153 2. every time one of those feeds changes, tell the hub
154 with a simple POST request.
156 I have tested this by adding debug prints to a local hub
157 server and checking that the server got the right publish
158 requests.
160 I can&#39;t quite get the server to work, but I think the bug
161 is not in my code. I think that the server expects to be
162 able to grab the feed and see the feed&#39;s actual URL in
163 the link rel=&quot;self&quot;, but the default value for that drops
164 the :port from the URL, and I cannot for the life of me
165 figure out how to get the Atom generator deep inside
166 django not to do that, or even where it is doing that,
167 or even what code is running to generate the Atom feed.
168 (I thought I knew but I added some assert False statements
169 and it kept running!)
171 Ignoring that particular problem, I would appreciate
172 feedback on the right way to get the two values at
173 the top of feeds.py marked NOTE(rsc).
180 Title: "rietveld: correct tab handling\n",
181 Link: []Link{
182 {Rel: "alternate", Href: "http://codereview.appspot.com/124106"},
184 Updated: "2009-10-03T23:02:17+00:00",
185 Author: Person{
186 Name: "email-address-removed",
187 InnerXML: "<name>email-address-removed</name>",
189 Id: "urn:md5:0a2a4f19bb815101f0ba2904aed7c35a",
190 Summary: Text{
191 Type: "html",
192 Body: `
193 This fixes the buggy tab rendering that can be seen at
194 http://codereview.appspot.com/116075/diff/1/2
196 The fundamental problem was that the tab code was
197 not being told what column the text began in, so it
198 didn&#39;t know where to put the tab stops. Another problem
199 was that some of the code assumed that string byte
200 offsets were the same as column offsets, which is only
201 true if there are no tabs.
203 In the process of fixing this, I cleaned up the arguments
204 to Fold and ExpandTabs and renamed them Break and
205 _ExpandTabs so that I could be sure that I found all the
206 call sites. I also wanted to verify that ExpandTabs was
207 not being used from outside intra_region_diff.py.
216 type FieldNameTest struct {
217 in, out string
220 var FieldNameTests = []FieldNameTest{
221 {"Profile-Image", "profileimage"},
222 {"_score", "score"},
225 func TestFieldName(t *testing.T) {
226 for _, tt := range FieldNameTests {
227 a := fieldName(tt.in)
228 if a != tt.out {
229 t.Fatalf("have %#v\nwant %#v\n\n", a, tt.out)