/test/webkit/fast/js/kde/encode_decode_uri.js

https://gitlab.com/AnneSmile/v8 · JavaScript · 102 lines · 62 code · 17 blank · 23 comment · 11 complexity · 1e9de6a7ef043c4c10770f7c00e88729 MD5 · raw file

  1. // Copyright 2013 the V8 project authors. All rights reserved.
  2. // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions
  6. // are met:
  7. // 1. Redistributions of source code must retain the above copyright
  8. // notice, this list of conditions and the following disclaimer.
  9. // 2. Redistributions in binary form must reproduce the above copyright
  10. // notice, this list of conditions and the following disclaimer in the
  11. // documentation and/or other materials provided with the distribution.
  12. //
  13. // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
  14. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17. // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. description("KDE JS Test");
  24. // --------------------------------------------------------------------------------
  25. var resolution = 251; // set to 1 for 100% coverage
  26. function checkEncodeException(encodeFunctionName,c1,c2)
  27. {
  28. if (c2 == undefined)
  29. shouldThrow(encodeFunctionName
  30. + "(String.fromCharCode(" + c1 + "))");
  31. else
  32. shouldThrow(encodeFunctionName
  33. + "(String.fromCharCode(" + c1 + ") + String.fromCharCode(" + c2 + "))");
  34. }
  35. function checkEncodeDecode(encodeFunctionName, decodeFunctionName, c1, c2)
  36. {
  37. if (c2 == undefined)
  38. shouldBe(decodeFunctionName + "(" + encodeFunctionName
  39. + "(String.fromCharCode(" + c1 + ")))",
  40. "String.fromCharCode(" + c1 + ")");
  41. else
  42. shouldBe(decodeFunctionName + "(" + encodeFunctionName
  43. + "(String.fromCharCode(" + c1 + ") + String.fromCharCode(" + c2 + ")))",
  44. "String.fromCharCode(" + c1 + ") + String.fromCharCode(" + c2 + ")");
  45. }
  46. function checkWithFunctions(encodeFunction, decodeFunction)
  47. {
  48. checkEncodeDecode(encodeFunction, decodeFunction, 0);
  49. checkEncodeDecode(encodeFunction, decodeFunction, 0xD7FF);
  50. checkEncodeDecode(encodeFunction, decodeFunction, 0xE000);
  51. checkEncodeDecode(encodeFunction, decodeFunction, 0xFFFD);
  52. checkEncodeDecode(encodeFunction, decodeFunction, 0xFFFE);
  53. checkEncodeDecode(encodeFunction, decodeFunction, 0xFFFF);
  54. checkEncodeException(encodeFunction, 0xDC00);
  55. checkEncodeException(encodeFunction, 0xDFFF);
  56. checkEncodeDecode(encodeFunction, decodeFunction, 0xD800, 0xDC00);
  57. checkEncodeDecode(encodeFunction, decodeFunction, 0xDBFF, 0xDC00);
  58. checkEncodeDecode(encodeFunction, decodeFunction, 0xD800, 0xDFFF);
  59. checkEncodeDecode(encodeFunction, decodeFunction, 0xDBFF, 0xDFFF);
  60. checkEncodeException(encodeFunction, 0xD800, 0);
  61. checkEncodeException(encodeFunction, 0xD800, 0xD7FF);
  62. checkEncodeException(encodeFunction, 0xD800, 0xD800);
  63. checkEncodeException(encodeFunction, 0xD800, 0xDBFF);
  64. checkEncodeException(encodeFunction, 0xD800, 0xE000);
  65. checkEncodeException(encodeFunction, 0xD800, 0xE000);
  66. checkEncodeException(encodeFunction, 0xD800, 0xFFFD);
  67. checkEncodeException(encodeFunction, 0xD800, 0xFFFE);
  68. checkEncodeException(encodeFunction, 0xD800, 0xFFFF);
  69. for (var charcode = 1; charcode < 0xD7FF; charcode += resolution)
  70. checkEncodeDecode(encodeFunction, decodeFunction, charcode);
  71. for (var charcode = 0xE001; charcode < 0xFFFD; charcode += resolution)
  72. checkEncodeDecode(encodeFunction, decodeFunction, charcode);
  73. for (var charcode = 0xDC01; charcode < 0xDFFF; charcode += resolution)
  74. checkEncodeException(encodeFunction, charcode);
  75. for (var charcode = 0xD801; charcode < 0xDBFF; charcode += resolution)
  76. checkEncodeDecode(encodeFunction, decodeFunction, charcode, 0xDC00);
  77. for (var charcode = 0xDC01; charcode < 0xDFFF; charcode += resolution)
  78. checkEncodeDecode(encodeFunction, decodeFunction, 0xD800, charcode);
  79. for (var charcode = 1; charcode < 0xDBFF; charcode += resolution)
  80. checkEncodeException(encodeFunction, 0xD800, charcode);
  81. for (var charcode = 0xE001; charcode < 0xFFFD; charcode += resolution)
  82. checkEncodeException(encodeFunction, 0xD800, charcode);
  83. }
  84. checkWithFunctions("encodeURI", "decodeURI");
  85. checkWithFunctions("encodeURIComponent", "decodeURIComponent");