Skip to content

Commit

Permalink
Merge branch 'pr-1171'
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Jun 3, 2018
2 parents 41e6c84 + 3eca759 commit 44ca65d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
38 changes: 38 additions & 0 deletions spec/cli/yard_on_yard_spec.rb
@@ -0,0 +1,38 @@
# frozen_string_literal: true

$TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '../..'))

require 'fileutils'

RSpec.describe YARD::CLI::Yardoc do
include FileUtils

context 'building the documentation of YARD itself' do
before(:context) do
rm_rf File.join($TOPDIR, 'doc')
rm_rf File.join($TOPDIR, '.yardoc')

# Note: as this is very time consuming, we do it only once
Dir.chdir($TOPDIR) do
@res = YARD::CLI::Yardoc.new.run('--title', 'YARD-On-YARD')
end
end

it 'succeeds and creates doc/ and .yardoc/' do
expect(@res).to be true
expect(Dir.exist?('doc')).to be true
expect(Dir.exist?('.yardoc')).to be true
end

it 'writes the given title in each documentation file' do
Dir.glob(File.join($TOPDIR, 'doc/**/*.html')) do |htmlfile|
next if %w(
frames file_list class_list method_list tag_list _index
).include?(File.basename(htmlfile, '.html'))
html = File.read(htmlfile)

expect(html.index('— YARD-On-YARD')).to be >= 0
end
end
end
end if ENV['CI'] || ENV['YY']
32 changes: 17 additions & 15 deletions spec/parser/ruby/legacy/token_list_spec.rb
@@ -1,18 +1,20 @@
# frozen_string_literal: true

include YARD::Parser::Ruby::Legacy
include YARD::Parser::Ruby::Legacy::RubyToken

RSpec.describe YARD::Parser::Ruby::Legacy::TokenList do
Legacy = YARD::Parser::Ruby::Legacy
TokenList = Legacy::TokenList
LT = Legacy::RubyToken

describe "#initialize / #push" do
it "accepts a tokenlist (via constructor or push)" do
expect { TokenList.new(TokenList.new) }.not_to raise_error
expect(TokenList.new.push(TokenList.new("x = 2")).size).to eq 6
end

it "accept a token (via constructor or push)" do
expect { TokenList.new(Token.new(0, 0)) }.not_to raise_error
expect(TokenList.new.push(Token.new(0, 0), Token.new(1, 1)).size).to eq 2
expect { TokenList.new(LT::Token.new(0, 0)) }.not_to raise_error
expect(TokenList.new.push(LT::Token.new(0, 0),
LT::Token.new(1, 1)).size).to eq 2
end

it "accepts a string and parse it as code (via constructor or push)" do
Expand All @@ -30,29 +32,29 @@
it "does not interpolate string data" do
x = TokenList.new('x = "hello #{world}"')
expect(x.size).to eq 6
expect(x[4].class).to eq TkDSTRING
expect(x[4].class).to eq LT::TkDSTRING
expect(x.to_s).to eq 'x = "hello #{world}"' + "\n"
end

it "handles label syntax" do
x = TokenList.new('a:1,b:2')
expect(x[0].class).to eq TkLABEL
expect(x[0].class).to eq LT::TkLABEL
expect(x[0].text).to eq 'a:'
expect(x[3].class).to eq TkLABEL
expect(x[3].class).to eq LT::TkLABEL
expect(x[3].text).to eq 'b:'
end
end

describe "#to_s" do
before do
@t = TokenList.new
@t << TkDEF.new(1, 1, "def")
@t << TkSPACE.new(1, 1)
@t << TkIDENTIFIER.new(1, 1, "x")
@t << TkStatementEnd.new(1, 1)
@t << TkSEMICOLON.new(1, 1) << TkSPACE.new(1, 1)
@t << TkBlockContents.new(1, 1)
@t << TkSPACE.new(1, 1) << TkEND.new(1, 1, "end")
@t << LT::TkDEF.new(1, 1, "def")
@t << LT::TkSPACE.new(1, 1)
@t << LT::TkIDENTIFIER.new(1, 1, "x")
@t << LT::TkStatementEnd.new(1, 1)
@t << LT::TkSEMICOLON.new(1, 1) << LT::TkSPACE.new(1, 1)
@t << LT::TkBlockContents.new(1, 1)
@t << LT::TkSPACE.new(1, 1) << LT::TkEND.new(1, 1, "end")
@t[0].set_text "def"
@t[1].set_text " "
@t[2].set_text "x"
Expand Down

0 comments on commit 44ca65d

Please sign in to comment.