| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('yaml_test'); | 5 #library('yaml_test'); |
| 6 | 6 |
| 7 #import('../../../lib/unittest/unittest.dart'); | 7 #import('../../../lib/unittest/unittest.dart'); |
| 8 #import('../../pub/yaml/yaml.dart'); | 8 #import('../../pub/yaml/yaml.dart'); |
| 9 #import('../../pub/yaml/deep_equals.dart'); | 9 #import('../../pub/yaml/deep_equals.dart'); |
| 10 #import('../../../tests/utils/test_utils.dart'); | 10 #import('../../../tests/utils/test_utils.dart'); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 test('a map', () => _expectKeyWorks(() => {'foo': 'bar'})); | 53 test('a map', () => _expectKeyWorks(() => {'foo': 'bar'})); |
| 54 test('a YAML map', () => _expectKeyWorks(() => yamlMap({'foo': 'bar'}))); | 54 test('a YAML map', () => _expectKeyWorks(() => yamlMap({'foo': 'bar'}))); |
| 55 }); | 55 }); |
| 56 | 56 |
| 57 test('works as a hash key', () { | 57 test('works as a hash key', () { |
| 58 var normalMap = new Map(); | 58 var normalMap = new Map(); |
| 59 normalMap[yamlMap({'foo': 'bar'})] = 'baz'; | 59 normalMap[yamlMap({'foo': 'bar'})] = 'baz'; |
| 60 Expect.isTrue(normalMap.containsKey(yamlMap({'foo': 'bar'}))); | 60 Expect.isTrue(normalMap.containsKey(yamlMap({'foo': 'bar'}))); |
| 61 Expect.equals('baz', normalMap[yamlMap({'foo': 'bar'})]); | 61 Expect.equals('baz', normalMap[yamlMap({'foo': 'bar'})]); |
| 62 }); | 62 }); |
| 63 |
| 64 test('treats YamlMap keys the same as normal maps', () { |
| 65 var map = yamlMap(); |
| 66 map[{'a': 'b'}] = 5; |
| 67 Expect.equals(5, map[yamlMap({'a': 'b'})]); |
| 68 }); |
| 63 }); | 69 }); |
| 64 | 70 |
| 65 // The following tests are all taken directly from the YAML spec | 71 // The following tests are all taken directly from the YAML spec |
| 66 // (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples | 72 // (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples |
| 67 // that are directly included in the spec, but additional tests are derived | 73 // that are directly included in the spec, but additional tests are derived |
| 68 // from the prose. | 74 // from the prose. |
| 69 | 75 |
| 70 // A few examples from the spec are deliberately excluded, because they test | 76 // A few examples from the spec are deliberately excluded, because they test |
| 71 // features that this implementation doesn't intend to support (character | 77 // features that this implementation doesn't intend to support (character |
| 72 // encoding detection and user-defined tags). More tests are commented out, | 78 // encoding detection and user-defined tags). More tests are commented out, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 - | 123 - |
| 118 name: Mark McGwire | 124 name: Mark McGwire |
| 119 hr: 65 | 125 hr: 65 |
| 120 avg: 0.278 | 126 avg: 0.278 |
| 121 - | 127 - |
| 122 name: Sammy Sosa | 128 name: Sammy Sosa |
| 123 hr: 63 | 129 hr: 63 |
| 124 avg: 0.288"""); | 130 avg: 0.288"""); |
| 125 }); | 131 }); |
| 126 | 132 |
| 127 // test('[Example 2.5]', () { | 133 test('[Example 2.5]', () { |
| 128 // expectYamlLoads([ | 134 expectYamlLoads([ |
| 129 // ["name", "hr", "avg"], | 135 ["name", "hr", "avg"], |
| 130 // ["Mark McGwire", 65, 0.278], | 136 ["Mark McGwire", 65, 0.278], |
| 131 // ["Sammy Sosa", 63, 0.288] | 137 ["Sammy Sosa", 63, 0.288] |
| 132 // ], | 138 ], |
| 133 // """ | 139 """ |
| 134 // - [name , hr, avg ] | 140 - [name , hr, avg ] |
| 135 // - [Mark McGwire, 65, 0.278] | 141 - [Mark McGwire, 65, 0.278] |
| 136 // - [Sammy Sosa , 63, 0.288]"""); | 142 - [Sammy Sosa , 63, 0.288]"""); |
| 137 // }); | 143 }); |
| 138 | 144 |
| 139 // test('[Example 2.6]', () { | 145 test('[Example 2.6]', () { |
| 140 // expectYamlLoads({ | 146 expectYamlLoads({ |
| 141 // "Mark McGwire": {"hr": 65, "avg": 0.278}, | 147 "Mark McGwire": {"hr": 65, "avg": 0.278}, |
| 142 // "Sammy Sosa": {"hr": 63, "avg": 0.288} | 148 "Sammy Sosa": {"hr": 63, "avg": 0.288} |
| 143 // }, | 149 }, |
| 144 // """ | 150 """ |
| 145 // Mark McGwire: {hr: 65, avg: 0.278} | 151 Mark McGwire: {hr: 65, avg: 0.278} |
| 146 // Sammy Sosa: { | 152 Sammy Sosa: { |
| 147 // hr: 63, | 153 hr: 63, |
| 148 // avg: 0.288 | 154 avg: 0.288 |
| 149 // }"""); | 155 }"""); |
| 150 // }); | 156 }); |
| 151 }); | 157 }); |
| 152 | 158 |
| 153 group('2.2: Structures', () { | 159 group('2.2: Structures', () { |
| 154 test('[Example 2.7]', () { | 160 test('[Example 2.7]', () { |
| 155 expectYamlStreamLoads([ | 161 expectYamlStreamLoads([ |
| 156 ["Mark McGwire", "Sammy Sosa", "Ken Griffey"], | 162 ["Mark McGwire", "Sammy Sosa", "Ken Griffey"], |
| 157 ["Chicago Cubs", "St Louis Cardinals"] | 163 ["Chicago Cubs", "St Louis Cardinals"] |
| 158 ], | 164 ], |
| 159 """ | 165 """ |
| 160 # Ranking of 1998 home runs | 166 # Ranking of 1998 home runs |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // --- | 218 // --- |
| 213 // hr: | 219 // hr: |
| 214 // - Mark McGwire | 220 // - Mark McGwire |
| 215 // # Following node labeled SS | 221 // # Following node labeled SS |
| 216 // - &SS Sammy Sosa | 222 // - &SS Sammy Sosa |
| 217 // rbi: | 223 // rbi: |
| 218 // - *SS # Subsequent occurrence | 224 // - *SS # Subsequent occurrence |
| 219 // - Ken Griffey"""); | 225 // - Ken Griffey"""); |
| 220 // }); | 226 // }); |
| 221 | 227 |
| 222 // test('[Example 2.11]', () { | 228 test('[Example 2.11]', () { |
| 223 // var doc = yamlMap(); | 229 var doc = yamlMap(); |
| 224 // doc[["Detroit Tigers", "Chicago cubs"]] = ["2001-07-23"]; | 230 doc[["Detroit Tigers", "Chicago cubs"]] = ["2001-07-23"]; |
| 225 // doc[["New York Yankees", "Atlanta Braves"]] = | 231 doc[["New York Yankees", "Atlanta Braves"]] = |
| 226 // ["2001-07-02", "2001-08-12", "2001-08-14"]; | 232 ["2001-07-02", "2001-08-12", "2001-08-14"]; |
| 227 // expectYamlLoads(doc, | 233 expectYamlLoads(doc, |
| 228 // """ | 234 """ |
| 229 // ? - Detroit Tigers | 235 ? - Detroit Tigers |
| 230 // - Chicago cubs | 236 - Chicago cubs |
| 231 // : | 237 : |
| 232 // - 2001-07-23 | 238 - 2001-07-23 |
| 233 | 239 |
| 234 // ? [ New York Yankees, | 240 ? [ New York Yankees, |
| 235 // Atlanta Braves ] | 241 Atlanta Braves ] |
| 236 // : [ 2001-07-02, 2001-08-12, | 242 : [ 2001-07-02, 2001-08-12, |
| 237 // 2001-08-14 ]"""); | 243 2001-08-14 ]"""); |
| 238 // }); | 244 }); |
| 239 | 245 |
| 240 test('[Example 2.12]', () { | 246 test('[Example 2.12]', () { |
| 241 expectYamlLoads([ | 247 expectYamlLoads([ |
| 242 {"item": "Super Hoop", "quantity": 1}, | 248 {"item": "Super Hoop", "quantity": 1}, |
| 243 {"item": "Basketball", "quantity": 4}, | 249 {"item": "Basketball", "quantity": 4}, |
| 244 {"item": "Big Shoes", "quantity": 1}, | 250 {"item": "Big Shoes", "quantity": 1}, |
| 245 ], | 251 ], |
| 246 """ | 252 """ |
| 247 --- | 253 --- |
| 248 # Products purchased | 254 # Products purchased |
| 249 - item : Super Hoop | 255 - item : Super Hoop |
| 250 quantity: 1 | 256 quantity: 1 |
| 251 - item : Basketball | 257 - item : Basketball |
| 252 quantity: 4 | 258 quantity: 4 |
| 253 - item : Big Shoes | 259 - item : Big Shoes |
| 254 quantity: 1"""); | 260 quantity: 1"""); |
| 255 }); | 261 }); |
| 256 }); | 262 }); |
| 257 | 263 |
| 258 group('2.3: Scalars', () { | 264 group('2.3: Scalars', () { |
| 259 // test('[Example 2.13]', () { | 265 test('[Example 2.13]', () { |
| 260 // expectYamlLoads( | 266 expectYamlLoads( |
| 261 // cleanUpLiteral( | 267 cleanUpLiteral( |
| 262 // """ | 268 """ |
| 263 // \//||\\/|| | 269 \\//||\\/|| |
| 264 // // || ||__"""), | 270 // || ||__"""), |
| 265 // """ | 271 """ |
| 266 // # ASCII Art | 272 # ASCII Art |
| 267 // --- | | 273 --- | |
| 268 // \//||\\/|| | 274 \\//||\\/|| |
| 269 // // || ||__"""); | 275 // || ||__"""); |
| 270 // }); | 276 }); |
| 271 | 277 |
| 272 // test('[Example 2.14]', () { | 278 test('[Example 2.14]', () { |
| 273 // expectYamlLoads("Mark McGwire's year was crippled by a knee injury.", | 279 expectYamlLoads("Mark McGwire's year was crippled by a knee injury.", |
| 274 // """ | 280 """ |
| 275 // --- > | 281 --- > |
| 276 // Mark McGwire's | 282 Mark McGwire's |
| 277 // year was crippled | 283 year was crippled |
| 278 // by a knee injury."""); | 284 by a knee injury."""); |
| 279 // }); | 285 }); |
| 280 | 286 |
| 281 // test('[Example 2.15]', () { | 287 test('[Example 2.15]', () { |
| 282 // expectYamlLoads | 288 expectYamlLoads( |
| 283 // cleanUpLiteral( | 289 cleanUpLiteral( |
| 284 // """ | 290 """ |
| 285 // Sammy Sosa completed another | 291 Sammy Sosa completed another fine season with great stats. |
| 286 // fine season with great stats. | |
| 287 | 292 |
| 288 // 63 Home Runs | 293 63 Home Runs |
| 289 // 0.288 Batting Average | 294 0.288 Batting Average |
| 290 | 295 |
| 291 // What a year!"""), | 296 What a year!"""), |
| 292 // """ | 297 """ |
| 293 // > | 298 > |
| 294 // Sammy Sosa completed another | 299 Sammy Sosa completed another |
| 295 // fine season with great stats. | 300 fine season with great stats. |
| 296 | 301 |
| 297 // 63 Home Runs | 302 63 Home Runs |
| 298 // 0.288 Batting Average | 303 0.288 Batting Average |
| 299 | 304 |
| 300 // What a year!"""); | 305 What a year!"""); |
| 301 // }); | 306 }); |
| 302 | 307 |
| 303 // test('[Example 2.16]', () { | 308 test('[Example 2.16]', () { |
| 304 // expectYamlLoads({ | 309 expectYamlLoads({ |
| 305 // "name": "Mark McGwire", | 310 "name": "Mark McGwire", |
| 306 // "accomplishment": "Mark set a major league home run record in 1998.", | 311 "accomplishment": "Mark set a major league home run record in 1998.\n", |
| 307 // "stats": "65 Home Runs\n0.278 Batting Average" | 312 "stats": "65 Home Runs\n0.278 Batting Average" |
| 308 // }, | 313 }, |
| 309 // """ | 314 """ |
| 310 // name: Mark McGwire | 315 name: Mark McGwire |
| 311 // accomplishment: > | 316 accomplishment: > |
| 312 // Mark set a major league | 317 Mark set a major league |
| 313 // home run record in 1998. | 318 home run record in 1998. |
| 314 // stats: | | 319 stats: | |
| 315 // 65 Home Runs | 320 65 Home Runs |
| 316 // 0.278 Batting Average"""); | 321 0.278 Batting Average"""); |
| 317 // }); | 322 }); |
| 318 | 323 |
| 319 // test('[Example 2.17]', () { | 324 test('[Example 2.17]', () { |
| 320 // expectYamlLoads({ | 325 expectYamlLoads({ |
| 321 // "unicode": "Sosa did fine.\u263A", | 326 "unicode": "Sosa did fine.\u263A", |
| 322 // "control": "\b1998\t1999\t2000\n", | 327 "control": "\b1998\t1999\t2000\n", |
| 323 // "hex esc": "\r\n is \r\n", | 328 "hex esc": "\r\n is \r\n", |
| 324 // "single": '"Howdy!" he cried.', | 329 "single": '"Howdy!" he cried.', |
| 325 // "quoted": " # Not a 'comment'.", | 330 "quoted": " # Not a 'comment'.", |
| 326 // "tie-fighter": "|\-*-/|" | 331 "tie-fighter": "|\\-*-/|" |
| 327 // }, | 332 }, |
| 328 // """ | 333 """ |
| 329 // unicode: "Sosa did fine.\\u263A" | 334 unicode: "Sosa did fine.\\u263A" |
| 330 // control: "\\b1998\\t1999\\t2000\\n" | 335 control: "\\b1998\\t1999\\t2000\\n" |
| 331 // hex esc: "\\x0d\\x0a is \\r\\n" | 336 hex esc: "\\x0d\\x0a is \\r\\n" |
| 332 | 337 |
| 333 // single: '"Howdy!" he cried.' | 338 single: '"Howdy!" he cried.' |
| 334 // quoted: ' # Not a ''comment''.' | 339 quoted: ' # Not a ''comment''.' |
| 335 // tie-fighter: '|\\-*-/|'"""); | 340 tie-fighter: '|\\-*-/|'"""); |
| 336 // }); | 341 }); |
| 337 | 342 |
| 338 // test('[Example 2.18]', () { | 343 test('[Example 2.18]', () { |
| 339 // expectYamlLoads({ | 344 expectYamlLoads({ |
| 340 // "plain": "This unquoted scalar spans many lines.", | 345 "plain": "This unquoted scalar spans many lines.", |
| 341 // "quoted": "So does this quoted scalar.\n" | 346 "quoted": "So does this quoted scalar.\n" |
| 342 // }, | 347 }, |
| 343 // ''' | 348 ''' |
| 344 // plain: | 349 plain: |
| 345 // This unquoted scalar | 350 This unquoted scalar |
| 346 // spans many lines. | 351 spans many lines. |
| 347 | 352 |
| 348 // quoted: "So does this | 353 quoted: "So does this |
| 349 // quoted scalar.\\n"'''); | 354 quoted scalar.\\n"'''); |
| 350 // }); | 355 }); |
| 351 }); | 356 }); |
| 352 | 357 |
| 353 group('2.4: Tags', () { | 358 group('2.4: Tags', () { |
| 354 test('[Example 2.19]', () { | 359 test('[Example 2.19]', () { |
| 355 expectYamlLoads({ | 360 expectYamlLoads({ |
| 356 "canonical": 12345, | 361 "canonical": 12345, |
| 357 "decimal": 12345, | 362 "decimal": 12345, |
| 358 "octal": 12, | 363 "octal": 12, |
| 359 "hexadecimal": 12 | 364 "hexadecimal": 12 |
| 360 }, | 365 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 374 "not a number": nan | 379 "not a number": nan |
| 375 }, | 380 }, |
| 376 """ | 381 """ |
| 377 canonical: 1.23015e+3 | 382 canonical: 1.23015e+3 |
| 378 exponential: 12.3015e+02 | 383 exponential: 12.3015e+02 |
| 379 fixed: 1230.15 | 384 fixed: 1230.15 |
| 380 negative infinity: -.inf | 385 negative infinity: -.inf |
| 381 not a number: .NaN"""); | 386 not a number: .NaN"""); |
| 382 }); | 387 }); |
| 383 | 388 |
| 384 // test('[Example 2.21]', () { | 389 test('[Example 2.21]', () { |
| 385 // var doc = yamlMap({ | 390 var doc = yamlMap({ |
| 386 // "booleans": [true, false], | 391 "booleans": [true, false], |
| 387 // "string": "012345" | 392 "string": "012345" |
| 388 // }); | 393 }); |
| 389 // doc[null] = null; | 394 doc[null] = null; |
| 390 // expectYamlLoads(doc, | 395 expectYamlLoads(doc, |
| 391 // """ | 396 """ |
| 392 // null: | 397 null: |
| 393 // booleans: [ true, false ] | 398 booleans: [ true, false ] |
| 394 // string: '012345'"""); | 399 string: '012345'"""); |
| 395 // }); | 400 }); |
| 396 | 401 |
| 397 // Examples 2.22 through 2.26 test custom tag URIs, which this | 402 // Examples 2.22 through 2.26 test custom tag URIs, which this |
| 398 // implementation currently doesn't plan to support. | 403 // implementation currently doesn't plan to support. |
| 399 }); | 404 }); |
| 400 | 405 |
| 401 group('2.5 Full Length Example', () { | 406 group('2.5 Full Length Example', () { |
| 402 // Example 2.27 tests custom tag URIs, which this implementation currently | 407 // Example 2.27 tests custom tag URIs, which this implementation currently |
| 403 // doesn't plan to support. | 408 // doesn't plan to support. |
| 404 | 409 |
| 405 // test('[Example 2.28]', () { | 410 test('[Example 2.28]', () { |
| 406 // expectYamlStreamLoads([ | 411 expectYamlStreamLoads([ |
| 407 // { | 412 { |
| 408 // "Time": "2001-11-23 15:01:42 -5", | 413 "Time": "2001-11-23 15:01:42 -5", |
| 409 // "User": "ed", | 414 "User": "ed", |
| 410 // "Warning": "This is an error message for the log file" | 415 "Warning": "This is an error message for the log file" |
| 411 // }, | 416 }, |
| 412 // { | 417 { |
| 413 // "Time": "2001-11-23 15:02:31 -5", | 418 "Time": "2001-11-23 15:02:31 -5", |
| 414 // "User": "ed", | 419 "User": "ed", |
| 415 // "Warning": "A slightly different error message." | 420 "Warning": "A slightly different error message." |
| 416 // }, | 421 }, |
| 417 // { | 422 { |
| 418 // "Date": "2001-11-23 15:03:17 -5", | 423 "Date": "2001-11-23 15:03:17 -5", |
| 419 // "User": "ed", | 424 "User": "ed", |
| 420 // "Fatal": 'Unknown variable "bar"', | 425 "Fatal": 'Unknown variable "bar"', |
| 421 // "Stack": [ | 426 "Stack": [ |
| 422 // { | 427 { |
| 423 // "file": "TopClass.py", | 428 "file": "TopClass.py", |
| 424 // "line": 23, | 429 "line": 23, |
| 425 // "code": 'x = MoreObject("345\n")\n' | 430 "code": 'x = MoreObject("345\\n")\n' |
| 426 // }, | 431 }, |
| 427 // {"file": "MoreClass.py", "line": 58, "code": "foo = bar"} | 432 {"file": "MoreClass.py", "line": 58, "code": "foo = bar"} |
| 428 // ] | 433 ] |
| 429 // } | 434 } |
| 430 // ], | 435 ], |
| 431 // """ | 436 """ |
| 432 // --- | 437 --- |
| 433 // Time: 2001-11-23 15:01:42 -5 | 438 Time: 2001-11-23 15:01:42 -5 |
| 434 // User: ed | 439 User: ed |
| 435 // Warning: | 440 Warning: |
| 436 // This is an error message | 441 This is an error message |
| 437 // for the log file | 442 for the log file |
| 438 // --- | 443 --- |
| 439 // Time: 2001-11-23 15:02:31 -5 | 444 Time: 2001-11-23 15:02:31 -5 |
| 440 // User: ed | 445 User: ed |
| 441 // Warning: | 446 Warning: |
| 442 // A slightly different error | 447 A slightly different error |
| 443 // message. | 448 message. |
| 444 // --- | 449 --- |
| 445 // Date: 2001-11-23 15:03:17 -5 | 450 Date: 2001-11-23 15:03:17 -5 |
| 446 // User: ed | 451 User: ed |
| 447 // Fatal: | 452 Fatal: |
| 448 // Unknown variable "bar" | 453 Unknown variable "bar" |
| 449 // Stack: | 454 Stack: |
| 450 // - file: TopClass.py | 455 - file: TopClass.py |
| 451 // line: 23 | 456 line: 23 |
| 452 // code: | | 457 code: | |
| 453 // x = MoreObject("345\\n") | 458 x = MoreObject("345\\n") |
| 454 // - file: MoreClass.py | 459 - file: MoreClass.py |
| 455 // line: 58 | 460 line: 58 |
| 456 // code: |- | 461 code: |- |
| 457 // foo = bar"""); | 462 foo = bar"""); |
| 458 // }); | 463 }); |
| 459 }); | 464 }); |
| 460 | 465 |
| 461 // Chapter 3 just talks about the structure of loading and dumping Yaml. | 466 // Chapter 3 just talks about the structure of loading and dumping Yaml. |
| 462 // Chapter 4 explains conventions used in the spec. | 467 // Chapter 4 explains conventions used in the spec. |
| 463 | 468 |
| 464 // Chapter 5: Characters | 469 // Chapter 5: Characters |
| 465 group('5.1: Character Set', () { | 470 group('5.1: Character Set', () { |
| 466 expectAllowsCharacter(int charCode) { | 471 expectAllowsCharacter(int charCode) { |
| 467 var char = new String.fromCharCodes([charCode]); | 472 var char = new String.fromCharCodes([charCode]); |
| 468 expectYamlLoads('The character "$char" is allowed', | 473 expectYamlLoads('The character "$char" is allowed', |
| (...skipping 22 matching lines...) Expand all Loading... |
| 491 | 496 |
| 492 test("doesn't include C1 control characters", () { | 497 test("doesn't include C1 control characters", () { |
| 493 expectDisallowsCharacter(0x80); | 498 expectDisallowsCharacter(0x80); |
| 494 expectDisallowsCharacter(0x8A); | 499 expectDisallowsCharacter(0x8A); |
| 495 expectDisallowsCharacter(0x9F); | 500 expectDisallowsCharacter(0x9F); |
| 496 }); | 501 }); |
| 497 | 502 |
| 498 test("includes NEL", () => expectAllowsCharacter(0x85)); | 503 test("includes NEL", () => expectAllowsCharacter(0x85)); |
| 499 | 504 |
| 500 group("within quoted strings", () { | 505 group("within quoted strings", () { |
| 501 // test("includes DEL", () => expectAllowsQuotedCharacter(0x7F)); | 506 test("includes DEL", () => expectAllowsQuotedCharacter(0x7F)); |
| 502 // test("includes C1 control characters", () { | 507 test("includes C1 control characters", () { |
| 503 // expectAllowsQuotedCharacter(0x80); | 508 expectAllowsQuotedCharacter(0x80); |
| 504 // expectAllowsQuotedCharacter(0x8A); | 509 expectAllowsQuotedCharacter(0x8A); |
| 505 // expectAllowsQuotedCharacter(0x9F); | 510 expectAllowsQuotedCharacter(0x9F); |
| 506 // }); | 511 }); |
| 507 }); | 512 }); |
| 508 }); | 513 }); |
| 509 | 514 |
| 510 // Skipping section 5.2 (Character Encodings), since at the moment the module | 515 // Skipping section 5.2 (Character Encodings), since at the moment the module |
| 511 // assumes that the client code is providing it with a string of the proper | 516 // assumes that the client code is providing it with a string of the proper |
| 512 // encoding. | 517 // encoding. |
| 513 | 518 |
| 514 group('5.3: Indicator Characters', () { | 519 group('5.3: Indicator Characters', () { |
| 515 // test('[Example 5.3]', () { | 520 test('[Example 5.3]', () { |
| 516 // expectYamlLoads({ | 521 expectYamlLoads({ |
| 517 // 'sequence': ['one', 'two'], | 522 'sequence': ['one', 'two'], |
| 518 // 'mapping': {'sky': 'blue', 'sea': 'green'} | 523 'mapping': {'sky': 'blue', 'sea': 'green'} |
| 519 // }, | 524 }, |
| 520 // """ | 525 """ |
| 521 // sequence: | 526 sequence: |
| 522 // - one | 527 - one |
| 523 // - two | 528 - two |
| 524 // mapping: | 529 mapping: |
| 525 // ? sky | 530 ? sky |
| 526 // : blue | 531 : blue |
| 527 // sea : green"""); | 532 sea : green"""); |
| 528 // }); | 533 }); |
| 529 | 534 |
| 530 // test('[Example 5.4]', () { | 535 test('[Example 5.4]', () { |
| 531 // expectYamlLoads({ | 536 expectYamlLoads({ |
| 532 // 'sequence': ['one', 'two'], | 537 'sequence': ['one', 'two'], |
| 533 // 'mapping': {'sky': 'blue', 'sea': 'green'} | 538 'mapping': {'sky': 'blue', 'sea': 'green'} |
| 534 // }, | 539 }, |
| 535 // """ | 540 """ |
| 536 // sequence: [ one, two, ] | 541 sequence: [ one, two, ] |
| 537 // mapping: { sky: blue, sea: green }"""); | 542 mapping: { sky: blue, sea: green }"""); |
| 538 // }); | 543 }); |
| 539 | 544 |
| 540 test('[Example 5.5]', () => expectYamlLoads(null, "# Comment only.")); | 545 test('[Example 5.5]', () => expectYamlLoads(null, "# Comment only.")); |
| 541 | 546 |
| 542 // Skipping 5.6 because it uses an undefined tag. | 547 // Skipping 5.6 because it uses an undefined tag. |
| 543 | 548 |
| 544 // test('[Example 5.7]', () { | 549 test('[Example 5.7]', () { |
| 545 // expectYamlLoads({ | 550 expectYamlLoads({ |
| 546 // 'literal': "some text\n", | 551 'literal': "some\ntext\n", |
| 547 // 'folded': "some\ntext\n" | 552 'folded': "some text\n" |
| 548 // }, | 553 }, |
| 549 // """ | 554 """ |
| 550 // literal: | | 555 literal: | |
| 551 // some | 556 some |
| 552 // text | 557 text |
| 553 // folded: > | 558 folded: > |
| 554 // some | 559 some |
| 555 // text"""); | 560 text |
| 556 // }); | 561 """); |
| 562 }); |
| 557 | 563 |
| 558 // test('[Example 5.8]', () { | 564 test('[Example 5.8]', () { |
| 559 // expectYamlLoads({ | 565 expectYamlLoads({ |
| 560 // 'single': "text", | 566 'single': "text", |
| 561 // 'double': "text" | 567 'double': "text" |
| 562 // }, | 568 }, |
| 563 // """ | 569 """ |
| 564 // single: 'text' | 570 single: 'text' |
| 565 // double: "text" | 571 double: "text" |
| 566 // """); | 572 """); |
| 567 // }); | 573 }); |
| 568 | 574 |
| 569 // test('[Example 5.9]', () { | 575 // test('[Example 5.9]', () { |
| 570 // expectYamlLoads("text", | 576 // expectYamlLoads("text", |
| 571 // """ | 577 // """ |
| 572 // %YAML 1.2 | 578 // %YAML 1.2 |
| 573 // --- text"""); | 579 // --- text"""); |
| 574 // }); | 580 // }); |
| 575 | 581 |
| 576 // test('[Example 5.10]', () { | 582 test('[Example 5.10]', () { |
| 577 // Expect.throws(() => loadYaml("commercial-at: @text")); | 583 Expect.throws(() => loadYaml("commercial-at: @text")); |
| 578 // Expect.throws(() => loadYaml("commercial-at: `text")); | 584 Expect.throws(() => loadYaml("commercial-at: `text")); |
| 579 // }); | 585 }); |
| 580 }); | 586 }); |
| 581 | 587 |
| 582 group('5.4: Line Break Characters', () { | 588 group('5.4: Line Break Characters', () { |
| 583 group('include', () { | 589 group('include', () { |
| 584 test('\\n', () => expectYamlLoads([1, 2], indentLiteral("- 1\n- 2"))); | 590 test('\\n', () => expectYamlLoads([1, 2], indentLiteral("- 1\n- 2"))); |
| 585 test('\\r', () => expectYamlLoads([1, 2], "- 1\r- 2")); | 591 test('\\r', () => expectYamlLoads([1, 2], "- 1\r- 2")); |
| 586 }); | 592 }); |
| 587 | 593 |
| 588 group('do not include', () { | 594 group('do not include', () { |
| 589 test('form feed', () => Expect.throws(() => loadYaml("- 1\x0C- 2"))); | 595 test('form feed', () => Expect.throws(() => loadYaml("- 1\x0C- 2"))); |
| 590 test('NEL', () => expectYamlLoads(["1\x85- 2"], "- 1\x85- 2")); | 596 test('NEL', () => expectYamlLoads(["1\x85- 2"], "- 1\x85- 2")); |
| 591 test('0x2028', () => expectYamlLoads(["1\u2028- 2"], "- 1\u2028- 2")); | 597 test('0x2028', () => expectYamlLoads(["1\u2028- 2"], "- 1\u2028- 2")); |
| 592 test('0x2029', () => expectYamlLoads(["1\u2029- 2"], "- 1\u2029- 2")); | 598 test('0x2029', () => expectYamlLoads(["1\u2029- 2"], "- 1\u2029- 2")); |
| 593 }); | 599 }); |
| 594 | 600 |
| 595 // group('in a scalar context must be normalized', () { | 601 group('in a scalar context must be normalized', () { |
| 596 // test("from \\r to \\n", () => | 602 test("from \\r to \\n", () => |
| 597 // expectYamlLoads("foo\nbar", indentLiteral('- |\n foo\r bar'))); | 603 expectYamlLoads(["foo\nbar"], indentLiteral('- |\n foo\r bar'))); |
| 598 // test("from \\r\\n to \\n", () => | 604 test("from \\r\\n to \\n", () => |
| 599 // expectYamlLoads("foo\nbar", indentLiteral('- |\n foo\r\n bar'))
); | 605 expectYamlLoads(["foo\nbar"], indentLiteral('- |\n foo\r\n bar')))
; |
| 600 // }); | 606 }); |
| 601 | 607 |
| 602 // test('[Example 5.11]', () { | 608 test('[Example 5.11]', () { |
| 603 // expectYamlLoads | 609 expectYamlLoads( |
| 604 // cleanUpLiteral(""" | 610 cleanUpLiteral(""" |
| 605 // Line break (no glyph) | 611 Line break (no glyph) |
| 606 // Line break (glyphed)"""), | 612 Line break (glyphed)"""), |
| 607 // """ | 613 """ |
| 608 // | | 614 | |
| 609 // Line break (no glyph) | 615 Line break (no glyph) |
| 610 // Line break (glyphed)"""); | 616 Line break (glyphed)"""); |
| 611 // }); | 617 }); |
| 612 }); | 618 }); |
| 613 | 619 |
| 614 group('5.5: White Space Characters', () { | 620 group('5.5: White Space Characters', () { |
| 615 // test('[Example 5.12]', () { | 621 test('[Example 5.12]', () { |
| 616 // expectYamlLoads({ | 622 expectYamlLoads({ |
| 617 // "quoted": "Quoted \t", | 623 "quoted": "Quoted \t", |
| 618 // "block": 'void main() {\n\tprintf("Hello, world!\\n");\n}\n' | 624 "block": 'void main() {\n\tprintf("Hello, world!\\n");\n}\n' |
| 619 // }, | 625 }, |
| 620 // """ | 626 """ |
| 621 // # Tabs and spaces | 627 # Tabs and spaces |
| 622 // quoted: "Quoted \t" | 628 quoted: "Quoted \t" |
| 623 // block:\t| | 629 block:\t| |
| 624 // void main() { | 630 void main() { |
| 625 // \tprintf("Hello, world!\\n"); | 631 \tprintf("Hello, world!\\n"); |
| 626 // }"""); | 632 } |
| 627 // }); | 633 """); |
| 634 }); |
| 628 }); | 635 }); |
| 629 | 636 |
| 630 group('5.7: Escaped Characters', () { | 637 group('5.7: Escaped Characters', () { |
| 631 // test('[Example 5.13]', () { | 638 test('[Example 5.13]', () { |
| 632 // expectYamlLoads | 639 expectYamlLoads( |
| 633 // expectYamlLoads(""" | 640 "Fun with \x5C " |
| 634 // Fun with \x5C | 641 "\x22 \x07 \x08 \x1B \x0C " |
| 635 // \x22 \x07 \x08 \x1B \x0C | 642 "\x0A \x0D \x09 \x0B \x00 " |
| 636 // \x0A \x0D \x09 \x0B \x00 | 643 "\x20 \xA0 \x85 \u2028 \u2029 " |
| 637 // \x20 \xA0 \x85 \u2028 \u2029 | 644 "A A A", |
| 638 // A A A"""), | 645 ''' |
| 639 // ''' | 646 "Fun with \\\\ |
| 640 // "Fun with \\\\ | 647 \\" \\a \\b \\e \\f \\ |
| 641 // \\" \\a \\b \\e \\f \\ | 648 \\n \\r \\t \\v \\0 \\ |
| 642 // \\n \\r \\t \\v \\0 \\ | 649 \\ \\_ \\N \\L \\P \\ |
| 643 // \\ \\_ \\N \\L \\P \\ | 650 \\x41 \\u0041 \\U00000041"'''); |
| 644 // \\x41 \\u0041 \\U00000041"'''); | 651 }); |
| 645 // }); | |
| 646 | 652 |
| 647 // test('[Example 5.14]', () { | 653 test('[Example 5.14]', () { |
| 648 // Expect.throws(() => loadYaml('Bad escape: "\\c"')); | 654 Expect.throws(() => loadYaml('Bad escape: "\\c"')); |
| 649 // Expect.throws(() => loadYaml('Bad escape: "\\xq-"')); | 655 Expect.throws(() => loadYaml('Bad escape: "\\xq-"')); |
| 650 // }); | 656 }); |
| 651 }); | 657 }); |
| 652 | 658 |
| 653 // Chapter 6: Basic Structures | 659 // Chapter 6: Basic Structures |
| 654 group('6.1: Indentation Spaces', () { | 660 group('6.1: Indentation Spaces', () { |
| 655 test('may not include TAB characters', () { | 661 test('may not include TAB characters', () { |
| 656 Expect.throws(() => loadYaml(cleanUpLiteral( | 662 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 657 """ | 663 """ |
| 658 - | 664 - |
| 659 \t- foo | 665 \t- foo |
| 660 \t- bar"""))); | 666 \t- bar"""))); |
| 661 }); | 667 }); |
| 662 | 668 |
| 663 test('must be the same for all sibling nodes', () { | 669 test('must be the same for all sibling nodes', () { |
| 664 Expect.throws(() => loadYaml(cleanUpLiteral( | 670 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 665 """ | 671 """ |
| 666 - | 672 - |
| 667 - foo | 673 - foo |
| 668 - bar"""))); | 674 - bar"""))); |
| 669 }); | 675 }); |
| 670 | 676 |
| 671 test('may be different for the children of sibling nodes', () { | 677 test('may be different for the children of sibling nodes', () { |
| 672 expectYamlLoads([["foo"], ["bar"]], | 678 expectYamlLoads([["foo"], ["bar"]], |
| 673 """ | 679 """ |
| 674 - | 680 - |
| 675 - foo | 681 - foo |
| 676 - | 682 - |
| 677 - bar"""); | 683 - bar"""); |
| 678 }); | 684 }); |
| 679 | 685 |
| 680 // test('[Example 6.1]', () { | 686 test('[Example 6.1]', () { |
| 681 // expectYamlLoads({ | 687 expectYamlLoads({ |
| 682 // "Not indented": { | 688 "Not indented": { |
| 683 // "By one space": "By four\n spaces\n", | 689 "By one space": "By four\n spaces\n", |
| 684 // "Flow style": [ | 690 "Flow style": [ |
| 685 // "By two", | 691 "By two", |
| 686 // "Also by two", | 692 "Also by two", |
| 687 // "Still by two" | 693 "Still by two" |
| 688 // ] | 694 ] |
| 689 // } | 695 } |
| 690 // }, | 696 }, |
| 691 // """ | 697 """ |
| 692 // # Leading comment line spaces are | 698 # Leading comment line spaces are |
| 693 // # neither content nor indentation. | 699 # neither content nor indentation. |
| 694 | 700 |
| 695 // Not indented: | 701 Not indented: |
| 696 // By one space: | | 702 By one space: | |
| 697 // By four | 703 By four |
| 698 // spaces | 704 spaces |
| 699 // Flow style: [ # Leading spaces | 705 Flow style: [ # Leading spaces |
| 700 // By two, # in flow style | 706 By two, # in flow style |
| 701 // Also by two, # are neither | 707 Also by two, # are neither |
| 702 // \tStill by two # content nor | 708 \tStill by two # content nor |
| 703 // ] # indentation."""); | 709 ] # indentation."""); |
| 704 // }); | 710 }); |
| 705 | 711 |
| 706 // test('[Example 6.2]', () { | 712 test('[Example 6.2]', () { |
| 707 // expectYamlLoads({'a': ['b', ['c', 'd']]}, | 713 expectYamlLoads({'a': ['b', ['c', 'd']]}, |
| 708 // """ | 714 """ |
| 709 // ? a | 715 ? a |
| 710 // : -\tb | 716 : -\tb |
| 711 // - -\tc | 717 - -\tc |
| 712 // - d"""); | 718 - d"""); |
| 713 // }); | 719 }); |
| 714 }); | 720 }); |
| 715 | 721 |
| 716 group('6.2: Separation Spaces', () { | 722 group('6.2: Separation Spaces', () { |
| 717 test('[Example 6.3]', () { | 723 test('[Example 6.3]', () { |
| 718 expectYamlLoads([{'foo': 'bar'}, ['baz', 'baz']], | 724 expectYamlLoads([{'foo': 'bar'}, ['baz', 'baz']], |
| 719 """ | 725 """ |
| 720 - foo:\t bar | 726 - foo:\t bar |
| 721 - - baz | 727 - - baz |
| 722 -\tbaz"""); | 728 -\tbaz"""); |
| 723 }); | 729 }); |
| 724 }); | 730 }); |
| 725 | 731 |
| 726 group('6.3: Line Prefixes', () { | 732 group('6.3: Line Prefixes', () { |
| 727 // test('[Example 6.4]', () { | 733 test('[Example 6.4]', () { |
| 728 // expectYamlLoads({ | 734 expectYamlLoads({ |
| 729 // "plain": "text lines", | 735 "plain": "text lines", |
| 730 // "quoted": "text lines", | 736 "quoted": "text lines", |
| 731 // "block": "text\n \tlines\n" | 737 "block": "text\n \tlines\n" |
| 732 // }, | 738 }, |
| 733 // """ | 739 """ |
| 734 // plain: text | 740 plain: text |
| 735 // lines | 741 lines |
| 736 // quoted: "text | 742 quoted: "text |
| 737 // \tlines" | 743 \tlines" |
| 738 // block: | | 744 block: | |
| 739 // text | 745 text |
| 740 // \tlines"""); | 746 \tlines |
| 741 // }); | 747 """); |
| 748 }); |
| 742 }); | 749 }); |
| 743 | 750 |
| 744 group('6.4: Empty Lines', () { | 751 group('6.4: Empty Lines', () { |
| 745 // test('[Example 6.5]', () { | 752 test('[Example 6.5]', () { |
| 746 // expectYamlLoads({ | 753 expectYamlLoads({ |
| 747 // "Folding": "Empty line\nas a line feed", | 754 "Folding": "Empty line\nas a line feed", |
| 748 // "Chomping": "Clipped empty lines\n", | 755 "Chomping": "Clipped empty lines\n", |
| 749 // }, | 756 }, |
| 750 // """ | 757 """ |
| 751 // Folding: | 758 Folding: |
| 752 // "Empty line | 759 "Empty line |
| 753 // \t | 760 \t |
| 754 // as a line feed" | 761 as a line feed" |
| 755 // Chomping: | | 762 Chomping: | |
| 756 // Clipped empty lines | 763 Clipped empty lines |
| 757 // """); | 764 """); |
| 758 // }); | 765 }); |
| 759 }); | 766 }); |
| 760 | 767 |
| 761 group('6.5: Line Folding', () { | 768 group('6.5: Line Folding', () { |
| 762 // test('[Example 6.6]', () { | 769 test('[Example 6.6]', () { |
| 763 // expectYamlLoads("trimmed\n\n\nas space", | 770 expectYamlLoads("trimmed\n\n\nas space", |
| 764 // """ | 771 """ |
| 765 // >- | 772 >- |
| 766 // trimmed | 773 trimmed |
| 767 | 774 |
| 768 | 775 |
| 769 | 776 |
| 770 // as | 777 as |
| 771 // space"""); | 778 space |
| 772 // }); | 779 """); |
| 780 }); |
| 773 | 781 |
| 774 // test('[Example 6.7]', () { | 782 test('[Example 6.7]', () { |
| 775 // expectYamlLoads("foo \n\n\t bar\n\nbaz\n", | 783 expectYamlLoads("foo \n\n\t bar\n\nbaz\n", |
| 776 // """ | 784 """ |
| 777 // > | 785 > |
| 778 // foo | 786 foo |
| 779 | 787 |
| 780 // \t bar | 788 \t bar |
| 781 | 789 |
| 782 // baz"""); | 790 baz |
| 783 // }); | 791 """); |
| 792 }); |
| 784 | 793 |
| 785 // test('[Example 6.8]', () { | 794 test('[Example 6.8]', () { |
| 786 // expectYamlLoads(" foo\nbar\nbaz ", | 795 expectYamlLoads(" foo\nbar\nbaz ", |
| 787 // """ | 796 ''' |
| 788 // " | 797 " |
| 789 // foo | 798 foo |
| 790 | 799 |
| 791 // \t bar | 800 \t bar |
| 792 | 801 |
| 793 // baz | 802 baz |
| 794 // "'''); | 803 "'''); |
| 795 // }); | 804 }); |
| 796 }); | 805 }); |
| 797 | 806 |
| 798 group('6.6: Comments', () { | 807 group('6.6: Comments', () { |
| 799 test('must be separated from other tokens by white space characters', () { | 808 test('must be separated from other tokens by white space characters', () { |
| 800 expectYamlLoads("foo#bar", "foo#bar"); | 809 expectYamlLoads("foo#bar", "foo#bar"); |
| 801 expectYamlLoads("foo:#bar", "foo:#bar"); | 810 expectYamlLoads("foo:#bar", "foo:#bar"); |
| 802 expectYamlLoads("-#bar", "-#bar"); | 811 expectYamlLoads("-#bar", "-#bar"); |
| 803 }); | 812 }); |
| 804 | 813 |
| 805 test('[Example 6.9]', () { | 814 test('[Example 6.9]', () { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 830 test('include lines containing only white space characters', () { | 839 test('include lines containing only white space characters', () { |
| 831 expectYamlLoads([1, 2], | 840 expectYamlLoads([1, 2], |
| 832 """ | 841 """ |
| 833 - 1 | 842 - 1 |
| 834 \t | 843 \t |
| 835 - 2"""); | 844 - 2"""); |
| 836 }); | 845 }); |
| 837 }); | 846 }); |
| 838 | 847 |
| 839 group('within scalar content', () { | 848 group('within scalar content', () { |
| 840 // test('may not appear on a line of their own', () { | 849 test('may not appear on a line of their own', () { |
| 841 // expectYamlLoads("foo\n# not comment\nbar\n", | 850 expectYamlLoads(["foo\n# not comment\nbar\n"], |
| 842 // """ | 851 """ |
| 843 // - | | 852 - | |
| 844 // foo | 853 foo |
| 845 // # not comment | 854 # not comment |
| 846 // bar"""); | 855 bar |
| 847 // }); | 856 """); |
| 857 }); |
| 848 | 858 |
| 849 // test("don't include lines containing only white space characters", () { | 859 test("don't include lines containing only white space characters", () { |
| 850 // expectYamlLoads("foo\n \t \nbar\n", | 860 expectYamlLoads(["foo\n \t \nbar\n"], |
| 851 // """ | 861 """ |
| 852 // - | | 862 - | |
| 853 // foo | 863 foo |
| 854 // \t | 864 \t |
| 855 // bar"""); | 865 bar |
| 856 // }); | 866 """); |
| 867 }); |
| 857 }); | 868 }); |
| 858 | 869 |
| 859 test('[Example 6.10]', () { | 870 test('[Example 6.10]', () { |
| 860 expectYamlLoads(null, | 871 expectYamlLoads(null, |
| 861 """ | 872 """ |
| 862 # Comment | 873 # Comment |
| 863 | 874 |
| 864 """); | 875 """); |
| 865 }); | 876 }); |
| 866 | 877 |
| 867 test('[Example 6.11]', () { | 878 test('[Example 6.11]', () { |
| 868 expectYamlLoads({'key': 'value'}, | 879 expectYamlLoads({'key': 'value'}, |
| 869 """ | 880 """ |
| 870 key: # Comment | 881 key: # Comment |
| 871 # lines | 882 # lines |
| 872 value"""); | 883 value |
| 884 """); |
| 873 }); | 885 }); |
| 874 | 886 |
| 875 // group('ending a block scalar header', () { | 887 group('ending a block scalar header', () { |
| 876 // test('may not be followed by additional comment lines', () { | 888 test('may not be followed by additional comment lines', () { |
| 877 // expectYamlLoads("# not comment\nfoo\n", | 889 expectYamlLoads(["# not comment\nfoo\n"], |
| 878 // """ | 890 """ |
| 879 // - | # comment | 891 - | # comment |
| 880 // # not comment | 892 # not comment |
| 881 // foo"""); | 893 foo |
| 882 // }); | 894 """); |
| 883 // }); | 895 }); |
| 896 }); |
| 884 }); | 897 }); |
| 885 | 898 |
| 886 group('6.7: Separation Lines', () { | 899 group('6.7: Separation Lines', () { |
| 887 // test('may not be used within implicit keys', () { | 900 test('may not be used within implicit keys', () { |
| 888 // Expect.throws(() => loadYaml(cleanUpLiteral( | 901 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 889 // """ | 902 """ |
| 890 // [1, | 903 [1, |
| 891 // 2]: 3"""))); | 904 2]: 3"""))); |
| 892 // }); | 905 }); |
| 893 | 906 |
| 894 // test('[Example 6.12]', () { | 907 test('[Example 6.12]', () { |
| 895 // var doc = yamlMap(); | 908 var doc = yamlMap(); |
| 896 // doc[{'first': 'Sammy', 'last': 'Sosa'}] = { | 909 doc[{'first': 'Sammy', 'last': 'Sosa'}] = { |
| 897 // 'hr': 65, | 910 'hr': 65, |
| 898 // 'avg': 0.278 | 911 'avg': 0.278 |
| 899 // }; | 912 }; |
| 900 // expectYamlLoads(doc, | 913 expectYamlLoads(doc, |
| 901 // """ | 914 """ |
| 902 // { first: Sammy, last: Sosa }: | 915 { first: Sammy, last: Sosa }: |
| 903 // # Statistics: | 916 # Statistics: |
| 904 // hr: # Home runs | 917 hr: # Home runs |
| 905 // 65 | 918 65 |
| 906 // avg: # Average | 919 avg: # Average |
| 907 // 0.278"""); | 920 0.278"""); |
| 908 // }); | 921 }); |
| 909 }); | 922 }); |
| 910 | 923 |
| 911 group('6.8: Directives', () { | 924 group('6.8: Directives', () { |
| 912 // // TODO(nweiz): assert that this produces a warning | 925 // // TODO(nweiz): assert that this produces a warning |
| 913 // test('[Example 6.13]', () { | 926 // test('[Example 6.13]', () { |
| 914 // expectYamlLoads("foo", | 927 // expectYamlLoads("foo", |
| 915 // ''' | 928 // ''' |
| 916 // %FOO bar baz # Should be ignored | 929 // %FOO bar baz # Should be ignored |
| 917 // # with a warning. | 930 // # with a warning. |
| 918 // --- "foo"'''); | 931 // --- "foo"'''); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 // "foo": "", | 1094 // "foo": "", |
| 1082 // "": "bar" | 1095 // "": "bar" |
| 1083 // }, | 1096 // }, |
| 1084 // """ | 1097 // """ |
| 1085 // { | 1098 // { |
| 1086 // foo : !!str, | 1099 // foo : !!str, |
| 1087 // !!str : bar, | 1100 // !!str : bar, |
| 1088 // }"""); | 1101 // }"""); |
| 1089 // }); | 1102 // }); |
| 1090 | 1103 |
| 1091 // test('[Example 7.3]', () { | 1104 test('[Example 7.3]', () { |
| 1092 // var doc = yamlMap({"foo": null}); | 1105 var doc = yamlMap({"foo": null}); |
| 1093 // doc[null] = "bar"; | 1106 doc[null] = "bar"; |
| 1094 // expectYamlLoads(doc, | 1107 expectYamlLoads(doc, |
| 1095 // """ | 1108 """ |
| 1096 // { | 1109 { |
| 1097 // ? foo :, | 1110 ? foo :, |
| 1098 // : bar, | 1111 : bar, |
| 1099 // }"""); | 1112 }"""); |
| 1100 // }); | 1113 }); |
| 1101 }); | 1114 }); |
| 1102 | 1115 |
| 1103 group('7.3: Flow Scalar Styles', () { | 1116 group('7.3: Flow Scalar Styles', () { |
| 1104 // test('[Example 7.4]', () { | 1117 test('[Example 7.4]', () { |
| 1105 // expectYamlLoads({ | 1118 expectYamlLoads({ |
| 1106 // "implicit block key": [{"implicit flow key": "value"}] | 1119 "implicit block key": [{"implicit flow key": "value"}] |
| 1107 // }, | 1120 }, |
| 1108 // ''' | 1121 ''' |
| 1109 // "implicit block key" : [ | 1122 "implicit block key" : [ |
| 1110 // "implicit flow key" : value, | 1123 "implicit flow key" : value, |
| 1111 // ]'''); | 1124 ]'''); |
| 1112 // }); | 1125 }); |
| 1113 | 1126 |
| 1114 // test('[Example 7.5]', () { | 1127 test('[Example 7.5]', () { |
| 1115 // expectYamlLoads( | 1128 expectYamlLoads( |
| 1116 // "folded to a space,\nto a line feed, or \t \tnon-content", | 1129 "folded to a space,\nto a line feed, or \t \tnon-content", |
| 1117 // ''' | 1130 ''' |
| 1118 // "folded | 1131 "folded |
| 1119 // to a space,\t | 1132 to a space,\t |
| 1120 | 1133 |
| 1121 // to a line feed, or \t\\ | 1134 to a line feed, or \t\\ |
| 1122 // \\ \tnon-content"'''); | 1135 \\ \tnon-content"'''); |
| 1123 // }); | 1136 }); |
| 1124 | 1137 |
| 1125 // test('[Example 7.6]', () { | 1138 test('[Example 7.6]', () { |
| 1126 // expectYamlLoads(" 1st non-empty\n2nd non-empty 3rd non-empty ", | 1139 expectYamlLoads(" 1st non-empty\n2nd non-empty 3rd non-empty ", |
| 1127 // ''' | 1140 ''' |
| 1128 // " 1st non-empty | 1141 " 1st non-empty |
| 1129 | 1142 |
| 1130 // 2nd non-empty | 1143 2nd non-empty |
| 1131 // \t3rd non-empty "'''); | 1144 \t3rd non-empty "'''); |
| 1132 // }); | 1145 }); |
| 1133 | 1146 |
| 1134 // test('[Example 7.7]', () { | 1147 test('[Example 7.7]', () { |
| 1135 // expectYamlLoads("here's to \"quotes\"", "'here''s to \"quotes\"'"); | 1148 expectYamlLoads("here's to \"quotes\"", "'here''s to \"quotes\"'"); |
| 1136 // }); | 1149 }); |
| 1137 | 1150 |
| 1138 // test('[Example 7.8]', () { | 1151 test('[Example 7.8]', () { |
| 1139 // expectYamlLoads({ | 1152 expectYamlLoads({ |
| 1140 // "implicit block key": [{"implicit flow key": "value"}] | 1153 "implicit block key": [{"implicit flow key": "value"}] |
| 1141 // }, | 1154 }, |
| 1142 // """ | 1155 """ |
| 1143 // 'implicit block key' : [ | 1156 'implicit block key' : [ |
| 1144 // 'implicit flow key' : value, | 1157 'implicit flow key' : value, |
| 1145 // ]"""); | 1158 ]"""); |
| 1146 // }); | 1159 }); |
| 1147 | 1160 |
| 1148 // test('[Example 7.9]', () { | 1161 test('[Example 7.9]', () { |
| 1149 // expectYamlLoads(" 1st non-empty\n2nd non-empty 3rd non-empty ", | 1162 expectYamlLoads(" 1st non-empty\n2nd non-empty 3rd non-empty ", |
| 1150 // """ | 1163 """ |
| 1151 // ' 1st non-empty | 1164 ' 1st non-empty |
| 1152 | 1165 |
| 1153 // 2nd non-empty | 1166 2nd non-empty |
| 1154 // \t3rd non-empty '"""); | 1167 \t3rd non-empty '"""); |
| 1155 // }); | 1168 }); |
| 1156 | 1169 |
| 1157 // test('[Example 7.10]', () { | 1170 test('[Example 7.10]', () { |
| 1158 // expectYamlLoads([ | 1171 expectYamlLoads([ |
| 1159 // "::vector", ": - ()", "Up, up, and away!", -123, | 1172 "::vector", ": - ()", "Up, up, and away!", -123, |
| 1160 // "http://example.com/foo#bar", | 1173 "http://example.com/foo#bar", |
| 1161 // [ | 1174 [ |
| 1162 // "::vector", ": - ()", "Up, up, and away!", -123, | 1175 "::vector", ": - ()", "Up, up, and away!", -123, |
| 1163 // "http://example.com/foo#bar" | 1176 "http://example.com/foo#bar" |
| 1164 // ] | 1177 ] |
| 1165 // ], | 1178 ], |
| 1166 // ''' | 1179 ''' |
| 1167 // # Outside flow collection: | 1180 # Outside flow collection: |
| 1168 // - ::vector | 1181 - ::vector |
| 1169 // - ": - ()" | 1182 - ": - ()" |
| 1170 // - Up, up, and away! | 1183 - Up, up, and away! |
| 1171 // - -123 | 1184 - -123 |
| 1172 // - http://example.com/foo#bar | 1185 - http://example.com/foo#bar |
| 1173 // # Inside flow collection: | 1186 # Inside flow collection: |
| 1174 // - [ ::vector, | 1187 - [ ::vector, |
| 1175 // ": - ()", | 1188 ": - ()", |
| 1176 // "Up, up and away!", | 1189 "Up, up, and away!", |
| 1177 // -123, | 1190 -123, |
| 1178 // http://example.com/foo#bar ]'''); | 1191 http://example.com/foo#bar ]'''); |
| 1179 // }); | 1192 }); |
| 1180 | 1193 |
| 1181 // test('[Example 7.11]', () { | 1194 test('[Example 7.11]', () { |
| 1182 // expectYamlLoads({ | 1195 expectYamlLoads({ |
| 1183 // "implicit block key": [{"implicit flow key": "value"}] | 1196 "implicit block key": [{"implicit flow key": "value"}] |
| 1184 // }, | 1197 }, |
| 1185 // """ | 1198 """ |
| 1186 // implicit block key : [ | 1199 implicit block key : [ |
| 1187 // implicit flow key : value, | 1200 implicit flow key : value, |
| 1188 // ]"""); | 1201 ]"""); |
| 1189 // }); | 1202 }); |
| 1190 | 1203 |
| 1191 // test('[Example 7.12]', () { | 1204 test('[Example 7.12]', () { |
| 1192 // expectYamlLoads("1st non-empty\n2nd non-empty 3rd non-empty", | 1205 expectYamlLoads("1st non-empty\n2nd non-empty 3rd non-empty", |
| 1193 // """ | 1206 """ |
| 1194 // 1st non-empty | 1207 1st non-empty |
| 1195 | 1208 |
| 1196 // 2nd non-empty | 1209 2nd non-empty |
| 1197 // \t3rd non-empty"""); | 1210 \t3rd non-empty"""); |
| 1198 // }); | 1211 }); |
| 1199 }); | 1212 }); |
| 1200 | 1213 |
| 1201 group('7.4: Flow Collection Styles', () { | 1214 group('7.4: Flow Collection Styles', () { |
| 1202 // test('[Example 7.13]', () { | 1215 test('[Example 7.13]', () { |
| 1203 // expectYamlLoads([ | 1216 expectYamlLoads([ |
| 1204 // ['one', 'two'], | 1217 ['one', 'two'], |
| 1205 // ['three', 'four'] | 1218 ['three', 'four'] |
| 1206 // ], | 1219 ], |
| 1207 // """ | 1220 """ |
| 1208 // - [ one, two, ] | 1221 - [ one, two, ] |
| 1209 // - [three ,four]"""); | 1222 - [three ,four]"""); |
| 1210 // }); | 1223 }); |
| 1211 | 1224 |
| 1212 // test('[Example 7.14]', () { | 1225 test('[Example 7.14]', () { |
| 1213 // expectYamlLoads([ | 1226 expectYamlLoads([ |
| 1214 // "double quoted", "single quoted", "plain text", ["nested"], | 1227 "double quoted", "single quoted", "plain text", ["nested"], |
| 1215 // {"single": "pair"} | 1228 {"single": "pair"} |
| 1216 // ], | 1229 ], |
| 1217 // """ | 1230 """ |
| 1218 // [ | 1231 [ |
| 1219 // "double | 1232 "double |
| 1220 // quoted", 'single | 1233 quoted", 'single |
| 1221 // quoted', | 1234 quoted', |
| 1222 // plain | 1235 plain |
| 1223 // text, [ nested ], | 1236 text, [ nested ], |
| 1224 // single: pair, | 1237 single: pair, |
| 1225 // ]"""); | 1238 ]"""); |
| 1226 // }); | 1239 }); |
| 1227 | 1240 |
| 1228 // test('[Example 7.15]', () { | 1241 test('[Example 7.15]', () { |
| 1229 // expectYamlLoads([ | 1242 expectYamlLoads([ |
| 1230 // {"one": "two", "three": "four"}, | 1243 {"one": "two", "three": "four"}, |
| 1231 // {"five": "six", "seven": "eight"}, | 1244 {"five": "six", "seven": "eight"}, |
| 1232 // ], | 1245 ], |
| 1233 // """ | 1246 """ |
| 1234 // - { one : two , three: four , } | 1247 - { one : two , three: four , } |
| 1235 // - {five: six,seven : eight}"""); | 1248 - {five: six,seven : eight}"""); |
| 1236 // }); | 1249 }); |
| 1237 | 1250 |
| 1238 // test('[Example 7.16]', () { | 1251 test('[Example 7.16]', () { |
| 1239 // var doc = yamlMap({ | 1252 var doc = yamlMap({ |
| 1240 // "explicit": "entry", | 1253 "explicit": "entry", |
| 1241 // "implicit": "entry" | 1254 "implicit": "entry" |
| 1242 // }); | 1255 }); |
| 1243 // doc[null] = null; | 1256 doc[null] = null; |
| 1244 // expectYamlLoads(doc, | 1257 expectYamlLoads(doc, |
| 1245 // """ | 1258 """ |
| 1246 // { | 1259 { |
| 1247 // ? explicit: entry, | 1260 ? explicit: entry, |
| 1248 // implicit: entry, | 1261 implicit: entry, |
| 1249 // ? | 1262 ? |
| 1250 // }"""); | 1263 }"""); |
| 1251 // }); | 1264 }); |
| 1252 | 1265 |
| 1253 // test('[Example 7.17]', () { | 1266 test('[Example 7.17]', () { |
| 1254 // var doc = yamlMap({ | 1267 var doc = yamlMap({ |
| 1255 // "unquoted": "separate", | 1268 "unquoted": "separate", |
| 1256 // "http://foo.com": null, | 1269 "http://foo.com": null, |
| 1257 // "omitted value": null | 1270 "omitted value": null |
| 1258 // }); | 1271 }); |
| 1259 // doc[null] = "omitted key"; | 1272 doc[null] = "omitted key"; |
| 1260 // expectYamlLoads(doc, | 1273 expectYamlLoads(doc, |
| 1261 // ''' | 1274 ''' |
| 1262 // { | 1275 { |
| 1263 // unquoted : "separate", | 1276 unquoted : "separate", |
| 1264 // http://foo.com, | 1277 http://foo.com, |
| 1265 // omitted value:, | 1278 omitted value:, |
| 1266 // : omitted key, | 1279 : omitted key, |
| 1267 // }'''); | 1280 }'''); |
| 1268 // }); | 1281 }); |
| 1269 | 1282 |
| 1270 // test('[Example 7.18]', () { | 1283 test('[Example 7.18]', () { |
| 1271 // expectYamlLoads({ | 1284 expectYamlLoads({ |
| 1272 // "adjacent": "value", | 1285 "adjacent": "value", |
| 1273 // "readable": "value", | 1286 "readable": "value", |
| 1274 // "empty": null | 1287 "empty": null |
| 1275 // }, | 1288 }, |
| 1276 // ''' | 1289 ''' |
| 1277 // { | 1290 { |
| 1278 // "adjacent":value, | 1291 "adjacent":value, |
| 1279 // "readable": value, | 1292 "readable": value, |
| 1280 // "empty": | 1293 "empty": |
| 1281 // }'''); | 1294 }'''); |
| 1282 // }); | 1295 }); |
| 1283 | 1296 |
| 1284 // test('[Example 7.19]', () { | 1297 test('[Example 7.19]', () { |
| 1285 // expectYamlLoads([{"foo": "bar"}], | 1298 expectYamlLoads([{"foo": "bar"}], |
| 1286 // """ | 1299 """ |
| 1287 // [ | 1300 [ |
| 1288 // foo: bar | 1301 foo: bar |
| 1289 // ]"""); | 1302 ]"""); |
| 1290 // }); | 1303 }); |
| 1291 | 1304 |
| 1292 // test('[Example 7.20]', () { | 1305 test('[Example 7.20]', () { |
| 1293 // expectYamlLoads([{"foo bar": "baz"}], | 1306 expectYamlLoads([{"foo bar": "baz"}], |
| 1294 // """ | 1307 """ |
| 1295 // [ | 1308 [ |
| 1296 // ? foo | 1309 ? foo |
| 1297 // bar : baz | 1310 bar : baz |
| 1298 // ]"""); | 1311 ]"""); |
| 1299 // }); | 1312 }); |
| 1300 | 1313 |
| 1301 // test('[Example 7.21]', () { | 1314 test('[Example 7.21]', () { |
| 1302 // var el1 = yamlMap(); | 1315 var el1 = yamlMap(); |
| 1303 // el1[null] = "empty key array"; | 1316 el1[null] = "empty key entry"; |
| 1304 | 1317 |
| 1305 // var el2 = yamlMap(); | 1318 var el2 = yamlMap(); |
| 1306 // el2[{"JSON": "like"}] = "adjacent"; | 1319 el2[{"JSON": "like"}] = "adjacent"; |
| 1307 // expectYamlLoads([[{"YAML": "separate"}], [el1], [el2]], | 1320 |
| 1308 // """ | 1321 expectYamlLoads([[{"YAML": "separate"}], [el1], [el2]], |
| 1309 // - [ YAML : separate ] | 1322 """ |
| 1310 // - [ : empty key entry ] | 1323 - [ YAML : separate ] |
| 1311 // - [ {JSON: like}:adjacent ]"""); | 1324 - [ : empty key entry ] |
| 1312 // }); | 1325 - [ {JSON: like}:adjacent ]"""); |
| 1313 | 1326 }); |
| 1314 // test('[Example 7.22]', () { | 1327 |
| 1315 // Expect.throws(() => loadYaml(cleanUpLiteral( | 1328 test('[Example 7.22]', () { |
| 1316 // """ | 1329 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 1317 // [ foo | 1330 """ |
| 1318 // bar: invalid ]""")); | 1331 [ foo |
| 1319 | 1332 bar: invalid ]"""))); |
| 1320 // var dotList = []; | 1333 |
| 1321 // dotList.insertRange(0, 1024, ' '); | 1334 // TODO(nweiz): enable this when we throw an error for long keys |
| 1322 // var dots = Strings.join(dotList, ''); | 1335 // var dotList = []; |
| 1323 // Expect.throws(() => loadYaml('[ "foo...$dots...bar": invalid ]')); | 1336 // dotList.insertRange(0, 1024, ' '); |
| 1324 // }); | 1337 // var dots = Strings.join(dotList, ''); |
| 1338 // Expect.throws(() => loadYaml('[ "foo...$dots...bar": invalid ]')); |
| 1339 }); |
| 1325 }); | 1340 }); |
| 1326 | 1341 |
| 1327 group('7.5: Flow Nodes', () { | 1342 group('7.5: Flow Nodes', () { |
| 1328 // test('[Example 7.23]', () { | 1343 test('[Example 7.23]', () { |
| 1329 // expectYamlLoads([["a", "b"], {"a": "b"}, "a", "b", "c"], | 1344 expectYamlLoads([["a", "b"], {"a": "b"}, "a", "b", "c"], |
| 1330 // """ | 1345 """ |
| 1331 // - [ a, b ] | 1346 - [ a, b ] |
| 1332 // - { a: b } | 1347 - { a: b } |
| 1333 // - "a" | 1348 - "a" |
| 1334 // - 'b' | 1349 - 'b' |
| 1335 // - c"""); | 1350 - c"""); |
| 1336 // }); | 1351 }); |
| 1337 | 1352 |
| 1338 // test('[Example 7.24]', () { | 1353 // test('[Example 7.24]', () { |
| 1339 // expectYamlLoads(["a", "b", "c", "c", ""], | 1354 // expectYamlLoads(["a", "b", "c", "c", ""], |
| 1340 // """ | 1355 // """ |
| 1341 // - !!str "a" | 1356 // - !!str "a" |
| 1342 // - 'b' | 1357 // - 'b' |
| 1343 // - &anchor "c" | 1358 // - &anchor "c" |
| 1344 // - *anchor | 1359 // - *anchor |
| 1345 // - !!str"""); | 1360 // - !!str"""); |
| 1346 // }); | 1361 // }); |
| 1347 }); | 1362 }); |
| 1348 | 1363 |
| 1349 // Chapter 8: Block Styles | 1364 // Chapter 8: Block Styles |
| 1350 group('8.1: Block Scalar Styles', () { | 1365 group('8.1: Block Scalar Styles', () { |
| 1351 // test('[Example 8.1]', () { | 1366 test('[Example 8.1]', () { |
| 1352 // expectYamlLoads(["literal\n", " folded\n", "keep\n\n", " strip"], | 1367 expectYamlLoads(["literal\n", " folded\n", "keep\n\n", " strip"], |
| 1353 // """ | 1368 """ |
| 1354 // - | # Empty header | 1369 - | # Empty header |
| 1355 // literal | 1370 literal |
| 1356 // - >1 # Indentation indicator | 1371 - >1 # Indentation indicator |
| 1357 // folded | 1372 folded |
| 1358 // - |+ # Chomping indicator | 1373 - |+ # Chomping indicator |
| 1359 // keep | 1374 keep |
| 1360 | 1375 |
| 1361 // - >1- # Both indicators | 1376 - >1- # Both indicators |
| 1362 // strip"""); | 1377 strip"""); |
| 1363 // }); | 1378 }); |
| 1364 | 1379 |
| 1365 // test('[Example 8.2]', () { | 1380 test('[Example 8.2]', () { |
| 1366 // expectYamlLoads([ | 1381 // Note: in the spec, the fourth element in this array is listed as |
| 1367 // "detected\n", | 1382 // "\t detected\n", not "\t\ndetected\n". However, I'm reasonably |
| 1368 // "\n\n# detected\n", | 1383 // confident that "\t\ndetected\n" is correct when parsed according to the |
| 1369 // " explicit\n", | 1384 // rest of the spec. |
| 1370 // "\t detected\n" | 1385 expectYamlLoads([ |
| 1371 // ], | 1386 "detected\n", |
| 1372 // """ | 1387 "\n\n# detected\n", |
| 1373 // - | | 1388 " explicit\n", |
| 1374 // detected | 1389 "\t\ndetected\n" |
| 1375 // - > | 1390 ], |
| 1391 """ |
| 1392 - | |
| 1393 detected |
| 1394 - > |
| 1376 | 1395 |
| 1377 | 1396 |
| 1378 // # detected | 1397 # detected |
| 1379 // - |1 | 1398 - |1 |
| 1380 // explicit | 1399 explicit |
| 1381 // - > | 1400 - > |
| 1382 // \t | 1401 \t |
| 1383 // detected"""); | 1402 detected |
| 1384 // }); | 1403 """); |
| 1404 }); |
| 1385 | 1405 |
| 1386 // test('[Example 8.3]', () { | 1406 test('[Example 8.3]', () { |
| 1387 // Expect.throws(() => loadYaml(cleanUpLiteral( | 1407 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 1388 // """ | 1408 """ |
| 1389 // - | | 1409 - | |
| 1390 | 1410 |
| 1391 // text"""))); | 1411 text"""))); |
| 1392 | 1412 |
| 1393 // Expect.throws(() => loadYaml(cleanUpLiteral( | 1413 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 1394 // """ | 1414 """ |
| 1395 // - > | 1415 - > |
| 1396 // text | 1416 text |
| 1397 // text"""))); | 1417 text"""))); |
| 1398 | 1418 |
| 1399 // Expect.throws(() => loadYaml(cleanUpLiteral( | 1419 Expect.throws(() => loadYaml(cleanUpLiteral( |
| 1400 // """ | 1420 """ |
| 1401 // - |2 | 1421 - |2 |
| 1402 // text""")); | 1422 text"""))); |
| 1403 // }); | 1423 }); |
| 1404 | 1424 |
| 1405 // test('[Example 8.4]', () { | 1425 test('[Example 8.4]', () { |
| 1406 // expectYamlLoads({"strip": "text", "clip": "text\n", "keep": "text\n"}, | 1426 expectYamlLoads({"strip": "text", "clip": "text\n", "keep": "text\n"}, |
| 1407 // """ | 1427 """ |
| 1408 // strip: |- | 1428 strip: |- |
| 1409 // text | 1429 text |
| 1410 // clip: | | 1430 clip: | |
| 1411 // text | 1431 text |
| 1412 // keep: |+ | 1432 keep: |+ |
| 1413 // text"""); | 1433 text |
| 1414 // }); | 1434 """); |
| 1435 }); |
| 1415 | 1436 |
| 1416 // test('[Example 8.5]', () { | 1437 test('[Example 8.5]', () { |
| 1417 // expectYamlLoads({ | 1438 // This example in the spec only includes a single newline in the "keep" |
| 1418 // "strip": "# text", | 1439 // value, but as far as I can tell that's not how it's supposed to be |
| 1419 // "clip": "# text\n", | 1440 // parsed according to the rest of the spec. |
| 1420 // "keep": "# text\n" | 1441 expectYamlLoads({ |
| 1421 // }, | 1442 "strip": "# text", |
| 1422 // """ | 1443 "clip": "# text\n", |
| 1423 // # Strip | 1444 "keep": "# text\n\n" |
| 1424 // # Comments: | 1445 }, |
| 1425 // strip: |- | 1446 """ |
| 1426 // # text | 1447 # Strip |
| 1448 # Comments: |
| 1449 strip: |- |
| 1450 # text |
| 1427 | 1451 |
| 1428 // # Clip | 1452 # Clip |
| 1429 // # comments: | 1453 # comments: |
| 1430 | 1454 |
| 1431 // clip: | | 1455 clip: | |
| 1432 // # text | 1456 # text |
| 1433 | 1457 |
| 1434 // # Keep | 1458 # Keep |
| 1435 // # comments: | 1459 # comments: |
| 1436 | 1460 |
| 1437 // keep: |+ | 1461 keep: |+ |
| 1438 // # text | 1462 # text |
| 1439 | 1463 |
| 1440 // # Trail | 1464 # Trail |
| 1441 // # comments."""); | 1465 # comments. |
| 1442 // }); | 1466 """); |
| 1467 }); |
| 1443 | 1468 |
| 1444 // test('[Example 8.6]', () { | 1469 test('[Example 8.6]', () { |
| 1445 // expectYamlLoads({"strip": "", "clip": "", "keep": "\n"}, | 1470 expectYamlLoads({"strip": "", "clip": "", "keep": "\n"}, |
| 1446 // """ | 1471 """ |
| 1447 // strip: >- | 1472 strip: >- |
| 1448 | 1473 |
| 1449 // clip: > | 1474 clip: > |
| 1450 | 1475 |
| 1451 // keep: |+ | 1476 keep: |+ |
| 1452 // """); | |
| 1453 // }); | |
| 1454 | 1477 |
| 1455 // test('[Example 8.7]', () { | 1478 """); |
| 1456 // expectYamlLoads("literal\n\ttext\n", | 1479 }); |
| 1457 // """ | |
| 1458 // | | |
| 1459 // literal | |
| 1460 // \ttext | |
| 1461 // """); | |
| 1462 // }); | |
| 1463 | 1480 |
| 1464 // test('[Example 8.8]', () { | 1481 test('[Example 8.7]', () { |
| 1465 // expectYamlLoads("\n\nliteral\n \n\ntext\n", | 1482 expectYamlLoads("literal\n\ttext\n", |
| 1466 // """ | 1483 """ |
| 1467 // | | 1484 | |
| 1485 literal |
| 1486 \ttext |
| 1487 """); |
| 1488 }); |
| 1489 |
| 1490 test('[Example 8.8]', () { |
| 1491 expectYamlLoads("\n\nliteral\n \n\ntext\n", |
| 1492 """ |
| 1493 | |
| 1468 | 1494 |
| 1469 | 1495 |
| 1470 // literal | 1496 literal |
| 1471 | 1497 |
| 1472 | 1498 |
| 1473 // text | 1499 text |
| 1474 | 1500 |
| 1475 // # Comment"""); | 1501 # Comment"""); |
| 1476 // }); | 1502 }); |
| 1477 | 1503 |
| 1478 // test('[Example 8.9]', () { | 1504 test('[Example 8.9]', () { |
| 1479 // expectYamlLoads("folded text\n", | 1505 expectYamlLoads("folded text\n", |
| 1480 // """ | 1506 """ |
| 1481 // > | 1507 > |
| 1482 // folded | 1508 folded |
| 1483 // text | 1509 text |
| 1484 // """); | 1510 """); |
| 1485 // }); | 1511 }); |
| 1486 | 1512 |
| 1487 // test('[Example 8.10]', () { | 1513 test('[Example 8.10]', () { |
| 1488 // expectYamlLoads( | 1514 expectYamlLoads( |
| 1489 // cleanUpLiteral(""" | 1515 cleanUpLiteral(""" |
| 1490 // folded line | |
| 1491 // next line | |
| 1492 // * bullet | |
| 1493 | 1516 |
| 1494 // * list | 1517 folded line |
| 1495 // * lines | 1518 next line |
| 1519 * bullet |
| 1496 | 1520 |
| 1497 // last line"""), | 1521 * list |
| 1498 // """ | 1522 * lines |
| 1499 // > | |
| 1500 | 1523 |
| 1501 // folded | 1524 last line |
| 1502 // line | 1525 """), |
| 1526 """ |
| 1527 > |
| 1503 | 1528 |
| 1504 // next | 1529 folded |
| 1505 // line | 1530 line |
| 1506 // * bullet | |
| 1507 | 1531 |
| 1508 // * list | 1532 next |
| 1509 // * lines | 1533 line |
| 1534 * bullet |
| 1510 | 1535 |
| 1511 // last | 1536 * list |
| 1512 // line | 1537 * lines |
| 1513 | 1538 |
| 1514 // # Comment"""); | 1539 last |
| 1515 // }); | 1540 line |
| 1541 |
| 1542 # Comment"""); |
| 1543 }); |
| 1516 | 1544 |
| 1517 // Examples 8.11 through 8.13 are duplicates of 8.10. | 1545 // Examples 8.11 through 8.13 are duplicates of 8.10. |
| 1518 }); | 1546 }); |
| 1519 | 1547 |
| 1520 group('8.2: Block Collection Styles', () { | 1548 group('8.2: Block Collection Styles', () { |
| 1521 test('[Example 8.14]', () { | 1549 test('[Example 8.14]', () { |
| 1522 expectYamlLoads({"block sequence": ["one", {"two": "three"}]}, | 1550 expectYamlLoads({"block sequence": ["one", {"two": "three"}]}, |
| 1523 """ | 1551 """ |
| 1524 block sequence: | 1552 block sequence: |
| 1525 - one | 1553 - one |
| 1526 - two : three"""); | 1554 - two : three"""); |
| 1527 }); | 1555 }); |
| 1528 | 1556 |
| 1529 // test('[Example 8.15]', () { | 1557 test('[Example 8.15]', () { |
| 1530 // expectYamlLoads([ | 1558 expectYamlLoads([ |
| 1531 // null, "block node\n", ["one", "two"], [{"one": "two"}] | 1559 null, "block node\n", ["one", "two"], {"one": "two"} |
| 1532 // ], | 1560 ], |
| 1533 // """ | 1561 """ |
| 1534 // - # Empty | 1562 - # Empty |
| 1535 // - | | 1563 - | |
| 1536 // block node | 1564 block node |
| 1537 // - - one # Compact | 1565 - - one # Compact |
| 1538 // - two # sequence | 1566 - two # sequence |
| 1539 // - one: two # Compact mapping"""); | 1567 - one: two # Compact mapping"""); |
| 1540 // }); | 1568 }); |
| 1541 | 1569 |
| 1542 // test('[Example 8.16]', () { | 1570 test('[Example 8.16]', () { |
| 1543 // expectYamlLoads({"block mapping": {"key": "value"}}, | 1571 expectYamlLoads({"block mapping": {"key": "value"}}, |
| 1544 // """ | 1572 """ |
| 1545 // block mapping: | 1573 block mapping: |
| 1546 // key: value"""); | 1574 key: value"""); |
| 1547 // }); | 1575 }); |
| 1548 | 1576 |
| 1549 // test('[Example 8.17]', () { | 1577 test('[Example 8.17]', () { |
| 1550 // expectYamlLoads({ | 1578 expectYamlLoads({ |
| 1551 // "explicit key": null, | 1579 "explicit key": null, |
| 1552 // "block key\n": ["one", "two"] | 1580 "block key\n": ["one", "two"] |
| 1553 // }, | 1581 }, |
| 1554 // """ | 1582 """ |
| 1555 // ? explicit key # Empty value | 1583 ? explicit key # Empty value |
| 1556 // ? | | 1584 ? | |
| 1557 // block key | 1585 block key |
| 1558 // : - one # Explicit compact | 1586 : - one # Explicit compact |
| 1559 // - two # block value"""); | 1587 - two # block value"""); |
| 1560 // }); | 1588 }); |
| 1561 | 1589 |
| 1562 // test('[Example 8.18]', () { | 1590 test('[Example 8.18]', () { |
| 1563 // var doc = yamlMap({ | 1591 var doc = yamlMap({ |
| 1564 // 'plain key': 'in-line value', | 1592 'plain key': 'in-line value', |
| 1565 // "quoted key": ["entry"] | 1593 "quoted key": ["entry"] |
| 1566 // }); | 1594 }); |
| 1567 // doc[null] = null; | 1595 doc[null] = null; |
| 1568 // expectYamlLoads(doc, | 1596 expectYamlLoads(doc, |
| 1569 // ''' | 1597 ''' |
| 1570 // plain key: in-line value | 1598 plain key: in-line value |
| 1571 // : # Both empty | 1599 : # Both empty |
| 1572 // "quoted key": | 1600 "quoted key": |
| 1573 // - entry'''); | 1601 - entry'''); |
| 1574 // }); | 1602 }); |
| 1575 | 1603 |
| 1576 // test('[Example 8.19]', () { | 1604 test('[Example 8.19]', () { |
| 1577 // var el = yamlMap(); | 1605 var el = yamlMap(); |
| 1578 // el[{'earth': 'blue'}] = {'moon': 'white'}; | 1606 el[{'earth': 'blue'}] = {'moon': 'white'}; |
| 1579 // expectYamlLoads([{'sun': 'yellow'}, el], | 1607 expectYamlLoads([{'sun': 'yellow'}, el], |
| 1580 // """ | 1608 """ |
| 1581 // - sun: yellow | 1609 - sun: yellow |
| 1582 // - ? earth: blue | 1610 - ? earth: blue |
| 1583 // : moon: white"""); | 1611 : moon: white"""); |
| 1584 // }); | 1612 }); |
| 1585 | 1613 |
| 1586 // test('[Example 8.20]', () { | 1614 // test('[Example 8.20]', () { |
| 1587 // expectYamlLoads(["flow in block", "Block scalar\n", {"foo": "bar"}], | 1615 // expectYamlLoads(["flow in block", "Block scalar\n", {"foo": "bar"}], |
| 1588 // ''' | 1616 // ''' |
| 1589 // - | 1617 // - |
| 1590 // "flow in block" | 1618 // "flow in block" |
| 1591 // - > | 1619 // - > |
| 1592 // Block scalar | 1620 // Block scalar |
| 1593 // - !!map # Block collection | 1621 // - !!map # Block collection |
| 1594 // foo : bar'''); | 1622 // foo : bar'''); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 | 1655 |
| 1628 // test('[Example 9.2]', () { | 1656 // test('[Example 9.2]', () { |
| 1629 // expectYamlLoads("Document", | 1657 // expectYamlLoads("Document", |
| 1630 // """ | 1658 // """ |
| 1631 // %YAML 1.2 | 1659 // %YAML 1.2 |
| 1632 // --- | 1660 // --- |
| 1633 // Document | 1661 // Document |
| 1634 // ... # Suffix"""); | 1662 // ... # Suffix"""); |
| 1635 // }); | 1663 // }); |
| 1636 | 1664 |
| 1637 // test('[Example 9.3]', () { | 1665 test('[Example 9.3]', () { |
| 1638 // expectYamlStreamLoads(["Bare Document", "%!PS-Adobe-2.0\n"], | 1666 // The spec example indicates that the comment after "%!PS-Adobe-2.0" |
| 1639 // """ | 1667 // should be stripped, which would imply that that line is not part of the |
| 1640 // Bare | 1668 // literal defined by the "|". The rest of the spec is ambiguous on this |
| 1641 // document | 1669 // point; the allowable indentation for non-indented literal content is |
| 1642 // ... | 1670 // not clearly explained. However, if both the "|" and the text were |
| 1643 // # No document | 1671 // indented the same amount, the text would be part of the literal, which |
| 1644 // ... | 1672 // implies that the spec's parse of this document is incorrect. |
| 1645 // | | 1673 expectYamlStreamLoads( |
| 1646 // %!PS-Adobe-2.0 # Not the first line"""); | 1674 ["Bare document", "%!PS-Adobe-2.0 # Not the first line\n"], |
| 1647 // }); | 1675 """ |
| 1676 Bare |
| 1677 document |
| 1678 ... |
| 1679 # No document |
| 1680 ... |
| 1681 | |
| 1682 %!PS-Adobe-2.0 # Not the first line |
| 1683 """); |
| 1684 }); |
| 1648 | 1685 |
| 1649 // test('[Example 9.4]', () { | 1686 test('[Example 9.4]', () { |
| 1650 // expectYamlStreamLoads([{"matches %": 20}, null], | 1687 expectYamlStreamLoads([{"matches %": 20}, null], |
| 1651 // """ | 1688 """ |
| 1652 // --- | 1689 --- |
| 1653 // { matches | 1690 { matches |
| 1654 // % : 20 } | 1691 % : 20 } |
| 1655 // ... | 1692 ... |
| 1656 // --- | 1693 --- |
| 1657 // # Empty | 1694 # Empty |
| 1658 // ..."""); | 1695 ..."""); |
| 1659 // }); | 1696 }); |
| 1660 | 1697 |
| 1661 // test('[Example 9.5]', () { | 1698 // test('[Example 9.5]', () { |
| 1662 // expectYamlStreamLoads(["%!PS-Adobe-2.0\n", null], | 1699 // expectYamlStreamLoads(["%!PS-Adobe-2.0\n", null], |
| 1663 // """ | 1700 // """ |
| 1664 // %YAML 1.2 | 1701 // %YAML 1.2 |
| 1665 // --- | | 1702 // --- | |
| 1666 // %!PS-Adobe-2.0 | 1703 // %!PS-Adobe-2.0 |
| 1667 // ... | 1704 // ... |
| 1668 // %YAML1.2 | 1705 // %YAML1.2 |
| 1669 // --- | 1706 // --- |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 // """ | 1833 // """ |
| 1797 // A null: null | 1834 // A null: null |
| 1798 // Booleans: [ true, false ] | 1835 // Booleans: [ true, false ] |
| 1799 // Integers: [ 0, -0, 3, -19 ] | 1836 // Integers: [ 0, -0, 3, -19 ] |
| 1800 // Floats: [ 0., -0.0, 12e03, -2E+05 ] | 1837 // Floats: [ 0., -0.0, 12e03, -2E+05 ] |
| 1801 // Invalid: [ True, Null, 0o7, 0x3A, +12.3 ]"""); | 1838 // Invalid: [ True, Null, 0o7, 0x3A, +12.3 ]"""); |
| 1802 // }); | 1839 // }); |
| 1803 }); | 1840 }); |
| 1804 | 1841 |
| 1805 group('10.3: Core Schema', () { | 1842 group('10.3: Core Schema', () { |
| 1806 // test('[Example 10.9]', () { | 1843 test('[Example 10.9]', () { |
| 1807 // expectYamlStreamLoads({ | 1844 expectYamlLoads({ |
| 1808 // "A null": null, | 1845 "A null": null, |
| 1809 // "Also a null": null, | 1846 "Also a null": null, |
| 1810 // "Not a null": "", | 1847 "Not a null": "", |
| 1811 // "Booleans": [true, true, false, false], | 1848 "Booleans": [true, true, false, false], |
| 1812 // "Integers": [0, 7, 0x3A, -19], | 1849 "Integers": [0, 7, 0x3A, -19], |
| 1813 // "Floats": [0, 0, 0.5, 12000, -200000], | 1850 "Floats": [0, 0, 0.5, 12000, -200000], |
| 1814 // "Also floats": [infinity, -infinity, infinity, nan] | 1851 "Also floats": [infinity, -infinity, infinity, nan] |
| 1815 // }, | 1852 }, |
| 1816 // ''' | 1853 ''' |
| 1817 // A null: null | 1854 A null: null |
| 1818 // Also a null: # Empty | 1855 Also a null: # Empty |
| 1819 // Not a null: "" | 1856 Not a null: "" |
| 1820 // Booleans: [ true, True, false, FALSE ] | 1857 Booleans: [ true, True, false, FALSE ] |
| 1821 // Integers: [ 0, 0o7, 0x3A, -19 ] | 1858 Integers: [ 0, 0o7, 0x3A, -19 ] |
| 1822 // Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] | 1859 Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] |
| 1823 // Also floats: [ .inf, -.Inf, +.INF, .NAN ]'''); | 1860 Also floats: [ .inf, -.Inf, +.INF, .NAN ]'''); |
| 1824 // }); | 1861 }); |
| 1825 }); | 1862 }); |
| 1826 } | 1863 } |
| OLD | NEW |