diff --git a/spec/doc_parser_spec.rb b/spec/doc_parser_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..c65f6a84fea97ba6264183836ceb6ece4aad1d7f --- /dev/null +++ b/spec/doc_parser_spec.rb @@ -0,0 +1,103 @@ +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 + diff --git a/test/tc_doc_parser.rb b/test/tc_doc_parser.rb deleted file mode 100644 index 17b80a24b37971b97779c45d4a6e2d8b31482213..0000000000000000000000000000000000000000 --- a/test/tc_doc_parser.rb +++ /dev/null @@ -1,46 +0,0 @@ -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 -