summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/tc_signal.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/tc_signal.py b/test/tc_signal.py
index 67625505..a585a86b 100644
--- a/test/tc_signal.py
+++ b/test/tc_signal.py
@@ -15,7 +15,7 @@
 
 if __name__ == '__main__': from __init__ import init; init()
 import unittest
-from ranger.ext.signal_dispatcher import SignalDispatcher
+from ranger.ext.signal_dispatcher import *
 
 class TestSignal(unittest.TestCase):
 	def setUp(self):
@@ -75,5 +75,47 @@ class TestSignal(unittest.TestCase):
 		sd.signal_emit('setnumber', number=100)
 		self.assertEqual(None, lst[-1])
 
+	def test_regexp_signals(self):
+		sd = RegexpSignalDispatcher()
+		lst = []
+		def modify(s):
+			s.number = 5
+		def set_number(s):
+			lst.append(s.number)
+		def stopit(s):
+			s.stop()
+
+		h1 = sd.signal_bind_regexp('.*ar', modify, priority=1)
+
+		sd.signal_bind('xyz', set_number)
+		sd.signal_bind('foobar', set_number)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(10, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(5, lst[-1])
+
+		h2 = sd.signal_bind_regexp('x.z', modify, priority=1)
+#		print(sd._signals)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(5, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(5, lst[-1])
+
+		sd.signal_unbind(h2)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(10, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(5, lst[-1])
+
+		sd.signal_unbind(h1)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(10, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(10, lst[-1])
+
 if __name__ == '__main__':
 	unittest.main()
ring.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
(selective-load "mu.arc" section-level)
(set allow-raw-addresses*)

(section 100

(reset)
(new-trace "new-screen")
(add-code:readfile "edit.mu")
(add-code
  '((function test-new-screen [
      (1:screen-address/global <- new-screen 5:literal 5:literal)
     ])))
;? (each stmt function*!new-screen
;?   (prn stmt))
(let routine make-routine!test-new-screen
  (let before rep.routine!alloc
;?     (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1")))
    (run 'test-new-screen)
;?     (prn memory*)
;?     (prn memory*.2001)
    (when (~is (memory* memory*.1) 5)  ; number of rows
      (prn "F - newly-allocated screen doesn't have the right number of rows: @(memory* memory*!2001)"))
    (let row-pointers (let base (+ 1 memory*.1)
                        (range base (+ base 4)))
  ;?     (prn row-pointers)
      (when (some nil (map memory* row-pointers))
        (prn "F - newly-allocated screen didn't initialize all of its row pointers"))
      (when (~all 5 (map memory* (map memory* row-pointers)))
        (prn "F - newly-allocated screen didn't initialize all of its row lengths")))))

(reset)

)  ; section 100 for all editor code