Loading lib/jsduck/merger.rb +5 −1 Original line number Diff line number Diff line module JsDuck # Takes data from doc-comment and code that follows it and combines # these to pieces of information into one. The code comes from # JsDuck::Parser and doc-comment from JsDuck::DocParser. # # The main method merge() produces a hash as a result. class Merger def merge(docs, code) case detect_doc_type(docs, code) Loading spec/merger_spec.rb 0 → 100644 +59 −0 Original line number Diff line number Diff line require "jsduck/merger" describe JsDuck::Merger do def merge(doc, code) return JsDuck::Merger.new.merge(doc, code) end describe "only name in code" do before do @doc = merge( [{:tagname => :cfg, :type => "String", :doc => "My Config"}], { :type => :assignment, :left => ["option"] }) end it "gets tagname from doc" do @doc[:tagname].should == :cfg end it "gets type from doc" do @doc[:type].should == "String" end it "gets documentation from doc" do @doc[:doc].should == "My Config" end it "gets name from code" do @doc[:name].should == "option" end end describe "most stuff in code" do before do @doc = merge( [{:tagname => :default, :doc => "Hello world"}], { :type => :assignment, :left => ["some", "prop"], :right => {:type => :literal, :class => "Boolean"} }) end it "gets tagname from code" do @doc[:tagname].should == :property end it "gets type from code" do @doc[:type].should == "Boolean" end it "gets documentation from doc" do @doc[:doc].should == "Hello world" end it "gets name from code" do @doc[:name].should == "prop" end end end test/tc_merger.rbdeleted 100644 → 0 +0 −35 Original line number Diff line number Diff line require "jsduck/merger" require "test/unit" class TestMerger < Test::Unit::TestCase def merge(doc, code) return JsDuck::Merger.new.merge(doc, code) end def test_cfg doc = merge([ {:tagname => :cfg, :type => "String", :doc => "My Config"}, ], {:type => :assignment, :left => ["option"]} ) assert_equal(:cfg, doc[:tagname]) assert_equal("String", doc[:type]) assert_equal("My Config", doc[:doc]) assert_equal("option", doc[:name]) end def test_property doc = merge([{:tagname => :default, :doc => "Hello world"}], {:type => :assignment, :left => ["some", "prop"], :right => {:type => :literal, :class => "Boolean"}} ) assert_equal(:property, doc[:tagname]) assert_equal("Boolean", doc[:type]) assert_equal("Hello world", doc[:doc]) assert_equal("prop", doc[:name]) end end Loading
lib/jsduck/merger.rb +5 −1 Original line number Diff line number Diff line module JsDuck # Takes data from doc-comment and code that follows it and combines # these to pieces of information into one. The code comes from # JsDuck::Parser and doc-comment from JsDuck::DocParser. # # The main method merge() produces a hash as a result. class Merger def merge(docs, code) case detect_doc_type(docs, code) Loading
spec/merger_spec.rb 0 → 100644 +59 −0 Original line number Diff line number Diff line require "jsduck/merger" describe JsDuck::Merger do def merge(doc, code) return JsDuck::Merger.new.merge(doc, code) end describe "only name in code" do before do @doc = merge( [{:tagname => :cfg, :type => "String", :doc => "My Config"}], { :type => :assignment, :left => ["option"] }) end it "gets tagname from doc" do @doc[:tagname].should == :cfg end it "gets type from doc" do @doc[:type].should == "String" end it "gets documentation from doc" do @doc[:doc].should == "My Config" end it "gets name from code" do @doc[:name].should == "option" end end describe "most stuff in code" do before do @doc = merge( [{:tagname => :default, :doc => "Hello world"}], { :type => :assignment, :left => ["some", "prop"], :right => {:type => :literal, :class => "Boolean"} }) end it "gets tagname from code" do @doc[:tagname].should == :property end it "gets type from code" do @doc[:type].should == "Boolean" end it "gets documentation from doc" do @doc[:doc].should == "Hello world" end it "gets name from code" do @doc[:name].should == "prop" end end end
test/tc_merger.rbdeleted 100644 → 0 +0 −35 Original line number Diff line number Diff line require "jsduck/merger" require "test/unit" class TestMerger < Test::Unit::TestCase def merge(doc, code) return JsDuck::Merger.new.merge(doc, code) end def test_cfg doc = merge([ {:tagname => :cfg, :type => "String", :doc => "My Config"}, ], {:type => :assignment, :left => ["option"]} ) assert_equal(:cfg, doc[:tagname]) assert_equal("String", doc[:type]) assert_equal("My Config", doc[:doc]) assert_equal("option", doc[:name]) end def test_property doc = merge([{:tagname => :default, :doc => "Hello world"}], {:type => :assignment, :left => ["some", "prop"], :right => {:type => :literal, :class => "Boolean"}} ) assert_equal(:property, doc[:tagname]) assert_equal("Boolean", doc[:type]) assert_equal("Hello world", doc[:doc]) assert_equal("prop", doc[:name]) end end