Ver código fonte

Fixed Number>>copy and Number>>deepCopy + unit tests

Nicolas Petton 13 anos atrás
pai
commit
f698fc2575
6 arquivos alterados com 102 adições e 6 exclusões
  1. 12 0
      js/Kernel-Tests.deploy.js
  2. 18 1
      js/Kernel-Tests.js
  3. 22 0
      js/Kernel.deploy.js
  4. 32 0
      js/Kernel.js
  5. 8 5
      st/Kernel-Tests.st
  6. 10 0
      st/Kernel.st

+ 12 - 0
js/Kernel-Tests.deploy.js

@@ -294,6 +294,18 @@ return self;}
 }),
 smalltalk.NumberTest);
 
+smalltalk.addMethod(
+'_testCopying',
+smalltalk.method({
+selector: 'testCopying',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send((1), "_copy", []), "__eq", [(1)])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send((1), "_deepCopy", []), "__eq", [(1)])]);
+return self;}
+}),
+smalltalk.NumberTest);
+
 
 
 smalltalk.addClass('JSObjectProxyTest', smalltalk.TestCase, [], 'Kernel-Tests');

+ 18 - 1
js/Kernel-Tests.js

@@ -242,7 +242,7 @@ smalltalk.addMethod(
 unescape('_testPrintShowingDecimalPlaces'),
 smalltalk.method({
 selector: unescape('testPrintShowingDecimalPlaces'),
-category: 'not yet classified',
+category: 'tests',
 fn: function (){
 var self=this;
 smalltalk.send(self, "_assert_equals_", ["23.00", smalltalk.send((23), "_printShowingDecimalPlaces_", [(2)])]);
@@ -389,6 +389,23 @@ referencedClasses: []
 }),
 smalltalk.NumberTest);
 
+smalltalk.addMethod(
+unescape('_testCopying'),
+smalltalk.method({
+selector: unescape('testCopying'),
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send((1), "_copy", []), "__eq", [(1)])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send((1), "_deepCopy", []), "__eq", [(1)])]);
+return self;},
+args: [],
+source: unescape('testCopying%0A%09self%20assert%3A%201%20copy%20%3D%201.%0A%09self%20assert%3A%201%20deepCopy%20%3D%201'),
+messageSends: ["assert:", unescape("%3D"), "copy", "deepCopy"],
+referencedClasses: []
+}),
+smalltalk.NumberTest);
+
 
 
 smalltalk.addClass('JSObjectProxyTest', smalltalk.TestCase, [], 'Kernel-Tests');

+ 22 - 0
js/Kernel.deploy.js

@@ -1867,6 +1867,28 @@ return self;}
 }),
 smalltalk.Number);
 
+smalltalk.addMethod(
+'_deepCopy',
+smalltalk.method({
+selector: 'deepCopy',
+fn: function (){
+var self=this;
+return smalltalk.send(self, "_copy", []);
+return self;}
+}),
+smalltalk.Number);
+
+smalltalk.addMethod(
+'_copy',
+smalltalk.method({
+selector: 'copy',
+fn: function (){
+var self=this;
+return self;
+return self;}
+}),
+smalltalk.Number);
+
 
 smalltalk.addMethod(
 '_pi',

+ 32 - 0
js/Kernel.js

@@ -2658,6 +2658,38 @@ referencedClasses: []
 }),
 smalltalk.Number);
 
+smalltalk.addMethod(
+unescape('_deepCopy'),
+smalltalk.method({
+selector: unescape('deepCopy'),
+category: 'copying',
+fn: function (){
+var self=this;
+return smalltalk.send(self, "_copy", []);
+return self;},
+args: [],
+source: unescape('deepCopy%0A%09%5Eself%20copy'),
+messageSends: ["copy"],
+referencedClasses: []
+}),
+smalltalk.Number);
+
+smalltalk.addMethod(
+unescape('_copy'),
+smalltalk.method({
+selector: unescape('copy'),
+category: 'copying',
+fn: function (){
+var self=this;
+return self;
+return self;},
+args: [],
+source: unescape('copy%0A%09%5Eself'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Number);
+
 
 smalltalk.addMethod(
 unescape('_pi'),

+ 8 - 5
st/Kernel-Tests.st

@@ -154,7 +154,7 @@ TestCase subclass: #NumberTest
 	instanceVariableNames: ''
 	category: 'Kernel-Tests'!
 
-!NumberTest methodsFor: 'not yet classified'!
+!NumberTest methodsFor: 'tests'!
 
 testPrintShowingDecimalPlaces
 	self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
@@ -170,9 +170,7 @@ testPrintShowingDecimalPlaces
 	self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
 	self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
 	self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
-! !
-
-!NumberTest methodsFor: 'tests'!
+!
 
 testEquality
 	self assert: 1 = 1.
@@ -237,6 +235,11 @@ testTruncated
 	self assert: 3 truncated = 3.
 	self assert: 3.212 truncated = 3.
 	self assert: 3.51 truncated = 3
+!
+
+testCopying
+	self assert: 1 copy = 1.
+	self assert: 1 deepCopy = 1
 ! !
 
 TestCase subclass: #JSObjectProxyTest
@@ -273,5 +276,5 @@ testPropertyThatReturnsEmptyString
 
 	document location hash: 'test'.
 	self assert: '#test' equals: document location hash.
+! !
 
-! !

+ 10 - 0
st/Kernel.st

@@ -880,6 +880,16 @@ to: stop by: step do: aBlock
 	    			value := value + step]]
 ! !
 
+!Number methodsFor: 'copying'!
+
+deepCopy
+	^self copy
+!
+
+copy
+	^self
+! !
+
 !Number methodsFor: 'enumerating'!
 
 timesRepeat: aBlock