LEFT | RIGHT |
1 package goyaml_test | 1 package goyaml_test |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
6 "launchpad.net/goyaml" | 6 "launchpad.net/goyaml" |
7 "math" | 7 "math" |
| 8 "strconv" |
8 "strings" | 9 "strings" |
9 ) | 10 ) |
10 | 11 |
11 var marshalIntTest = 123 | 12 var marshalIntTest = 123 |
12 | 13 |
13 var marshalTests = []struct { | 14 var marshalTests = []struct { |
14 data string | 15 data string |
15 value interface{} | 16 value interface{} |
16 }{ | 17 }{ |
17 {"{}\n", &struct{}{}}, | 18 {"{}\n", &struct{}{}}, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 obj := &typeWithGetter{} | 169 obj := &typeWithGetter{} |
169 obj.tag = "" | 170 obj.tag = "" |
170 obj.value = map[string]string{"hello": "world!"} | 171 obj.value = map[string]string{"hello": "world!"} |
171 data, err := goyaml.Marshal(obj) | 172 data, err := goyaml.Marshal(obj) |
172 c.Assert(err, IsNil) | 173 c.Assert(err, IsNil) |
173 c.Assert(string(data), Equals, "hello: world!\n") | 174 c.Assert(string(data), Equals, "hello: world!\n") |
174 } | 175 } |
175 | 176 |
176 func (s *S) TestSortedOutput(c *C) { | 177 func (s *S) TestSortedOutput(c *C) { |
177 order := []interface{}{ | 178 order := []interface{}{ |
| 179 false, |
| 180 true, |
178 1, | 181 1, |
| 182 uint(1), |
179 1.0, | 183 1.0, |
180 1.1, | 184 1.1, |
181 1.2, | 185 1.2, |
182 2, | 186 2, |
| 187 uint(2), |
183 2.0, | 188 2.0, |
184 2.1, | 189 2.1, |
| 190 "", |
| 191 ".1", |
| 192 ".2", |
| 193 ".a", |
| 194 "1", |
| 195 "2", |
185 "a!10", | 196 "a!10", |
186 "a/2", | 197 "a/2", |
187 "a/10", | 198 "a/10", |
188 "a~10", | 199 "a~10", |
189 "ab/1", | 200 "ab/1", |
190 "b/1", | 201 "b/1", |
191 "b/01", | 202 "b/01", |
192 "b/2", | 203 "b/2", |
193 "b/02", | 204 "b/02", |
194 "b/3", | 205 "b/3", |
(...skipping 10 matching lines...) Expand all Loading... |
205 m := make(map[interface{}]int) | 216 m := make(map[interface{}]int) |
206 for _, k := range order { | 217 for _, k := range order { |
207 m[k] = 1 | 218 m[k] = 1 |
208 } | 219 } |
209 data, err := goyaml.Marshal(m) | 220 data, err := goyaml.Marshal(m) |
210 c.Assert(err, IsNil) | 221 c.Assert(err, IsNil) |
211 out := "\n" + string(data) | 222 out := "\n" + string(data) |
212 last := 0 | 223 last := 0 |
213 for i, k := range order { | 224 for i, k := range order { |
214 repr := fmt.Sprint(k) | 225 repr := fmt.Sprint(k) |
| 226 if s, ok := k.(string); ok { |
| 227 if _, err = strconv.ParseFloat(repr, 32); s == "" || err
== nil { |
| 228 repr = `"` + repr + `"` |
| 229 } |
| 230 } |
215 index := strings.Index(out, "\n"+repr+":") | 231 index := strings.Index(out, "\n"+repr+":") |
216 if index == -1 { | 232 if index == -1 { |
217 c.Fatalf("%#v is not in the output: %#v", k, out) | 233 c.Fatalf("%#v is not in the output: %#v", k, out) |
218 } | 234 } |
219 if index < last { | 235 if index < last { |
220 c.Fatalf("%#v was generated before %#v: %q", k, order[i-
1], out) | 236 c.Fatalf("%#v was generated before %#v: %q", k, order[i-
1], out) |
221 } | 237 } |
222 last = index | 238 last = index |
223 } | 239 } |
224 } | 240 } |
LEFT | RIGHT |