Comment driven spec builder for Crystal.
- This is a spec string generator.
- This is not a kind of spec tools.
- crystal: 0.26.1
Add this to your application's shard.yml:
dependencies:
comment-spec:
github: maiha/comment-spec.cr
version: 1.0.0require "comment-spec"
CommentSpec.parse "1 + 2 # => 3" # => "( 1 + 2 ).should eq( 3 )"
CommentSpec.parse "value # => 2016-03-31 12:36:21" # => "( value ).should eq( Time.parse(\"2016-03-31 12:36:21\", \"%F %T\") )"
CommentSpec.parse "v[10] # raises IndexError" # => "expect_raises(IndexError) { v[10] }"
CommentSpec.parse "value # => #<XXX>" # => "( value ).class.to_s.should eq( \"XXX\" )"- rule: src/comment-spec/lexer_parser.cr
- spec: spec/fixtures/
This library is a line based parser. So, following partial code is processed as is.
...
end # => [1,2]
This library extract a comment from source by using three parsers.
This parses the code by using Crystal::Lexer. Although this can strictly parse codes, therefore it would raise error when the case of partial or invalid codes.
struct Foo # a some comment here
# or
[] # raises error
Crystal::Parser would fail with unexpected :EOF.
This parses the code by using Regex. This simply scans a code with /#/ and split it into code and comment. So, somtimes the parsing result would be wrong, but never fails.
This basically uses LexerParser and fallback with RegexParser. So, it's easy to use for API because CommentSpec.parse(line) can parse almost codes with best effort.
make spec- Fork it ( https://github.com/maiha/comment-spec.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- maiha maiha - creator, maintainer