test/sdl4r/parser_test.rb in sdl4r-0.9.7 vs test/sdl4r/parser_test.rb in sdl4r-0.9.8

- old
+ new

@@ -16,18 +16,20 @@ # 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. #++ +# Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653) +# $:[0] = File.join(File.dirname(__FILE__),'../../lib') if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"] module SDL4R - + require 'bigdecimal' require 'test/unit' - - require File.dirname(__FILE__) + '/../../lib/sdl4r/tag' + require "sdl4r/tag" + class ParserTest < Test::Unit::TestCase @@zone_offset = Rational(Time.now.utc_offset, 24 * 60 * 60) @@ -193,10 +195,14 @@ "date5"); assert_equal( local_civil_date(1807, 11, 11, 22, 28, Rational(13888, 1000), Rational(-85, 240)), tag1.attribute("date6"), "date6"); + + tag1 = parse_one_tag1("tag1 2008/06/01 5d:12:34") # not a datetime: a date + a timespan + assert_equal Date.civil(2008, 6, 1), tag1.values[0] + assert_equal SdlTimeSpan.new(5, 12, 34), tag1.values[1] end def test_numbers tag1 = parse_one_tag1( "tag1 123 3000000000 456l 789L 123.45f 67.8F 910.11 12.13d 1415.16D 171.8BD 1.920bd 12345678901234567890BD") @@ -376,9 +382,43 @@ end new_child("peanut.butter") end assert_equal expected, root + end + + def test_identifiers + root = SDL4R::read("my_ns:my_tag my_ns2:my_attr=-13.8") + assert_equal "my_ns", root.child.namespace + assert_equal "my_tag", root.child.name + assert_equal({ "my_ns2:my_attr" => -13.8 }, root.child.attributes) + + root = SDL4R::read("_my_ns:_my_tag _my_ns2:_my_attr=-13.8") + assert_equal "_my_ns", root.child.namespace + assert_equal "_my_tag", root.child.name + assert_equal({ "_my_ns2:_my_attr" => -13.8 }, root.child.attributes) + + root = SDL4R::read("my.ns:my.tag my.ns2:my.attr=-13.8") + assert_equal "my.ns", root.child.namespace + assert_equal "my.tag", root.child.name + assert_equal({ "my.ns2:my.attr" => -13.8 }, root.child.attributes) + + root = SDL4R::read("my$ns:my$tag my$ns2:my$attr=-13.8") + assert_equal "my$ns", root.child.namespace + assert_equal "my$tag", root.child.name + assert_equal({ "my$ns2:my$attr" => -13.8 }, root.child.attributes) + end + + def test_empty_block + tag1 = parse_one_tag1("tag1 {\n}") + assert_equal [], tag1.values + assert_equal({}, tag1.attributes) + assert_equal [], tag1.children + +# tag1 = parse_one_tag1("tag1 {}") +# assert_equal [], tag1.values +# assert_equal({}, tag1.attributes) +# assert_equal [], tag1.children end def test_parse_error # WARNING: the line and col of an error is not accurate science. The goal here is to point to # coordinates that are useful to the user. \ No newline at end of file