sanemat / ruby-parser-book

2 stars 0 forks source link

AST to ASTのテスト #14

Open sanemat opened 9 years ago

sanemat commented 9 years ago

AST to ASTのテストを書くのに、Module: AST::Sexp 見ながら、手描きの温かみのあるASTでテストを書いたが、これを逐一書くのは非常にしんどい

結論から言うと、expected: AST, actual: ASTのテストを書くのは早めに諦めて、expected: String(contents), actual String(contents) を互いにASTにして比較、というテストにした。

テストのサポートのメソッドもライブラリ側に生やした。

問題はX140 遅いことだけど、まあ手書きの温かみのあるのはキビシイので、ひとまず。

    # NOTE: Too slow(140X slower).
    #       ast:      0.00487 seconds
    #       contents: 0.678528 seconds

どうにかサポートが有るのが、string(Gemfile) to ast(string) だけなのが厳しい。string(Gemfile) to ast(include sexp形式), ast(string) to ast(object), ast(include sexp形式) to string(Gemfile), あたりの相互変換がうまくないとツライ。

出来るのはこれだけなので。

$ cat ~/Dropbox/miso/2014-12-08-07-38-20.txt
gem 'bar'
gem 'action_args'
source 'https://rubygems.org'
ruby '2.1.5'
$ cat ~/Dropbox/miso/2014-12-08-07-38-20.txt| ruby-parse-wrapped -
(begin
  (send nil :gem
    (str "bar"))
  (send nil :gem
    (str "action_args"))
  (send nil :source
    (str "https://rubygems.org"))
  (send nil :ruby
    (str "2.1.5")))