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

ruby-changes:45384

From: nobu <ko1@a...>
Date: Mon, 30 Jan 2017 12:21:20 +0900 (JST)
Subject: [ruby-changes:45384] nobu:r57457 (trunk): test for prompt

nobu	2017-01-30 12:21:15 +0900 (Mon, 30 Jan 2017)

  New Revision: 57457

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57457

  Log:
    test for prompt

  Modified files:
    trunk/test/irb/test_ruby-lex.rb
Index: test/irb/test_ruby-lex.rb
===================================================================
--- test/irb/test_ruby-lex.rb	(revision 57456)
+++ test/irb/test_ruby-lex.rb	(revision 57457)
@@ -9,6 +9,10 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby-lex.rb#L9
       @scanner = RubyLex.new
     end
 
+    def teardown
+      RubyLex.debug_level = 0
+    end
+
     def test_set_input_proc
       called = false
       @scanner.set_input(nil) {called = true; nil}
@@ -40,6 +44,49 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby-lex.rb#L44
       assert_equal([[src, 1]], top_level_statement(src))
     end
 
+    def test_prompt
+      prompts = []
+      @scanner.set_prompt {|*a|
+        a << @scanner.instance_variable_get(:@lex_state)
+        unless prompts.last == a
+          prompts << a
+        end
+      }
+      src = "#{<<-"begin;"}#{<<~"end;"}"
+      begin;
+        if false or
+          true
+          "
+          "
+          '
+          '
+        else
+          nil
+          nil
+        end
+      end;
+      assert_equal([[src, 1]], top_level_statement(src))
+      expected = [
+        [nil, 0, false],
+        [nil, 1, true],
+        [nil, 1, false],
+        ['"', 1, false],
+        [nil, 1, false],
+        ["'", 1, false],
+        [nil, 1, false],
+        [nil, 1, true], # FIXME: just after `else' should be `false'
+        [nil, 1, false],
+        [nil, 1, false],
+        [nil, 0, false],
+      ]
+      srcs = src.lines
+      assert_equal(expected.size, prompts.size)
+      expected.each_with_index {|e, i|
+        assert_equal(i + 1, prompts[i][3])
+        assert_equal(e, prompts[i][0..2], "#{i+1}: #{srcs[i]} # #{prompts[i]}")
+      }
+    end
+
     def top_level_statement(lines)
       input = InputLines.new(lines, "r")
       scanned = []

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

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