|
Java example source code file (HtmlEscapersTest.java)
The HtmlEscapersTest.java Java example source code/* * Copyright (C) 2009 The Guava Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.common.html; import static com.google.common.html.HtmlEscapers.htmlEscaper; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; /** * Tests for the {@link HtmlEscapers} class. * * @author David Beaumont */ @GwtCompatible public class HtmlEscapersTest extends TestCase { public void testHtmlEscaper() throws Exception { assertEquals("xxx", htmlEscaper().escape("xxx")); assertEquals(""test"", htmlEscaper().escape("\"test\"")); assertEquals("'test'", htmlEscaper().escape("\'test'")); assertEquals("test & test & test", htmlEscaper().escape("test & test & test")); assertEquals("test << 1", htmlEscaper().escape("test << 1")); assertEquals("test >> 1", htmlEscaper().escape("test >> 1")); assertEquals("<tab>", htmlEscaper().escape("<tab>")); // Test simple escape of '&'. assertEquals("foo&bar", htmlEscaper().escape("foo&bar")); // If the string contains no escapes, it should return the arg. // Note: assert<b>Same for this implementation. String s = "blah blah farhvergnugen"; assertSame(s, htmlEscaper().escape(s)); // Tests escapes at begin and end of string. assertEquals("<p>", htmlEscaper().escape("<p>")); // Test all escapes. assertEquals("a"b<c>d&", htmlEscaper().escape("a\"b<c>d&")); // Test two escapes in a row. assertEquals("foo&&bar", htmlEscaper().escape("foo&&bar")); // Test many non-escaped characters. s = "!@#$%^*()_+=-/?\\|]}[{,.;:" + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "1234567890"; assertSame(s, htmlEscaper().escape(s)); } } Other Java examples (source code examples)Here is a short list of links related to this Java HtmlEscapersTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.