/
githubmirror
/
guava
Обзор
Документация
Войти
/
githubmirror
/
guava
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
android/guava-tests/test/com/google/common/html/HtmlEscapersTest.java
66 строк
3 KB
cpovirk
Address some more counterfactual [CheckedExceptionNotThrown](https://errorprone.info/bugpattern/CheckedExceptionNotThrown) findings.
25 июн 2026, 20:33
25 июн 2026, 20:33
c37cd2a
Код
Авторство
О чём код?
/* * 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 static com.google.common.truth.Truth.assertThat; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; /** * Tests for the {@link HtmlEscapers} class. * * @author David Beaumont */ @GwtCompatible @NullUnmarked public class HtmlEscapersTest extends TestCase { public void testHtmlEscaper() { assertThat(htmlEscaper().escape("xxx")).isEqualTo("xxx"); assertThat(htmlEscaper().escape("\"test\"")).isEqualTo(""test""); assertThat(htmlEscaper().escape("'test'")).isEqualTo("'test'"); assertThat(htmlEscaper().escape("test & test & test")).isEqualTo("test & test & test"); assertThat(htmlEscaper().escape("test << 1")).isEqualTo("test << 1"); assertThat(htmlEscaper().escape("test >> 1")).isEqualTo("test >> 1"); assertThat(htmlEscaper().escape("<tab>")).isEqualTo("<tab>"); // Test simple escape of '&'. assertThat(htmlEscaper().escape("foo&bar")).isEqualTo("foo&bar"); // If the string contains no escapes, it should return the arg. // Note: assert<b>Same</b> for this implementation. String s = "blah blah farhvergnugen"; assertThat(htmlEscaper().escape(s)).isSameInstanceAs(s); // Tests escapes at begin and end of string. assertThat(htmlEscaper().escape("<p>")).isEqualTo("<p>"); // Test all escapes. assertThat(htmlEscaper().escape("a\"b<c>d&")).isEqualTo("a"b<c>d&"); // Test two escapes in a row. assertThat(htmlEscaper().escape("foo&&bar")).isEqualTo("foo&&bar"); // Test many non-escaped characters. s = "!@#$%^*()_+=-/?\\|]}[{,.;:" + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "1234567890"; assertThat(htmlEscaper().escape(s)).isSameInstanceAs(s); } }