Skip to content

Commit

Permalink
(PDOC-206) update markdown test and docstring handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eputnam committed Mar 2, 2018
1 parent affee45 commit 5bb3167
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/puppet-strings/yard/code_objects/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def to_hash
file: statement.file,
line: statement.line,
docstring: {
text: statement.json['description'],
text: statement.docstring,
tags: parameters
},
source: statement.source,
Expand Down
9 changes: 3 additions & 6 deletions lib/puppet-strings/yard/parsers/json/task_statement.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
module PuppetStrings::Yard::Parsers::JSON
# Represents the Puppet Task statement.
class TaskStatement
attr_reader :line, :comments, :comments_range, :json, :file, :source
attr_reader :line, :comments, :comments_range, :json, :file, :source, :docstring

def initialize(json, source, file)
@file = file
@source = source
@json = json
@line = 0
@comments_range = nil
end

def docstring
YARD::Docstring.new(json['description'] || "")
@docstring = YARD::Docstring.new(@json['description'])
end

def parameters
Expand All @@ -28,7 +25,7 @@ def show
end

def comments
""
docstring.all
end

def name
Expand Down
38 changes: 38 additions & 0 deletions spec/fixtures/unit/markdown/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* [`func3x`](#func3x): Documentation for an example 3.x function.
* [`func4x`](#func4x): An example 4.x function.
* [`func4x_1`](#func4x_1): An example 4.x function with only one signature.
## Tasks
* [`(stdin)`](#(stdin)): Allows you to backup your database to local file.
## Classes

### klass
Expand Down Expand Up @@ -381,3 +383,39 @@ Data type: `Integer`

The first parameter.

## Tasks

### (stdin)

Allows you to backup your database to local file.

#### Input

Input method: stdin

#### Parameters

##### `database`

Data type: `Optional[String[1]]`

Database to connect to

##### `user`

Data type: `Optional[String[1]]`

The user

##### `password`

Data type: `Optional[String[1]]`

The password

##### `sql`

Data type: `String[1]`

Path to file you want backup to

2 changes: 1 addition & 1 deletion spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class foo {
subject.parse
expect(subject.enumerator.size).to eq(1)
statement = subject.enumerator.first
expect(statement).to be_instance_of(Hash)
expect(statement).to be_instance_of(PuppetStrings::Yard::Parsers::JSON::TaskStatement)
end
end
end
56 changes: 56 additions & 0 deletions spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'spec_helper'

describe PuppetStrings::Yard::Parsers::JSON::TaskStatement do
let(:source) { <<-SOURCE
{
"description": "Allows you to backup your database to local file.",
"input_method": "stdin",
"parameters": {
"database": {
"description": "Database to connect to",
"type": "Optional[String[1]]"
},
"user": {
"description": "The user",
"type": "Optional[String[1]]"
},
"password": {
"description": "The password",
"type": "Optional[String[1]]"
},
"sql": {
"description": "Path to file you want backup to",
"type": "String[1]"
}
}
}
SOURCE
}
let(:json) { JSON.parse(source) }
subject { PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, source, "test.json") }
describe '#comments' do
it 'returns docstring' do
expect(subject.comments).to eq "Allows you to backup your database to local file."
end
end
describe '#parameters' do
context 'with params' do
it 'returns params' do
expect(subject.parameters.size > 0).to be true
end
end
context 'no params' do
let(:source) { <<-SOURCE
{
"description": "Allows you to backup your database to local file.",
"input_method": "stdin"
}
SOURCE
}
it 'returns an empty hash' do
expect(subject.parameters).to eq({})
end
end
end

end

0 comments on commit 5bb3167

Please sign in to comment.