#-- # Simple Declarative Language (SDL) for Ruby # Copyright 2005 Ikayzo, inc. # # This program is free software. You can distribute or modify it under the # terms of the GNU Lesser General Public License version 2.1 as published by # the Free Software Foundation. # # This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND, # INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, contact the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #++ module SDL4R require 'bigdecimal' require 'test/unit' require File.dirname(__FILE__) + '/../../lib/sdl4r/tag' require File.dirname(__FILE__) + '/../../lib/sdl4r/sdl_binary' class ParserTest < Test::Unit::TestCase public def test_empty root = Tag.new("root") root.read("") root.children(false) { fail("no child expected") } end def test_one_tag_alone # Tag without namespace tag1 = parse_one_tag1("tag1") assert_equal("tag1", tag1.name, "name" ) assert_equal("", tag1.namespace, "namespace" ) assert_equal(0, tag1.values.size, "values") assert_equal(0, tag1.attributes.size, "attributes") # Tag with namespace tag1 = parse_one_tag1("ns1:tag1") assert_equal("tag1", tag1.name, "name" ) assert_equal("ns1", tag1.namespace, "namespace" ) end def test_tag_with_one_value tag1 = parse_one_tag1("tag1 1") assert_not_nil(tag1, "tag1") assert_equal(1, tag1.value, "value") end def test_tag_with_two_values tag1 = parse_one_tag1("tag1 1 \"abc\"") assert_not_nil(tag1, "tag1") values = tag1.values assert_equal(1, values[0], "1st value") assert_equal("abc", values[1], "2nd value") end def test_tag_with_double_quote_string_values tag1 = parse_one_tag1("tag1 \"abc\" \"d\\\ne\\\nf\" \"g\\\n \t hi\"") assert_not_nil(tag1, "tag1") values = tag1.values assert_equal("abc", values[0], "values[0]") assert_equal("def", values[1], "values[1]") assert_equal("ghi", values[2], "values[2]") end def test_tag_with_back_quote_string_values tag1 = parse_one_tag1( "tag1 `abc` \"d`e`f\" `g\"h\"i` `j\\k+l` `m\\\nn\\\r\n \t o\r`") assert_not_nil(tag1, "tag1") values = tag1.values assert_equal("abc", values[0], "values[0]") assert_equal("d`e`f", values[1], "values[1]") assert_equal("g\"h\"i", values[2], "values[2]") assert_equal("j\\k+l", values[3], "values[3]") assert_equal("m\\\nn\\\n \t o\n", values[4], "values[4]") end def test_tag_with_base64_values tag1 = parse_one_tag1( < ` regex `\\w+\\.suite\\(\\)` EOF assert_equal "c:\\directory\\myfile.xls", root.child("winfile").value assert_equal 'I said "something"', root.child("talk").value assert_equal( "\n\n \n\n", root.child("xml").value) assert_equal "\\w+\\.suite\\(\\)", root.child("regex").value end def test_sub_tags root = SDL4R::read <