Loading spec/tree_spec.rb 0 → 100644 +119 −0 Original line number Diff line number Diff line require "jsduck/class" require "jsduck/tree" describe JsDuck::Tree do before do @tree = JsDuck::Tree.new.create([ JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.SampleClass"}), JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.Singleton", :singleton => true}), ]) end describe "creates root node" do it "with special id, text and icons" do @tree[:id].should == "apidocs" @tree[:text].should == "API Documentation" @tree[:iconCls].should == "icon-docs" end it "with singleClickExpand = true" do @tree[:singleClickExpand].should == true end it "with as many children as there are root packages" do @tree[:children].length.should == 1 end end describe "creates package nodes" do before do @package = @tree[:children][0] end it "with id reflecting package name" do @package[:id].should == "pkg-SamplePackage" end it "with text being package name" do @package[:text].should == "SamplePackage" end it "with icon being package icon" do @package[:iconCls].should == "icon-pkg" end it "with cls = 'package'" do @package[:cls].should == "package" end it "with singleClickExpand = true" do @package[:singleClickExpand].should == true end it "with as many children as there are classes inside this packages" do @package[:children].length.should == 2 end end shared_examples_for "all class nodes" do it "with isClass = true" do @class[:isClass].should == true end it "with cls = 'cls'" do @class[:isClass].should == true end it "with id being full class name" do @class[:id].should == @full_class_name end it "with text being short class name" do @class[:text].should == @short_class_name end it "with href pointing to output/ClassName.html" do @class[:href].should == "output/" + @full_class_name + ".html" end it "with leaf = true" do @class[:leaf].should == true end end describe "creates normal class nodes" do before do @class = @tree[:children][0][:children][0] @short_class_name = "SampleClass" @full_class_name = "SamplePackage.SampleClass" end it_should_behave_like "all class nodes" it "with normal class icon" do @class[:iconCls].should == "icon-cls" end end describe "creates singleton class nodes" do before do @class = @tree[:children][0][:children][1] @short_class_name = "Singleton" @full_class_name = "SamplePackage.Singleton" end it_should_behave_like "all class nodes" it "with singleton class icon" do @class[:iconCls].should == "icon-static" end end end test/tc_tree.rbdeleted 100644 → 0 +0 −50 Original line number Diff line number Diff line require "jsduck/class" require "jsduck/tree" require "test/unit" class TestTree < Test::Unit::TestCase def test_create output = JsDuck::Tree.new.create([ JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.SampleClass"}), JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.Singleton", :singleton => true}), ]) assert_equal({ :id => "apidocs", :iconCls => "icon-docs", :text => "API Documentation", :singleClickExpand => true, :children => [ { :id => "pkg-SamplePackage", :text => "SamplePackage", :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [ { :href => "output/SamplePackage.SampleClass.html", :text => "SampleClass", :id => "SamplePackage.SampleClass", :isClass => true, :iconCls => "icon-cls", :cls => "cls", :leaf => true }, { :href => "output/SamplePackage.Singleton.html", :text => "Singleton", :id => "SamplePackage.Singleton", :isClass => true, :iconCls => "icon-static", :cls => "cls", :leaf => true } ] } ] }, output) end end Loading
spec/tree_spec.rb 0 → 100644 +119 −0 Original line number Diff line number Diff line require "jsduck/class" require "jsduck/tree" describe JsDuck::Tree do before do @tree = JsDuck::Tree.new.create([ JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.SampleClass"}), JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.Singleton", :singleton => true}), ]) end describe "creates root node" do it "with special id, text and icons" do @tree[:id].should == "apidocs" @tree[:text].should == "API Documentation" @tree[:iconCls].should == "icon-docs" end it "with singleClickExpand = true" do @tree[:singleClickExpand].should == true end it "with as many children as there are root packages" do @tree[:children].length.should == 1 end end describe "creates package nodes" do before do @package = @tree[:children][0] end it "with id reflecting package name" do @package[:id].should == "pkg-SamplePackage" end it "with text being package name" do @package[:text].should == "SamplePackage" end it "with icon being package icon" do @package[:iconCls].should == "icon-pkg" end it "with cls = 'package'" do @package[:cls].should == "package" end it "with singleClickExpand = true" do @package[:singleClickExpand].should == true end it "with as many children as there are classes inside this packages" do @package[:children].length.should == 2 end end shared_examples_for "all class nodes" do it "with isClass = true" do @class[:isClass].should == true end it "with cls = 'cls'" do @class[:isClass].should == true end it "with id being full class name" do @class[:id].should == @full_class_name end it "with text being short class name" do @class[:text].should == @short_class_name end it "with href pointing to output/ClassName.html" do @class[:href].should == "output/" + @full_class_name + ".html" end it "with leaf = true" do @class[:leaf].should == true end end describe "creates normal class nodes" do before do @class = @tree[:children][0][:children][0] @short_class_name = "SampleClass" @full_class_name = "SamplePackage.SampleClass" end it_should_behave_like "all class nodes" it "with normal class icon" do @class[:iconCls].should == "icon-cls" end end describe "creates singleton class nodes" do before do @class = @tree[:children][0][:children][1] @short_class_name = "Singleton" @full_class_name = "SamplePackage.Singleton" end it_should_behave_like "all class nodes" it "with singleton class icon" do @class[:iconCls].should == "icon-static" end end end
test/tc_tree.rbdeleted 100644 → 0 +0 −50 Original line number Diff line number Diff line require "jsduck/class" require "jsduck/tree" require "test/unit" class TestTree < Test::Unit::TestCase def test_create output = JsDuck::Tree.new.create([ JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.SampleClass"}), JsDuck::Class.new({:tagname => :class, :name => "SamplePackage.Singleton", :singleton => true}), ]) assert_equal({ :id => "apidocs", :iconCls => "icon-docs", :text => "API Documentation", :singleClickExpand => true, :children => [ { :id => "pkg-SamplePackage", :text => "SamplePackage", :iconCls => "icon-pkg", :cls => "package", :singleClickExpand => true, :children => [ { :href => "output/SamplePackage.SampleClass.html", :text => "SampleClass", :id => "SamplePackage.SampleClass", :isClass => true, :iconCls => "icon-cls", :cls => "cls", :leaf => true }, { :href => "output/SamplePackage.Singleton.html", :text => "Singleton", :id => "SamplePackage.Singleton", :isClass => true, :iconCls => "icon-static", :cls => "cls", :leaf => true } ] } ] }, output) end end