[Groonga-commit] droonga/drntest at 17352c2 [master] Move directive parsing code to loader from directive

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Dec 17 22:39:12 JST 2013


Kouhei Sutou	2013-12-17 22:39:12 +0900 (Tue, 17 Dec 2013)

  New Revision: 17352c20ea3a92b17c90cd8cb46908b4d6566db3
  https://github.com/droonga/drntest/commit/17352c20ea3a92b17c90cd8cb46908b4d6566db3

  Message:
    Move directive parsing code to loader from directive
    
    Because loading is the work for loader.

  Modified files:
    lib/drntest/test-loader.rb

  Modified: lib/drntest/test-loader.rb (+20 -21)
===================================================================
--- lib/drntest/test-loader.rb    2013-12-17 22:30:03 +0900 (56619e1)
+++ lib/drntest/test-loader.rb    2013-12-17 22:39:12 +0900 (33c3d97)
@@ -44,17 +44,20 @@ module Drntest
       data = ""
       Pathname(path).read.each_line do |line|
         data << line
-        if line[0] == "#"
-          if Directive.directive?(line)
-            directive = Directive.new(line)
-            if directive.type == :include
-              included = resolve_relative_path(directive.value)
-              included_operations = load_test_file(included)
-              operations += included_operations
-            else
-              operations << directive
-            end
+        case line.chomp
+        when /\A\#\@([^\s]+)(?:\s+(.+))?\z/
+          type = $1
+          value = $2
+          directive = Directive.new(type, value)
+          if directive.type == :include
+            included = resolve_relative_path(directive.value)
+            included_operations = load_test_file(included)
+            operations += included_operations
+          else
+            operations << directive
           end
+        when /\A\#/
+          # comment
         else
           begin
             parser << line
@@ -68,20 +71,16 @@ module Drntest
     end
 
     class Directive
-      MATCHER = /\A\#\@([^\s]+)(?:\s+(.+))?\z/.freeze
+      attr_reader :type, :value
 
-      class << self
-        def directive?(source)
-          MATCHER =~ source.strip
-        end
+      def initialize(type, value)
+        @type = normalize_type(type)
+        @value = value
       end
 
-      attr_reader :type, :value
-
-      def initialize(source)
-        MATCHER =~ source.strip
-        @value = $2
-        @type = $1.gsub("-", "_").to_sym
+      private
+      def normalize_type(type)
+        type.gsub("-", "_").to_sym
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index