Debug.write("RichTextTestBase.setUp"); rich.init(); assertNotSame(PLAIN_A, PLAIN_B); var contents = rich.getText(); assertSame("", contents); var foo = "FooBarBaz Lum."; rich.setText(foo); var after = rich.getText(); assertSame(foo, after); var str = new String(PLAIN_A + "\r" + PLAIN_B); var foo = replace(str, "\r", ""); assertSame(PLAIN_A + PLAIN_B, foo); var orig = "I am a little teapot."; var findme = "t"; var replacewith = "!"; var processed = replace(orig, findme, replacewith); assertSame("I am a li!!le !eapo!.", processed) // single replacement at beginning of the string processed = replace("twelve", findme, replacewith); assertSame("!welve", processed) // single replacement in middle of the string processed = replace("lite", findme, replacewith); assertSame("li!e", processed) // test single replacement at end of string processed = replace("great", findme, replacewith); assertSame("grea!", processed) // test two replacements in a row processed = replace("utter", findme, replacewith); assertSame("u!!er", processed) // test complete replacement processed = replace("tttttt", findme, replacewith); assertSame("!!!!!!", processed) if (!rich['defaultformat']) rich.defaultformat = new textformat(this, {font:"GreenPeas", size:25}); assertNotNull(rich.defaultformat); assertEquals("GreenPeas", rich.defaultformat.font); assertNotNull(rich.defaultformat); assertEquals("GreenPeas", rich.defaultformat.font); this.addTest("testDefault"); rich.setText(PLAIN_A); var contents = rich.getText(); assertSame(PLAIN_A, contents); rich.appendText(PLAIN_B); var after = rich.getText(); assertSame(PLAIN_A + PLAIN_B, after); rich.appendText(RICH_B, true); var after = rich.getText(); var munge = replace(after, "\r", ""); munge = replace(munge, "\n", ""); assertSame(PLAIN_A + PLAIN_RICH_B, munge); rich.appendText(PLAIN_B); rich.appendText(PLAIN_C); var after = rich.getText(); assertSame(PLAIN_A + PLAIN_B + PLAIN_C, after); rich.setHTMLText(RICH_A); var contents = rich.getHTMLText(); // We should have some formatting in there; it shouldn't be // just the plain text. However, we don't want to have to parse // out the formatting ourselves to check it... so this is a soft // pass. assertNotSame(PLAIN_RICH_A, contents); var contents = rich.getText(); assertSame(PLAIN_RICH_A, contents); rich.appendText(PLAIN_B, false); var after = rich.getText(); assertSame(PLAIN_RICH_A + PLAIN_B, after); rich.appendText(PLAIN_B); var after = rich.getText(); assertSame(PLAIN_RICH_A + PLAIN_B, after); rich.appendText(RICH_B, true); var after = rich.getText(); var munge = replace(after, "\r", ""); munge = replace(munge, "\n", ""); assertSame(PLAIN_RICH_A + PLAIN_RICH_B, munge); rich.appendText(RICH_B, true); rich.appendText(RICH_C, true); var after = rich.getText(); var munge = replace(after, "\r", ""); munge = replace(munge, "\n", ""); assertSame(PLAIN_RICH_A + PLAIN_RICH_B + PLAIN_RICH_C, munge); Debug.write("FormatsTestBase.setUp"); rich.setText(NUMBERS); plainFormat = new textformat(); boldFormat = new textformat(this, {bold:true}); niceFormat = new textformat(this, {font:"Verdana", size:11, align:"left"}); weirdFormat = new textformat(this, {font:"Courier", size:50, color:0x9900BB, italic:true, align:"center"}); var attrs = new Array("font", "size", "color", "bold", "italic", "underline", "url", "target", "align", "leftmargin", "rightmargin", "indent", "leading"); for (var i in attrs) { var attr = attrs[i]; if (a[attr] || b[attr]) assertEquals(a[attr], b[attr]); } Debug.write("testFormatExistingTextPlain, this is..", this); rich.setTextFormat(plainFormat, 3, 8); var fmt = rich.getTextFormat(3, 8); assertFalse(fmt.bold); rich.setTextFormat(boldFormat, 3, 8); var fmt = rich.getTextFormat(3, 8); Debug.write(fmt); assertTrue(fmt.bold); rich.setText(LONG_B); var fmt = rich.getTextFormat(3, 7); Debug.write("this is simple."); assertFalse(fmt.bold); rich.applyTextAttr("bold", true); fmt = rich.getTextFormat(3, 7); Debug.write("trickier."); assertFalse(fmt.bold); // Test for a bug where appending text makes the whole text get bold. // Drat, can't reproduce at this level. rich.appendText(PLAIN_A); fmt = rich.getTextFormat(3, 7); Debug.write("trickier."); assertFalse(fmt.bold); rich.setDefaultFormat(weirdFormat); rich.setText(NUMBERS); var gotfmt = rich.getTextFormat(3,8); sameFormat(weirdFormat, gotfmt); rich.setDefaultFormat(niceFormat); var gotfmt = rich.defaultformat; sameFormat(niceFormat, gotfmt); rich.setDefaultFormat(weirdFormat); rich.setHTMLText(RICH_A); // We know that RICH_A has bold formatting, and nothing else special about it. var gotfmt = rich.getTextFormat(2,3); assertEquals(weirdFormat.font, gotfmt.font); assertEquals(weirdFormat.size, gotfmt.size); assertTrue(gotfmt.bold); rich.setText(PLAIN_A); rich.applyTextAttr("font", "Courier", 1,3); var f = rich.getTextFormat(1, 3); assertEquals("Courier", f.font); assertEquals("Verdana", niceFormat.font); rich.setDefaultFormat(niceFormat); rich.setText(LONG_A); var f = rich.getTextFormat(7, 9); assertNotSame("Times", f.font); // the font should be the niceFormat font, Verdana assertEquals("Verdana", f.font); rich.setDefaultFormat(niceFormat); rich.setText(LONG_A); rich.applyTextAttr("font", "Courier", 7,9); f = rich.getTextFormat(7, 9); assertEquals("Courier", f.font); rich._forceResetDefaultFormat(); rich.appendText(PLAIN_A, false); var ending = rich.getText().substr(LONG_A.length); assertEquals(PLAIN_A, ending); f = rich.getTextFormat(LONG_A.length, LONG_A.length + 1); assertEquals("Verdana", f.font); rich.setDefaultFormat(niceFormat); rich.setText(LONG_A); rich.applyTextAttr("font", "Tahoma", 7, 11); rich._forceResetDefaultFormat(); rich.appendText(PLAIN_A, false); var f = rich.getTextFormat(LONG_A.length, LONG_A.length + 1); assertEquals("Verdana", f.font); rich.setDefaultFormat(niceFormat); rich.setText(LONG_A); rich.applyTextAttr("font", "Tahoma", 7, 11); rich.appendText(PLAIN_A, true); var f = rich.getTextFormat(LONG_A.length, LONG_A.length + 1); assertEquals("Verdana", f.font); rich.setDefaultFormat(niceFormat); rich.setText(LONG_A); rich.applyTextAttr("font", "Tahoma", 7, 11); var newstr = rich.getHTMLText() + PLAIN_A; rich.setHTMLText(newstr); var f = rich.getTextFormat(LONG_A.length, LONG_A.length + 1); assertEquals("Verdana", f.font); var pt = replace(rich.getText(), "\r", ""); assertEquals(LONG_A + PLAIN_A, pt); rich.setText(PLAIN_A); var f = rich.getTextFormat(2,3); assertFalse(f.bold); rich.toggleFormat("bold", 2,3); f = rich.getTextFormat(2,3); assertTrue(f.bold); rich.setText(PLAIN_A); var f = rich.getTextFormat(2,3); assertFalse(f.bold); rich.toggleFormat("bold", 2,3); f = rich.getTextFormat(2,3); assertTrue(f.bold); rich.toggleFormat("bold", 2,3); f = rich.getTextFormat(2,3); assertFalse(f.bold); rich.setText(PLAIN_A); var f = rich.getTextFormat(2,3); assertFalse(f.bold); rich.toggleFormat("bold", 2,3); var len = PLAIN_A.length; rich.appendText(PLAIN_B, false); f = rich.getTextFormat(len, len+1); assertFalse(f.bold); var myformat = new textformat(this, {font:"Monaco", size:20, align:"left"}); rich.setDefaultFormat(myformat); sameFormat(myformat, rich.defaultformat); // Make sure there's stuff in the field. assertTrue(rich.getText().length > 0); var initialFormat = rich.getTextFormat(0, rich.getText().length); var myformat = new textformat(this, {font:"Monaco", size:20, align:"left"}); var otherformat = new textformat(this, {font:"Tahoma", size:9, align:"center", italic:true}); // Make sure that setting the default actually sets the default, // but doesn't change the format of the existing text rich.setDefaultFormat(myformat); sameFormat(myformat, rich.defaultformat); var afterChangingDefault = rich.getTextFormat(0, rich.getText().length); sameFormat(initialFormat, afterChangingDefault); // Make sure there's stuff in the field. assertTrue(rich.getText().length > 0); var initialFormat = rich.getTextFormat(0, rich.getText().length); var myformat = new textformat(this, {font:"Monaco", size:20, align:"left"}); var otherformat = new textformat(this, {font:"Tahoma", size:9, align:"center", italic:true}); // Make sure that setting the default actually sets the default, // but doesn't change the format of the existing text rich.setDefaultFormat(myformat); sameFormat(myFormat, rich.defaultformat); var afterChangingDefault = rich.getTextFormat(0, rich.getText().length); sameFormat(initialFormat, afterChangingDefault); // We're getting ready to actually do something cool, namely, // add some text to the end, and make sure it has the default format. rich.appendText("john tesh is an excellent musician."); var appendedTextFormat = rich.getTextFormat(NUMBERS.length, NUMBERS.length + 5); sameFormat(rich.defaultformat, appendedTextFormat); assertEquals(rich.defaultformat.font, appendedTextFormat.font); // The format of the original text should not change!!! var beginningTextFormat = rich.getTextFormat(0, 7); sameFormat(initialFormat, beginningTextFormat); assertEquals(initialFormat.font, beginningTextFormat.font); // Okay, what if we set some text? rich.setText(PLAIN_B); var afterSetText = rich.getTextFormat(0, 2); sameFormat(rich.defaultformat, afterSetText); assertEquals(rich.defaultformat.font, afterSetText.font);