Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <web-client> network : Added String#to_xml.
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Tue, 15 Sep 2009 10:43:32 +0200
  • Message-id: <E1MnU2D-00049n-Kv@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit d811b06a9213a647143ca003822f6ce96d589ddb
Author: Martin Vidner <mvidner@xxxxxxx>
Date: Tue Sep 15 10:43:32 2009 +0200

Added String#to_xml.

Preparing to fix serialization of arrays of plain strings.
---
plugins/network/lib/string_serialization.rb | 11 ++++++
.../network/test/unit/string_serialization_test.rb | 34 ++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/plugins/network/lib/string_serialization.rb
b/plugins/network/lib/string_serialization.rb
new file mode 100644
index 0000000..7edaba3
--- /dev/null
+++ b/plugins/network/lib/string_serialization.rb
@@ -0,0 +1,11 @@
+# fixing serialization of arrays of plain strings
+
+class String
+ def to_xml(options = {})
+ require 'builder' unless defined?(Builder)
+ xml = options[:builder] ||= Builder::XmlMarkup.new(options)
+ xml.instruct! unless options[:skip_instruct]
+
+ xml.tag! :string, self
+ end unless method_defined?(:to_xml)
+end
diff --git a/plugins/network/test/unit/string_serialization_test.rb
b/plugins/network/test/unit/string_serialization_test.rb
new file mode 100644
index 0000000..a3fb9d0
--- /dev/null
+++ b/plugins/network/test/unit/string_serialization_test.rb
@@ -0,0 +1,34 @@
+require 'test_helper'
+require 'string_serialization'
+
+# a stupid modification to see if passing a special builder works
+class MyBuilder < Builder::XmlMarkup
+ def tag! name, content
+ super "my#{name}", content
+ end
+end
+
+class StringSerializationTest < Test::Unit::TestCase
+
+ def setup
+ @options = {:skip_instruct => true}
+ end
+
+ def test_plain
+ assert_equal "<string>foo</string>", "foo".to_xml(@options)
+ end
+
+ def test_full
+ assert_equal "<?xml version=\"1.0\"
encoding=\"UTF-8\"?><string>foo</string>", "foo".to_xml
+ end
+
+ def test_escaping
+ assert_equal "<string>&amp;</string>", "&".to_xml(@options)
+ end
+
+ def test_special_builder
+ my_builder = MyBuilder.new()
+ assert_equal "<mystring>foo</mystring>",
"foo".to_xml(@options.merge(:builder => my_builder))
+ end
+
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages