[前][次][番号順一覧][スレッド一覧]

ruby-changes:19031

From: nobu <ko1@a...>
Date: Tue, 8 Mar 2011 23:41:10 +0900 (JST)
Subject: [ruby-changes:19031] Ruby:r31069 (trunk): * test/misc/test_ruby_mode.rb: test for ruby-mode.el.

nobu	2011-03-08 23:40:33 +0900 (Tue, 08 Mar 2011)

  New Revision: 31069

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31069

  Log:
    * test/misc/test_ruby_mode.rb: test for ruby-mode.el.

  Added directories:
    trunk/test/misc/
  Added files:
    trunk/test/misc/test_ruby_mode.rb
  Modified files:
    trunk/ChangeLog

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31068)
+++ ChangeLog	(revision 31069)
@@ -1,3 +1,7 @@
+Tue Mar  8 23:40:30 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* test/misc/test_ruby_mode.rb: test for ruby-mode.el.
+
 Tue Mar  8 23:27:38 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* process.c (get_sc_ngroups_max): try to use NGROUPS_MAX at first if
Index: test/misc/test_ruby_mode.rb
===================================================================
--- test/misc/test_ruby_mode.rb	(revision 0)
+++ test/misc/test_ruby_mode.rb	(revision 31069)
@@ -0,0 +1,136 @@
+require 'test/unit'
+require 'tempfile'
+require 'mkmf'
+
+class TestRubyMode < Test::Unit::TestCase
+  MISCDIR = File.expand_path("../../../misc", __FILE__)
+  if emacs = find_executable0(ENV["EMACS"] || "emacs")
+    EMACS = %W"#{emacs} --quick --batch --load #{MISCDIR}/ruby-mode.el"
+  else
+    EMACS = nil
+  end
+end
+
+class TestRubyMode
+  EVAL_OPT = "--eval"
+  EXPR_SAVE = "(save-buffer)"
+  EXPR_RUBYMODE = "(ruby-mode)"
+  EXPR_NOBACKUP = "(progn" \
+  " (set (make-local-variable \'backup-inhibited) t)" \
+  " (set-buffer-modified-p t)" \
+  ")"
+
+  def run_emacs(src, *exprs)
+    tmp = Tempfile.new(%w"ruby-mode.test. .rb")
+    tmp.puts(src)
+    tmp.close
+    exprs = exprs.map {|expr| [EVAL_OPT, expr]}.flatten
+    exprs.unshift(EVAL_OPT, EXPR_RUBYMODE)
+    exprs.unshift(EVAL_OPT, EXPR_NOBACKUP)
+    output = IO.popen([*EMACS, tmp.path, *exprs, err:[:child, :out]], "r") {|e| e.read}
+    tmp.open
+    result = tmp.read
+    tmp.close!
+    return result, output
+  end
+
+  class TestIndent < self
+    EXPR_INDENT = "(indent-region (point-min) (point-max))"
+
+    def assert_indent(expected, source, *message)
+      if space = expected[/\A\n?(\s*\|)/, 1]
+        space = /^#{Regexp.quote(space)}/m
+        expected.gsub!(space, '')
+        source.gsub!(space, '')
+      end
+      result, output = run_emacs(source, EXPR_INDENT, EXPR_SAVE)
+      assert_match(/^Wrote /, output)
+      assert_equal(expected, result, *message)
+    end
+
+    def test_simple
+      assert_indent('
+      |if foo
+      |  bar
+      |end
+      |zot
+      |', '
+      |if foo
+      |bar
+      |  end
+      |    zot
+      |')
+    end
+
+    def test_keyword_label
+      assert_indent('
+      |bar(class: XXX) do
+      |  foo
+      |end
+      |bar
+      |', '
+      |bar(class: XXX) do
+      |     foo
+      |  end
+      |    bar
+      |')
+    end
+
+    def test_method_with_question_mark
+      assert_indent('
+      |if x.is_a?(XXX)
+      |  foo
+      |end
+      |', '
+      |if x.is_a?(XXX)
+      | foo
+      |   end
+      |')
+    end
+
+    def test_expr_in_regexp
+      assert_indent('
+      |if /#{foo}/ =~ s
+      |  x = 1
+      |end
+      |', '
+      |if /#{foo}/ =~ s
+      | x = 1
+      |  end
+      |')
+    end
+
+    def test_singleton_class
+      assert_indent('
+      |class<<bar
+      |  foo
+      |end
+      |', '
+      |class<<bar
+      |foo
+      |   end
+      |')
+    end
+
+    def test_array_literal
+      assert_indent('
+      |foo = [
+      |  bar
+      |]
+      |', '
+      |foo = [
+      | bar
+      |  ]
+      |')
+      assert_indent('
+      |foo do
+      |  [bar]
+      |end
+      |', '
+      |foo do
+      |[bar]
+      |  end
+      |')
+    end
+  end
+end if TestRubyMode::EMACS

Property changes on: test/misc/test_ruby_mode.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]