# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Sugar::Occurrence::DynamicValue describe self do before(:each) do @tm = get_used_tm_sys_tm @topic = @tm.get!("Leipzig") end after(:each) do @tm.close end describe "#dynamic value" do it "should return a Locator if the datatype is xsd:anyURI" do @occ = @topic.create_occurrence("Website", "http://www.example.org/Leipzig", :datatype => RTM::PSI[:IRI]) @occ.datatype.reference.should == RTM::PSI[:IRI] @occ.value.should == "http://www.example.org/Leipzig" @occ.dynamic_value.should == @tm.create_locator("http://www.example.org/Leipzig") ### @occ = @topic.create_occurrence("Website", "Leipzig", :datatype => RTM::PSI[:IRI]) @occ.datatype.reference.should == RTM::PSI[:IRI] @occ.value.should == "http://www.topicmapslab.de/Leipzig" @occ.dynamic_value.should == @tm.create_locator("http://www.topicmapslab.de/Leipzig") end it "should return a String if the datatype is xsd:string" do @occ = @topic.create_occurrence("Website", "http://www.example.org/Leipzig", :datatype => RTM::PSI[:String]) @occ.datatype.reference.should == RTM::PSI[:String] @occ.value.should == "http://www.example.org/Leipzig" @occ.dynamic_value.should == "http://www.example.org/Leipzig" end it "should return a Float if the datatype is xsd:float" do 3.5.class.should == Float @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Float]) @occ.datatype.reference.should == RTM::PSI[:Float] @occ.value.should == "3.5" @occ.dynamic_value.should == 3.5 @occ.dynamic_value.class.should == Float ### @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Float]) @occ.datatype.reference.should == RTM::PSI[:Float] @occ.value.should == "1" @occ.dynamic_value.should == 1.0 @occ.dynamic_value.class.should == Float end it "should return a Float if the datatype is xsd:double" do 3.5.class.should == Float @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Double]) @occ.datatype.reference.should == RTM::PSI[:Double] @occ.value.should == "3.5" @occ.dynamic_value.should == 3.5 @occ.dynamic_value.class.should == Float ### @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Double]) @occ.datatype.reference.should == RTM::PSI[:Double] @occ.value.should == "1" @occ.dynamic_value.should == 1.0 @occ.dynamic_value.class.should == Float end it "should return a Float if the datatype is xsd:decimal" do 3.5.class.should == Float @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Decimal]) @occ.datatype.reference.should == RTM::PSI[:Decimal] @occ.value.should == "3.5" @occ.dynamic_value.should == 3.5 @occ.dynamic_value.class.should == Float ### @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Decimal]) @occ.datatype.reference.should == RTM::PSI[:Decimal] @occ.value.should == "1" unless implementation_for_spec == :tinytim @occ.dynamic_value.should == 1.0 @occ.dynamic_value.class.should == Float end it "should return a Fixnum/Bignum if the datatype is xsd:int" do 3.5.class.should == Float @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Int]) @occ.datatype.reference.should == RTM::PSI[:Int] @occ.value.should == "3.5" @occ.dynamic_value.should == 3 @occ.dynamic_value.class.should == Fixnum ### @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Int]) @occ.datatype.reference.should == RTM::PSI[:Int] @occ.value.should == "1" @occ.dynamic_value.should == 1 @occ.dynamic_value.class.should == Fixnum #### number = 9999999999999999999 number.class.should == Bignum @occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Int]) @occ.datatype.reference.should == RTM::PSI[:Int] @occ.value.should == number.to_s @occ.dynamic_value.should == number @occ.dynamic_value.class.should == Bignum end it "should return a Fixnum/Bignum if the datatype is xsd:integer" do unless implementation_for_spec == :tinytim 3.5.class.should == Float @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Integer]) @occ.datatype.reference.should == RTM::PSI[:Integer] @occ.value.should == "3.5" @occ.dynamic_value.should == 3 @occ.dynamic_value.class.should == Fixnum end ### @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Integer]) @occ.datatype.reference.should == RTM::PSI[:Integer] @occ.value.should == "1" @occ.dynamic_value.should == 1 @occ.dynamic_value.class.should == Fixnum #### number = 9999999999999999999 number.class.should == Bignum @occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Integer]) @occ.datatype.reference.should == RTM::PSI[:Integer] @occ.value.should == number.to_s @occ.dynamic_value.should == number @occ.dynamic_value.class.should == Bignum end it "should return a Fixnum/Bignum if the datatype is xsd:integer" do 3.5.class.should == Float @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Long]) @occ.datatype.reference.should == RTM::PSI[:Long] @occ.value.should == "3.5" @occ.dynamic_value.should == 3 @occ.dynamic_value.class.should == Fixnum ### @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Long]) @occ.datatype.reference.should == RTM::PSI[:Long] @occ.value.should == "1" @occ.dynamic_value.should == 1 @occ.dynamic_value.class.should == Fixnum #### number = 9999999999999999999 number.class.should == Bignum @occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Long]) @occ.datatype.reference.should == RTM::PSI[:Long] @occ.value.should == number.to_s @occ.dynamic_value.should == number @occ.dynamic_value.class.should == Bignum end it "should return a Time if the datatype is xsd:time" do time = Time.new @occ = @topic.create_occurrence("Number", time) @occ.datatype.reference.should == RTM::PSI[:Time] @occ.value.should == time.to_s #@occ.dynamic_value.should == time # cannot be tested this way @occ.dynamic_value.class.should == Time end it "should return a Date if the datatype is xsd:date" do date = Date.new @occ = @topic.create_occurrence("Number", date) @occ.datatype.reference.should == RTM::PSI[:Date] @occ.value.should == date.to_s @occ.dynamic_value.should == date @occ.dynamic_value.class.should == Date end it "should return a DateTime if the datatype is xsd:dateTime" do dateTime = DateTime.new @occ = @topic.create_occurrence("Number", dateTime) @occ.datatype.reference.should == RTM::PSI[:DateTime] @occ.value.should == dateTime.to_s @occ.dynamic_value.should == dateTime @occ.dynamic_value.class.should == DateTime end end end end