sorcerer 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sorcerer.rb +1 -0
- data/lib/sorcerer/resource.rb +11 -3
- data/lib/sorcerer/version.rb +1 -1
- data/test/sorcerer/resource_test.rb +35 -9
- metadata +2 -2
    
        data/lib/sorcerer.rb
    CHANGED
    
    
    
        data/lib/sorcerer/resource.rb
    CHANGED
    
    | @@ -74,7 +74,6 @@ module Sorcerer | |
| 74 74 | 
             
                end
         | 
| 75 75 |  | 
| 76 76 | 
             
                def resource(sexp)
         | 
| 77 | 
            -
                  sexp = sexp.first if nested_sexp?(sexp)
         | 
| 78 77 | 
             
                  fail NotSexpError, "Not an S-EXPER: #{sexp.inspect}" unless sexp?(sexp)
         | 
| 79 78 | 
             
                  handler = HANDLERS[sexp.first]
         | 
| 80 79 | 
             
                  raise NoHandlerError.new(sexp.first) unless handler
         | 
| @@ -492,7 +491,16 @@ module Sorcerer | |
| 492 491 | 
             
                    resource(sexp[1])
         | 
| 493 492 | 
             
                    emit(")")
         | 
| 494 493 | 
             
                  },
         | 
| 495 | 
            -
                  :defs =>  | 
| 494 | 
            +
                  :defs => lambda { |sexp|
         | 
| 495 | 
            +
                    emit("def ")
         | 
| 496 | 
            +
                    resource(sexp[1])
         | 
| 497 | 
            +
                    resource(sexp[2])
         | 
| 498 | 
            +
                    resource(sexp[3])
         | 
| 499 | 
            +
                    opt_parens(sexp[4])
         | 
| 500 | 
            +
                    newline
         | 
| 501 | 
            +
                    indent do resource(sexp[5]) end
         | 
| 502 | 
            +
                    emit("end")
         | 
| 503 | 
            +
                  },
         | 
| 496 504 | 
             
                  :do_block => lambda { |sexp|
         | 
| 497 505 | 
             
                    emit_block(sexp, "do", "end")
         | 
| 498 506 | 
             
                  },
         | 
| @@ -903,7 +911,7 @@ module Sorcerer | |
| 903 911 | 
             
                  :@lparen => NYI,
         | 
| 904 912 | 
             
                  :@nl => NYI,
         | 
| 905 913 | 
             
                  :@op => EMIT1,
         | 
| 906 | 
            -
                  :@period =>  | 
| 914 | 
            +
                  :@period => EMIT1,
         | 
| 907 915 | 
             
                  :@qwords_beg => NYI,
         | 
| 908 916 | 
             
                  :@rbrace => NYI,
         | 
| 909 917 | 
             
                  :@rbracket => NYI,
         | 
    
        data/lib/sorcerer/version.rb
    CHANGED
    
    
| @@ -33,9 +33,21 @@ class SourcerTest < Test::Unit::TestCase | |
| 33 33 | 
             
              # string in single line and multi-line modes.
         | 
| 34 34 | 
             
              #
         | 
| 35 35 | 
             
              def assert_resource_lines(string, options={})
         | 
| 36 | 
            -
                assert_resource_for_mode( | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 36 | 
            +
                assert_resource_for_mode(
         | 
| 37 | 
            +
                  string,
         | 
| 38 | 
            +
                  options.merge(multiline: false)) { |s|
         | 
| 39 | 
            +
                  for_single_line(s)
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
                assert_resource_for_mode(
         | 
| 42 | 
            +
                  string,
         | 
| 43 | 
            +
                  options.merge(multiline: true)) { |s|
         | 
| 44 | 
            +
                  for_multi_line(s)
         | 
| 45 | 
            +
                }
         | 
| 46 | 
            +
                assert_resource_for_mode(
         | 
| 47 | 
            +
                  string,
         | 
| 48 | 
            +
                  options.merge(indent: true)) { |s|
         | 
| 49 | 
            +
                  for_indented(s)
         | 
| 50 | 
            +
                }
         | 
| 39 51 | 
             
              end
         | 
| 40 52 |  | 
| 41 53 | 
             
              # Assert the string is correctly resourced given the options and the
         | 
| @@ -81,7 +93,13 @@ class SourcerTest < Test::Unit::TestCase | |
| 81 93 | 
             
                  puts
         | 
| 82 94 | 
             
                  puts "***************************** options: #{options.inspect}"
         | 
| 83 95 | 
             
                end
         | 
| 84 | 
            -
                sexp = quietly { | 
| 96 | 
            +
                sexp = quietly {
         | 
| 97 | 
            +
                  if options[:quick]
         | 
| 98 | 
            +
                    Ripper.sexp(string)
         | 
| 99 | 
            +
                  else
         | 
| 100 | 
            +
                    Ripper::SexpBuilder.new(string).parse
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
                }
         | 
| 85 103 | 
             
                fail "Failed to parts '#{string}'" if sexp.nil?
         | 
| 86 104 | 
             
                Sorcerer.source(sexp, options)
         | 
| 87 105 | 
             
              end
         | 
| @@ -99,6 +117,12 @@ class SourcerTest < Test::Unit::TestCase | |
| 99 117 | 
             
                assert_resource "Mod::NS::Y"
         | 
| 100 118 | 
             
              end
         | 
| 101 119 |  | 
| 120 | 
            +
              def test_can_source_keywords
         | 
| 121 | 
            +
                assert_resource "true"
         | 
| 122 | 
            +
                assert_resource "false"
         | 
| 123 | 
            +
                assert_resource "nil"
         | 
| 124 | 
            +
              end
         | 
| 125 | 
            +
             | 
| 102 126 | 
             
              def test_can_source_constant_definition
         | 
| 103 127 | 
             
                assert_resource "X = 1"
         | 
| 104 128 | 
             
                assert_resource "X::Y = 1"
         | 
| @@ -583,6 +607,13 @@ class SourcerTest < Test::Unit::TestCase | |
| 583 607 | 
             
                assert_resource_lines "def f(a); #x; #y; end"
         | 
| 584 608 | 
             
              end
         | 
| 585 609 |  | 
| 610 | 
            +
              def test_can_source_def_self
         | 
| 611 | 
            +
                assert_resource_lines "def self.f; end"
         | 
| 612 | 
            +
                assert_resource_lines "def self.f(a, *args, &block); #x; #y; end"
         | 
| 613 | 
            +
                assert_resource_lines "def Mod.f; end"
         | 
| 614 | 
            +
                assert_resource_lines "def Mod.f(a, *args, &block); #x; #y; end"
         | 
| 615 | 
            +
              end
         | 
| 616 | 
            +
             | 
| 586 617 | 
             
              def test_can_source_class_without_parent
         | 
| 587 618 | 
             
                assert_resource_lines "class X; end"
         | 
| 588 619 | 
             
                assert_resource_lines "class X; #x; end"
         | 
| @@ -630,11 +661,6 @@ class SourcerTest < Test::Unit::TestCase | |
| 630 661 | 
             
                assert_resource_lines "Then {~#a == b; #x~}"
         | 
| 631 662 | 
             
              end
         | 
| 632 663 |  | 
| 633 | 
            -
              def test_can_use_ripper_sexp_output
         | 
| 634 | 
            -
                sexp = quietly { Ripper.sexp("a = 1") }
         | 
| 635 | 
            -
                assert_equal "a = 1", Sorcerer.source(sexp)
         | 
| 636 | 
            -
              end
         | 
| 637 | 
            -
             | 
| 638 664 | 
             
              def test_can_handle_missing_statements
         | 
| 639 665 | 
             
                sexp = [:bodystmt, [:stmts_add, [:stmts_new]], nil, nil, nil]
         | 
| 640 666 | 
             
                assert_equal "", Sorcerer.source(sexp)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sorcerer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-07- | 
| 12 | 
            +
            date: 2012-07-14 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies: []
         | 
| 14 14 | 
             
            description: Generate the original Ruby source from a Ripper-style abstract syntax
         | 
| 15 15 | 
             
              tree.
         |