// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package com.google.appinventor.components.common;
import junit.framework.TestCase;
/**
* Tests HtmlEntities.java.
*
* @author lizlooney@google.com (Liz Looney)
*/
public class HtmlEntitiesTest extends TestCase {
public void testdecodeHtmlText() throws Exception {
// Empty string
assertEquals("",
HtmlEntities.decodeHtmlText(""));
// No entities
assertEquals("No entities",
HtmlEntities.decodeHtmlText("No entities"));
// Recognized entities
assertEquals("< less than < less than <",
HtmlEntities.decodeHtmlText("< less than < less than <"));
assertEquals("> greater than > greater than >",
HtmlEntities.decodeHtmlText("> greater than > greater than >"));
assertEquals("& ampersand & ampersand &",
HtmlEntities.decodeHtmlText("& ampersand & ampersand &"));
assertEquals("' apostrophe ' apostrophe '",
HtmlEntities.decodeHtmlText("' apostrophe ' apostrophe '"));
assertEquals("\" quotes \" quotes \"",
HtmlEntities.decodeHtmlText("" quotes " quotes ""));
// Numeric entities
assertEquals("' apostrophe ' apostrophe '",
HtmlEntities.decodeHtmlText("' apostrophe ' apostrophe '"));
assertEquals("' apostrophe ' apostrophe '",
HtmlEntities.decodeHtmlText("' apostrophe ' apostrophe '"));
// Unrecognized entities are not decoded. No exception is thrown.
assertEquals("No semicolon after ampersand &",
HtmlEntities.decodeHtmlText("No semicolon after ampersand &"));
assertEquals("&; not decoded &; not decoded &;",
HtmlEntities.decodeHtmlText("&; not decoded &; not decoded &;"));
assertEquals("&abc; not decoded &abc; not decoded &abc;",
HtmlEntities.decodeHtmlText("&abc; not decoded &abc; not decoded &abc;"));
assertEquals("A not decoded A not decoded A", // illegal decimal value
HtmlEntities.decodeHtmlText("A not decoded A not decoded A"));
assertEquals("G; not decoded G; not decoded G;", // illegal hex value
HtmlEntities.decodeHtmlText("G; not decoded G; not decoded G;"));
}
}