Skip to content

Commit

Permalink
To be rebased: bw compat in doesNotUnderstand
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanHendersonMusic committed May 6, 2024
1 parent 1a9c607 commit 0e0606f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
27 changes: 24 additions & 3 deletions SCClassLibrary/Common/Core/Object.sc
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,32 @@ Object {
subclassResponsibility { arg method;
SubclassResponsibilityError(this, method, this.class).throw;
}
doesNotUnderstand { arg selector ... args;
DoesNotUnderstandError(this, selector, args).throw;
doesNotUnderstand { |selector ...args|
// if the class has a custom 'doesNotUnderstandWithKeys' method, call it.
var thisDoesNotUnderstandWithKeys = this.class.findRespondingMethodFor(\doesNotUnderstandWithKeys);
var objDoesNotUnderstandWithKeys = Object.findMethod(\doesNotUnderstandWithKeys);

if (thisDoesNotUnderstandWithKeys == objDoesNotUnderstandWithKeys){
DoesNotUnderstandError(this, selector, args).throw
} {
^this.doesNotUnderstandWithKeys(selector, args, [])
}
}
doesNotUnderstandWithKeys {|selector, argumentsArray, keywordArgumentPairs|
DoesNotUnderstandError(this, selector, argumentsArray, keywordArgumentPairs).throw;
// if the class has a custom 'doesNotUnderstand' method, post a warning and call it.
var thisDoesNotUnderstand = this.class.findRespondingMethodFor(\doesNotUnderstand);
var objDoesNotUnderstand = Object.findMethod(\doesNotUnderstand);

if (thisDoesNotUnderstand == objDoesNotUnderstand){
DoesNotUnderstandError(this, selector, argumentsArray, keywordArgumentPairs).throw;
} {
"% does not implement doesNotUnderstandWithKeys, "
"calling doesNotUnderstand and throwing away keyword arguments %."
.format(this.class, keywordArgumentPairs)
.warn;

^this.doesNotUnderstand(selector, *argumentsArray)
}
}
shouldNotImplement { arg method;
ShouldNotImplementError(this, method, this.class).throw;
Expand Down
21 changes: 21 additions & 0 deletions testsuite/classlibrary/TestDoesNotUnderstandWithKeys.sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ TestDoesNotUnderstandWithKeysWorking {
}
}


Test_DNUWK_OnlyNonKW {
doesNotUnderstand { |selector ...args| ^args }
}

Test_DNUWK_OnlyKW {
doesNotUnderstandWithKeys { |selector, argumentsArray, keywordArgumentPairs|
^argumentsArray
}
}



TestDoesNotUnderstandWithKeys : UnitTest {
test_object_throws {
this.assertException(
Expand All @@ -25,4 +38,12 @@ TestDoesNotUnderstandWithKeys : UnitTest {
"Keyword args should be passsed to doesNotUnderstandWithKeys as an Array of keypairs."
);
}

test_respects_existing_doesNotUnderstand {
this.assertEquals(Test_DNUWK_OnlyNonKW().asdf('hurray!', asdf: 1), ['hurray!']);
}
test_respects_only_doesNotUnderstandWithKeys {
this.assertEquals(Test_DNUWK_OnlyKW().asdf('hurray!'), ['hurray!']);
}

}

0 comments on commit 0e0606f

Please sign in to comment.