Browse Source

AssociationTest: more Association tests

mkroehnert 12 years ago
parent
commit
e0505e9306
3 changed files with 194 additions and 0 deletions
  1. 66 0
      js/Kernel-Tests.deploy.js
  2. 86 0
      js/Kernel-Tests.js
  3. 42 0
      st/Kernel-Tests.st

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

@@ -66,6 +66,24 @@ smalltalk.ArrayTest);
 
 
 smalltalk.addClass('AssociationTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+"_testClassCreation",
+smalltalk.method({
+selector: "testClassCreation",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var key=nil;
+var value=nil;
+(key="KEY_STRING");
+(value="VALUE_STRING");
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", [key, value]));
+smalltalk.send(self, "_assert_", [smalltalk.send(key, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(value, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
 smalltalk.addMethod(
 "_testEqualAssociations",
 smalltalk.method({
@@ -81,6 +99,23 @@ return self;}
 }),
 smalltalk.AssociationTest);
 
+smalltalk.addMethod(
+"_testKeyAccess",
+smalltalk.method({
+selector: "testKeyAccess",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var key=nil;
+(key="KEY_STRING");
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_new", []));
+smalltalk.send(anAssociation, "_key_", [key]);
+smalltalk.send(self, "_assert_", [smalltalk.send(key, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
 smalltalk.addMethod(
 "_testNotEqualAssociations",
 smalltalk.method({
@@ -111,6 +146,37 @@ return self;}
 }),
 smalltalk.AssociationTest);
 
+smalltalk.addMethod(
+"_testUninitializedObject",
+smalltalk.method({
+selector: "testUninitializedObject",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_new", []));
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
+smalltalk.addMethod(
+"_testValueAccess",
+smalltalk.method({
+selector: "testValueAccess",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var value=nil;
+(value="VALUE_STRING");
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_new", []));
+smalltalk.send(anAssociation, "_value_", [value]);
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(value, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
 
 
 smalltalk.addClass('BlockClosureTest', smalltalk.TestCase, [], 'Kernel-Tests');

+ 86 - 0
js/Kernel-Tests.js

@@ -86,6 +86,29 @@ smalltalk.ArrayTest);
 
 
 smalltalk.addClass('AssociationTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+"_testClassCreation",
+smalltalk.method({
+selector: "testClassCreation",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var key=nil;
+var value=nil;
+(key="KEY_STRING");
+(value="VALUE_STRING");
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", [key, value]));
+smalltalk.send(self, "_assert_", [smalltalk.send(key, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(value, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;},
+args: [],
+source: "testClassCreation\x0a\x09\x22Test if Associatin object created via the class method contains correct values\x22\x0a\x09| anAssociation key value|\x0a\x09key := 'KEY_STRING'.\x0a\x09value := 'VALUE_STRING'.\x0a\x09anAssociation := Association key: key value: value.\x0a\x0a\x09self assert: (key = anAssociation key).\x0a\x09self assert: (value = anAssociation value).",
+messageSends: ["key:value:", "assert:", "=", "key", "value"],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
 smalltalk.addMethod(
 "_testEqualAssociations",
 smalltalk.method({
@@ -106,6 +129,28 @@ referencedClasses: ["Association"]
 }),
 smalltalk.AssociationTest);
 
+smalltalk.addMethod(
+"_testKeyAccess",
+smalltalk.method({
+selector: "testKeyAccess",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var key=nil;
+(key="KEY_STRING");
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_new", []));
+smalltalk.send(anAssociation, "_key_", [key]);
+smalltalk.send(self, "_assert_", [smalltalk.send(key, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;},
+args: [],
+source: "testKeyAccess\x0a\x09\x22Test getter and setter messages for Association keys\x22\x0a\x09| anAssociation key |\x0a\x09key := 'KEY_STRING'.\x0a\x09anAssociation := Association new.\x0a\x09anAssociation key: key.\x0a\x0a\x09self assert: (key = anAssociation key).\x0a\x09self assert: (nil = anAssociation value).",
+messageSends: ["new", "key:", "assert:", "=", "key", "value"],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
 smalltalk.addMethod(
 "_testNotEqualAssociations",
 smalltalk.method({
@@ -146,6 +191,47 @@ referencedClasses: ["Association"]
 }),
 smalltalk.AssociationTest);
 
+smalltalk.addMethod(
+"_testUninitializedObject",
+smalltalk.method({
+selector: "testUninitializedObject",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_new", []));
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;},
+args: [],
+source: "testUninitializedObject\x0a\x09\x22Test if uninitialized Associatin object contains correct values\x22\x0a\x09| anAssociation |\x0a\x09anAssociation := Association new.\x0a\x0a\x09self assert: (nil = anAssociation key).\x0a\x09self assert: (nil = anAssociation value).",
+messageSends: ["new", "assert:", "=", "key", "value"],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
+smalltalk.addMethod(
+"_testValueAccess",
+smalltalk.method({
+selector: "testValueAccess",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var value=nil;
+(value="VALUE_STRING");
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_new", []));
+smalltalk.send(anAssociation, "_value_", [value]);
+smalltalk.send(self, "_assert_", [smalltalk.send(nil, "__eq", [smalltalk.send(anAssociation, "_key", [])])]);
+smalltalk.send(self, "_assert_", [smalltalk.send(value, "__eq", [smalltalk.send(anAssociation, "_value", [])])]);
+return self;},
+args: [],
+source: "testValueAccess\x0a\x09\x22Test getter and setter messages for Association values\x22\x0a\x09| anAssociation value |\x0a\x09value := 'VALUE_STRING'.\x0a\x09anAssociation := Association new.\x0a\x09anAssociation value: value.\x0a\x0a\x09self assert: (nil = anAssociation key).\x0a\x09self assert: (value = anAssociation value).",
+messageSends: ["new", "value:", "assert:", "=", "key", "value"],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
 
 
 smalltalk.addClass('BlockClosureTest', smalltalk.TestCase, [], 'Kernel-Tests');

+ 42 - 0
st/Kernel-Tests.st

@@ -46,6 +46,17 @@ TestCase subclass: #AssociationTest
 
 !AssociationTest methodsFor: 'tests'!
 
+testClassCreation
+	"Test if Associatin object created via the class method contains correct values"
+	| anAssociation key value|
+	key := 'KEY_STRING'.
+	value := 'VALUE_STRING'.
+	anAssociation := Association key: key value: value.
+
+	self assert: (key = anAssociation key).
+	self assert: (value = anAssociation value).
+!
+
 testEqualAssociations
 	"Test if two equal Association objects compare to true"
 	| anAssociation anotherAssociation |
@@ -55,6 +66,17 @@ testEqualAssociations
 	self assert: (anAssociation = anotherAssociation).
 !
 
+testKeyAccess
+	"Test getter and setter messages for Association keys"
+	| anAssociation key |
+	key := 'KEY_STRING'.
+	anAssociation := Association new.
+	anAssociation key: key.
+
+	self assert: (key = anAssociation key).
+	self assert: (nil = anAssociation value).
+!
+
 testNotEqualAssociations
 	"Test if two unequal Association objects compare to false"
 	| anAssociation anotherAssociation |
@@ -71,6 +93,26 @@ testPrintString
 	returnString := anAssociation printString.
 
 	self assert: ('''KEY''->''VALUE''' = returnString).
+!
+
+testUninitializedObject
+	"Test if uninitialized Associatin object contains correct values"
+	| anAssociation |
+	anAssociation := Association new.
+
+	self assert: (nil = anAssociation key).
+	self assert: (nil = anAssociation value).
+!
+
+testValueAccess
+	"Test getter and setter messages for Association values"
+	| anAssociation value |
+	value := 'VALUE_STRING'.
+	anAssociation := Association new.
+	anAssociation value: value.
+
+	self assert: (nil = anAssociation key).
+	self assert: (value = anAssociation value).
 ! !
 
 TestCase subclass: #BlockClosureTest