Sfoglia il codice sorgente

HashedCollectionTest: add test for >>printString

mkroehnert 12 anni fa
parent
commit
4ea7c4ce97
3 ha cambiato i file con 64 aggiunte e 0 eliminazioni
  1. 20 0
      js/Kernel-Tests.deploy.js
  2. 25 0
      js/Kernel-Tests.js
  3. 19 0
      st/Kernel-Tests.st

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

@@ -644,6 +644,26 @@ smalltalk.DictionaryTest);
 
 
 
+smalltalk.addClass('HashedCollectionTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+"_testPrintString",
+smalltalk.method({
+selector: "testPrintString",
+fn: function (){
+var self=this;
+var aHashedCollection=nil;
+(aHashedCollection=smalltalk.send((smalltalk.HashedCollection || HashedCollection), "_new", []));
+smalltalk.send(self, "_assert_equals_", ["a HashedCollection()", smalltalk.send(aHashedCollection, "_printString", [])]);
+smalltalk.send(aHashedCollection, "_at_put_", ["key1", (1)]);
+smalltalk.send(self, "_assert_equals_", ["a HashedCollection('key1'->1)", smalltalk.send(aHashedCollection, "_printString", [])]);
+smalltalk.send(aHashedCollection, "_at_put_", ["key2", (2)]);
+smalltalk.send(self, "_assert_equals_", ["a HashedCollection('key1'->1 , 'key2'->2)", smalltalk.send(aHashedCollection, "_printString", [])]);
+return self;}
+}),
+smalltalk.HashedCollectionTest);
+
+
+
 smalltalk.addClass('JSObjectProxyTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 "_jsObject",

+ 25 - 0
js/Kernel-Tests.js

@@ -844,6 +844,31 @@ smalltalk.DictionaryTest);
 
 
 
+smalltalk.addClass('HashedCollectionTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+"_testPrintString",
+smalltalk.method({
+selector: "testPrintString",
+category: 'tests',
+fn: function (){
+var self=this;
+var aHashedCollection=nil;
+(aHashedCollection=smalltalk.send((smalltalk.HashedCollection || HashedCollection), "_new", []));
+smalltalk.send(self, "_assert_equals_", ["a HashedCollection()", smalltalk.send(aHashedCollection, "_printString", [])]);
+smalltalk.send(aHashedCollection, "_at_put_", ["key1", (1)]);
+smalltalk.send(self, "_assert_equals_", ["a HashedCollection('key1'->1)", smalltalk.send(aHashedCollection, "_printString", [])]);
+smalltalk.send(aHashedCollection, "_at_put_", ["key2", (2)]);
+smalltalk.send(self, "_assert_equals_", ["a HashedCollection('key1'->1 , 'key2'->2)", smalltalk.send(aHashedCollection, "_printString", [])]);
+return self;},
+args: [],
+source: "testPrintString\x0a\x09\x22test if the printString message returns the correct string representation\x22\x0a\x09| aHashedCollection |\x0a\x09aHashedCollection := HashedCollection new.\x0a\x09self assert: 'a HashedCollection()' equals: aHashedCollection printString.\x0a\x0a\x09aHashedCollection at: 'key1' put: 1.\x0a\x09self assert: 'a HashedCollection(''key1''->1)' equals: aHashedCollection printString.\x0a\x0a\x09aHashedCollection at: 'key2' put: 2.\x0a\x09self assert: 'a HashedCollection(''key1''->1 , ''key2''->2)' equals: aHashedCollection printString.",
+messageSends: ["new", "assert:equals:", "printString", "at:put:"],
+referencedClasses: ["HashedCollection"]
+}),
+smalltalk.HashedCollectionTest);
+
+
+
 smalltalk.addClass('JSObjectProxyTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 "_jsObject",

+ 19 - 0
st/Kernel-Tests.st

@@ -461,6 +461,25 @@ testValues
 	self assert: d values = #(2 3 4)
 ! !
 
+TestCase subclass: #HashedCollectionTest
+	instanceVariableNames: ''
+	package: 'Kernel-Tests'!
+
+!HashedCollectionTest methodsFor: 'tests'!
+
+testPrintString
+	"test if the printString message returns the correct string representation"
+	| aHashedCollection |
+	aHashedCollection := HashedCollection new.
+	self assert: 'a HashedCollection()' equals: aHashedCollection printString.
+
+	aHashedCollection at: 'key1' put: 1.
+	self assert: 'a HashedCollection(''key1''->1)' equals: aHashedCollection printString.
+
+	aHashedCollection at: 'key2' put: 2.
+	self assert: 'a HashedCollection(''key1''->1 , ''key2''->2)' equals: aHashedCollection printString.
+! !
+
 TestCase subclass: #JSObjectProxyTest
 	instanceVariableNames: ''
 	package: 'Kernel-Tests'!