| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library json_unicode_tests; |
| 6 import 'unicode_tests.dart'; |
| 7 |
| 8 const _QUOTE = 0x22; // " |
| 9 const _COLON = 0x3a; // : |
| 10 const _COMMA = 0x2c; // , |
| 11 const _BRACE_OPEN = 0x7b; // { |
| 12 const _BRACE_CLOSE = 0x7d; // } |
| 13 const _BRACKET_OPEN = 0x5b; // [ |
| 14 const _BRACKET_CLOSE = 0x5d; // ] |
| 15 |
| 16 _expandUnicodeTests() { |
| 17 return UNICODE_TESTS.expand((test) { |
| 18 // The unicode test will be a string (possibly) containing unicode |
| 19 // characters. It also contains the empty string. |
| 20 // It must not contain a double-quote '"'. |
| 21 assert(!test.contains('"')); |
| 22 |
| 23 var bytes = test[0]; |
| 24 var string = test[1]; |
| 25 |
| 26 // expanded will hold all tests that are generated from the unicode test. |
| 27 var expanded = []; |
| 28 |
| 29 // Put the string into quotes. |
| 30 // For example: 'abcd' -> '"abcd"'. |
| 31 var inQuotesBytes = []; |
| 32 inQuotesBytes.add(_QUOTE); |
| 33 inQuotesBytes.addAll(bytes); |
| 34 inQuotesBytes.add(_QUOTE); |
| 35 expanded.add([inQuotesBytes, string]); |
| 36 |
| 37 // Put the quoted string into a triple nested list. |
| 38 // For example: 'abcd' -> '[[["abcd"]]]'. |
| 39 var listExpected = [[[string]]]; |
| 40 var inListBytes = []; |
| 41 inListBytes.addAll([_BRACKET_OPEN, _BRACKET_OPEN, _BRACKET_OPEN]); |
| 42 inListBytes.addAll(inQuotesBytes); |
| 43 inListBytes.addAll([_BRACKET_CLOSE, _BRACKET_CLOSE, _BRACKET_CLOSE]); |
| 44 expanded.add([inListBytes, listExpected]); |
| 45 |
| 46 // Put the quoted string into a triple nested list and duplicate that |
| 47 // list three times. |
| 48 // For example: 'abcd' -> '[[[["abcd"]]],[[["abcd"]]],[[["abcd"]]]]'. |
| 49 var listLongerExpected = [listExpected, listExpected, listExpected]; |
| 50 var listLongerBytes = []; |
| 51 listLongerBytes.add(_BRACKET_OPEN); |
| 52 listLongerBytes.addAll(inListBytes); |
| 53 listLongerBytes.add(_COMMA); |
| 54 listLongerBytes.addAll(inListBytes); |
| 55 listLongerBytes.add(_COMMA); |
| 56 listLongerBytes.addAll(inListBytes); |
| 57 listLongerBytes.add(_BRACKET_CLOSE); |
| 58 expanded.add([listLongerBytes, listLongerExpected]); |
| 59 |
| 60 // Put the previous strings/lists into a map. |
| 61 // For example: |
| 62 // 'abcd' -> '{"abcd":[[[["abcd"]]],[[["abcd"]]],[[["abcd"]]]]}'. |
| 63 var mapExpected = new Map(); |
| 64 mapExpected[string] = listLongerExpected; |
| 65 var mapBytes = []; |
| 66 mapBytes.add(_BRACE_OPEN); |
| 67 mapBytes.addAll(inQuotesBytes); |
| 68 mapBytes.add(_COLON); |
| 69 mapBytes.addAll(listLongerBytes); |
| 70 mapBytes.add(_BRACE_CLOSE); |
| 71 expanded.add([mapBytes, mapExpected]); |
| 72 |
| 73 return expanded; |
| 74 }).toList(); |
| 75 } |
| 76 |
| 77 final JSON_UNICODE_TESTS = _expandUnicodeTests(); |
| OLD | NEW |