Loading spec/doc_parser_spec.rb 0 → 100644 +103 −0 Original line number Diff line number Diff line require "jsduck/doc_parser" describe JsDuck::DocParser do def parse_single(doc) return JsDuck::DocParser.new.parse(doc) end describe "simple method doc-comment" do before do @doc = parse_single(<<-EOS.strip) /** * @method foo * Some docs. * @param {Number} x doc for x * @return {String} resulting value */ EOS end it "produces 3 @tags" do @doc.length.should == 3 end describe "@method" do before do @tag = @doc[0] end it "detects tagname" do @tag[:tagname].should == :method end it "detects name" do @tag[:name].should == "foo" end it "detects doc" do @tag[:doc].should == "Some docs." end end describe "@param" do before do @tag = @doc[1] end it "detects tagname" do @tag[:tagname].should == :param end it "detects name" do @tag[:name].should == "x" end it "detects type" do @tag[:type].should == "Number" end it "detects doc" do @tag[:doc].should == "doc for x" end end describe "@return" do before do @tag = @doc[2] end it "detects tagname" do @tag[:tagname].should == :return end it "detects type" do @tag[:type].should == "String" end it "detects doc" do @tag[:doc].should == "resulting value" end end end describe "@type without curlies" do before do @tag = parse_single(<<-EOS.strip)[0] /** * @type Boolean|String */ EOS end it "detects tagname" do @tag[:tagname].should == :type end it "detects tagname" do @tag[:type].should == "Boolean|String" end end describe "single-line doc-comment" do before do @tag = parse_single("/** @event blah */")[0] end it "detects tagname" do @tag[:tagname].should == :event end it "detects name" do @tag[:name].should == "blah" end end end test/tc_doc_parser.rbdeleted 100644 → 0 +0 −46 Original line number Diff line number Diff line require "jsduck/doc_parser" require "test/unit" class TestDocParser < Test::Unit::TestCase def parse_single(doc) return JsDuck::DocParser.new.parse(doc) end def test_method doc = parse_single("/** * @method foo * Some docs. * @param {Number} x doc for x * @return {String} resulting value */") assert_equal(:method, doc[0][:tagname]) assert_equal("foo", doc[0][:name]) assert_equal("Some docs.", doc[0][:doc]) assert_equal(:param, doc[1][:tagname]) assert_equal("x", doc[1][:name]) assert_equal("Number", doc[1][:type]) assert_equal("doc for x", doc[1][:doc]) assert_equal(:return, doc[2][:tagname]) assert_equal("String", doc[2][:type]) assert_equal("resulting value", doc[2][:doc]) end def test_type_without_curlies doc = parse_single("/** * @type Boolean|String */") assert_equal(:type, doc[0][:tagname]) assert_equal("Boolean|String", doc[0][:type]) end def test_single_line_doc_comment doc = parse_single("/** @event blah */") assert_equal(:event, doc[0][:tagname]) assert_equal("blah", doc[0][:name]) end end Loading
spec/doc_parser_spec.rb 0 → 100644 +103 −0 Original line number Diff line number Diff line require "jsduck/doc_parser" describe JsDuck::DocParser do def parse_single(doc) return JsDuck::DocParser.new.parse(doc) end describe "simple method doc-comment" do before do @doc = parse_single(<<-EOS.strip) /** * @method foo * Some docs. * @param {Number} x doc for x * @return {String} resulting value */ EOS end it "produces 3 @tags" do @doc.length.should == 3 end describe "@method" do before do @tag = @doc[0] end it "detects tagname" do @tag[:tagname].should == :method end it "detects name" do @tag[:name].should == "foo" end it "detects doc" do @tag[:doc].should == "Some docs." end end describe "@param" do before do @tag = @doc[1] end it "detects tagname" do @tag[:tagname].should == :param end it "detects name" do @tag[:name].should == "x" end it "detects type" do @tag[:type].should == "Number" end it "detects doc" do @tag[:doc].should == "doc for x" end end describe "@return" do before do @tag = @doc[2] end it "detects tagname" do @tag[:tagname].should == :return end it "detects type" do @tag[:type].should == "String" end it "detects doc" do @tag[:doc].should == "resulting value" end end end describe "@type without curlies" do before do @tag = parse_single(<<-EOS.strip)[0] /** * @type Boolean|String */ EOS end it "detects tagname" do @tag[:tagname].should == :type end it "detects tagname" do @tag[:type].should == "Boolean|String" end end describe "single-line doc-comment" do before do @tag = parse_single("/** @event blah */")[0] end it "detects tagname" do @tag[:tagname].should == :event end it "detects name" do @tag[:name].should == "blah" end end end
test/tc_doc_parser.rbdeleted 100644 → 0 +0 −46 Original line number Diff line number Diff line require "jsduck/doc_parser" require "test/unit" class TestDocParser < Test::Unit::TestCase def parse_single(doc) return JsDuck::DocParser.new.parse(doc) end def test_method doc = parse_single("/** * @method foo * Some docs. * @param {Number} x doc for x * @return {String} resulting value */") assert_equal(:method, doc[0][:tagname]) assert_equal("foo", doc[0][:name]) assert_equal("Some docs.", doc[0][:doc]) assert_equal(:param, doc[1][:tagname]) assert_equal("x", doc[1][:name]) assert_equal("Number", doc[1][:type]) assert_equal("doc for x", doc[1][:doc]) assert_equal(:return, doc[2][:tagname]) assert_equal("String", doc[2][:type]) assert_equal("resulting value", doc[2][:doc]) end def test_type_without_curlies doc = parse_single("/** * @type Boolean|String */") assert_equal(:type, doc[0][:tagname]) assert_equal("Boolean|String", doc[0][:type]) end def test_single_line_doc_comment doc = parse_single("/** @event blah */") assert_equal(:event, doc[0][:tagname]) assert_equal("blah", doc[0][:name]) end end