Skip to content
This repository
tree: 9e50f0cb61
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 43 lines (40 sloc) 1.543 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
;; test_swizzling.nu
;; tests for Nu method swizzling.
;;
;; Copyright (c) 2007 Tim Burks, Radtastical Inc.

(class TestSwizzling is NuTestCase
     
     (- (id) testInstanceMethodSwizzling is
        (class Test1 is NSObject
             (- (id) foo is "foo")
             (- (id) bar is "bar"))
        (set tester ((Test1 alloc) init))
        ;; before the swap
        (assert_equal "foo" (tester foo))
        (assert_equal "bar" (tester bar))
        ;; make the exchange
        (Test1 exchangeInstanceMethod:"foo" withMethod:"bar")
        ;; after the swap
        (assert_equal "bar" (tester foo))
        (assert_equal "foo" (tester bar))
        ;; put them back
        (Test1 exchangeInstanceMethod:"bar" withMethod:"foo")
        ;; now we should be back as we started
        (assert_equal "foo" (tester foo))
        (assert_equal "bar" (tester bar)))
     
     (- (id) testClassMethodSwizzling is
        (class Test2 is NSObject
             (+ (id) foo is "foo")
             (+ (id) bar is "bar"))
        ;; before the swap
        (assert_equal "foo" (Test2 foo))
        (assert_equal "bar" (Test2 bar))
        ;; make the exchange
        (Test2 exchangeClassMethod:"foo" withMethod:"bar")
        ;; after the swap
        (assert_equal "bar" (Test2 foo))
        (assert_equal "foo" (Test2 bar))
        ;; put them back
        (Test2 exchangeClassMethod:"bar" withMethod:"foo")
        ;; now we should be back as we started
        (assert_equal "foo" (Test2 foo))
        (assert_equal "bar" (Test2 bar))))
Something went wrong with that request. Please try again.