Browse Source

SetTest: add test for the printString message

mkroehnert 12 years ago
parent
commit
cab4860e50
3 changed files with 67 additions and 0 deletions
  1. 23 0
      js/Kernel-Tests.deploy.js
  2. 28 0
      js/Kernel-Tests.js
  3. 16 0
      st/Kernel-Tests.st

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

@@ -1232,6 +1232,29 @@ return self;}
 }),
 smalltalk.SetTest);
 
+smalltalk.addMethod(
+"_testPrintString",
+smalltalk.method({
+selector: "testPrintString",
+fn: function (){
+var self=this;
+var set=nil;
+(set=smalltalk.send((smalltalk.Set || Set), "_new", []));
+smalltalk.send(self, "_assert_equals_", ["a Set ()", smalltalk.send(set, "_printString", [])]);
+(function($rec){smalltalk.send($rec, "_add_", [(1)]);return smalltalk.send($rec, "_add_", [(3)]);})(set);
+smalltalk.send(self, "_assert_equals_", ["a Set (1 3)", smalltalk.send(set, "_printString", [])]);
+smalltalk.send(set, "_add_", ["foo"]);
+smalltalk.send(self, "_assert_equals_", ["a Set (1 3 'foo')", smalltalk.send(set, "_printString", [])]);
+(function($rec){smalltalk.send($rec, "_remove_", [(1)]);return smalltalk.send($rec, "_remove_", [(3)]);})(set);
+smalltalk.send(self, "_assert_equals_", ["a Set ('foo')", smalltalk.send(set, "_printString", [])]);
+smalltalk.send(set, "_add_", [(3)]);
+smalltalk.send(self, "_assert_equals_", ["a Set ('foo' 3)", smalltalk.send(set, "_printString", [])]);
+smalltalk.send(set, "_add_", [(3)]);
+smalltalk.send(self, "_assert_equals_", ["a Set ('foo' 3)", smalltalk.send(set, "_printString", [])]);
+return self;}
+}),
+smalltalk.SetTest);
+
 smalltalk.addMethod(
 "_testSize",
 smalltalk.method({

+ 28 - 0
js/Kernel-Tests.js

@@ -1657,6 +1657,34 @@ referencedClasses: ["Set", "Error"]
 }),
 smalltalk.SetTest);
 
+smalltalk.addMethod(
+"_testPrintString",
+smalltalk.method({
+selector: "testPrintString",
+category: 'tests',
+fn: function (){
+var self=this;
+var set=nil;
+(set=smalltalk.send((smalltalk.Set || Set), "_new", []));
+smalltalk.send(self, "_assert_equals_", ["a Set ()", smalltalk.send(set, "_printString", [])]);
+(function($rec){smalltalk.send($rec, "_add_", [(1)]);return smalltalk.send($rec, "_add_", [(3)]);})(set);
+smalltalk.send(self, "_assert_equals_", ["a Set (1 3)", smalltalk.send(set, "_printString", [])]);
+smalltalk.send(set, "_add_", ["foo"]);
+smalltalk.send(self, "_assert_equals_", ["a Set (1 3 'foo')", smalltalk.send(set, "_printString", [])]);
+(function($rec){smalltalk.send($rec, "_remove_", [(1)]);return smalltalk.send($rec, "_remove_", [(3)]);})(set);
+smalltalk.send(self, "_assert_equals_", ["a Set ('foo')", smalltalk.send(set, "_printString", [])]);
+smalltalk.send(set, "_add_", [(3)]);
+smalltalk.send(self, "_assert_equals_", ["a Set ('foo' 3)", smalltalk.send(set, "_printString", [])]);
+smalltalk.send(set, "_add_", [(3)]);
+smalltalk.send(self, "_assert_equals_", ["a Set ('foo' 3)", smalltalk.send(set, "_printString", [])]);
+return self;},
+args: [],
+source: "testPrintString\x0a\x09| set |\x0a\x09set := Set new.\x0a\x09self assert: 'a Set ()' equals: ( set printString ).\x0a\x09set add: 1; add: 3.\x0a\x09self assert: 'a Set (1 3)' equals: ( set printString ).\x0a\x09set add: 'foo'.\x0a\x09self assert: 'a Set (1 3 ''foo'')' equals: ( set printString ).\x0a\x09set remove: 1; remove: 3.\x0a\x09self assert: 'a Set (''foo'')' equals: ( set printString ).\x0a\x09set add: 3.\x0a\x09self assert: 'a Set (''foo'' 3)' equals: ( set printString ).\x0a\x09set add: 3.\x0a\x09self assert: 'a Set (''foo'' 3)' equals: ( set printString ).",
+messageSends: ["new", "assert:equals:", "printString", "add:", "remove:"],
+referencedClasses: ["Set"]
+}),
+smalltalk.SetTest);
+
 smalltalk.addMethod(
 "_testSize",
 smalltalk.method({

+ 16 - 0
st/Kernel-Tests.st

@@ -811,6 +811,22 @@ testAt
 	self should: [Set new at: 1 put: 2] raise: Error
 !
 
+testPrintString
+	| set |
+	set := Set new.
+	self assert: 'a Set ()' equals: ( set printString ).
+	set add: 1; add: 3.
+	self assert: 'a Set (1 3)' equals: ( set printString ).
+	set add: 'foo'.
+	self assert: 'a Set (1 3 ''foo'')' equals: ( set printString ).
+	set remove: 1; remove: 3.
+	self assert: 'a Set (''foo'')' equals: ( set printString ).
+	set add: 3.
+	self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
+	set add: 3.
+	self assert: 'a Set (''foo'' 3)' equals: ( set printString ).
+!
+
 testSize
 	self assert: Set new size equals: 0.
 	self assert: (Set withAll: #(1 2 3 4)) size equals: 4.