# File test/core_test.rb, line 324 def test_text string = "Some text" text = Text.new string assert_equal string, text.to_s text2 = Text.new text assert_equal text, text2 string = SourceFactory.create_from "Some text<element/>" text2 = Text.new string assert_equal text, text2 #testing substitution string = "0 < ( 1 & 1 )" correct = "0 < ( 1 & 1 )" text = Text.new string, true out = "" text.write out assert_equal correct, out string = "Cats & dogs" text = Text.new string, false, true assert_equal string, text.string string2 = "<a>#{string}</a>" doc = Document.new( string2, { raw:raw => } a b } } ) out = "" doc.write out, -1 assert_equal string2, out b = doc.root.add_element "b" b.text = string assert_equal string, b.text c = doc.root.add_element "c" c.text = string assert_equal string, c.text # test all string = "<a>&<b><</b><c>><d>"</d></c></a>" doc = Document.new string, { raw:raw => all:all } assert_equal "&", doc.elements["/a"].text assert_equal "<", doc.elements["/a/b"].text assert_equal ">", doc.elements["/a/c"].text assert_equal '"', doc.elements["//d"].text # test some other stuff doc = Document.new '<a><b/></a>' doc.root.text = 'Sean' assert_equal '<a><b/>Sean</a>', doc.to_s doc.root.text = 'Elliott' assert_equal '<a><b/>Elliott</a>', doc.to_s doc.root.add_element 'c' assert_equal '<a><b/>Elliott<c/></a>', doc.to_s doc.root.text = 'Russell' assert_equal '<a><b/>Russell<c/></a>', doc.to_s doc.root.text = nil assert_equal '<a><b/><c/></a>', doc.to_s end