PageRenderTime 59ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/com/evanmclean/evlib/escape/EscUrlTest.java

https://github.com/evmcl/evlibjava
Java | 72 lines | 27 code | 6 blank | 39 comment | 0 complexity | 5e169dac50efcb3ad1540be532119346 MD5 | raw file
  1. /*
  2. * = License =
  3. McLean Computer Services Open Source Software License
  4. (Looks like the BSD license, but less restrictive.)
  5. Copyright (c) 2006-2011 Evan McLean. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice, this
  9. list of conditions and the following disclaimer.
  10. 2. Neither the names "Evan McLean", "McLean Computer Services", "EvLib" nor the
  11. names of any contributors may be used to endorse or promote products derived
  12. from this software without prior written permission.
  13. 3. Products derived from this software may not be called "Evlib", nor may
  14. "Evlib" appear in their name, without prior written permission.
  15. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
  18. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  20. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  23. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. = License =
  25. */
  26. package com.evanmclean.evlib.escape;
  27. import junit.framework.TestCase;
  28. import com.evanmclean.evlib.charset.Charsets;
  29. /**
  30. * @author Evan M<sup>c</sup>Lean <a href="http://evanmclean.com/"
  31. * target="_blank">M<sup>c</sup>Lean Computer Services</a> (see the
  32. * overview for copyright and licensing.)
  33. */
  34. public class EscUrlTest extends TestCase
  35. {
  36. public static final String TEST_ALL_TEST_TYPE = "UNIT";
  37. public void testNull()
  38. {
  39. assertNull(Esc.url.text(null));
  40. }
  41. public void testUnchanged()
  42. {
  43. final String unchanged = "abcdef";
  44. assertSame(unchanged, Esc.url.text(unchanged));
  45. final String unchanged2 = "abc*def-_foo.";
  46. assertSame(unchanged2, Esc.url.text(unchanged2));
  47. }
  48. public void testUrl()
  49. {
  50. assertEquals("abc%20%2B%20def", Esc.url.text("abc + def"));
  51. assertEquals("abc*def-_foo.", Esc.url.text("abc*def-_foo."));
  52. assertEquals("The%20%E2%80%9Ctest%E2%80%9D",
  53. Esc.url.text("The \u201Ctest\u201D"));
  54. assertEquals("%FE%FF%00T%00h%00e%00%20%20%1C%00t%00e%00s%00t%20%1D",
  55. Esc.url.text("The \u201Ctest\u201D", Charsets.UTF16));
  56. }
  57. }