From 23f99de11430cfd83ff90fd94c95858148f9b168 Mon Sep 17 00:00:00 2001 From: Joubert Nel Date: Sat, 8 Jan 2011 22:12:26 -0500 Subject: [PATCH] Keyword equality, dictionary tests. --- Cacao.xcodeproj/joubert.perspectivev3 | 55 ++++++++++++++------------- Cacao.xcodeproj/project.pbxproj | 6 +++ CacaoKeyword.m | 6 ++- TestDictionaries.h | 38 ++++++++++++++++++ TestDictionaries.m | 46 ++++++++++++++++++++++ 5 files changed, 123 insertions(+), 28 deletions(-) create mode 100644 TestDictionaries.h create mode 100644 TestDictionaries.m diff --git a/Cacao.xcodeproj/joubert.perspectivev3 b/Cacao.xcodeproj/joubert.perspectivev3 index cb932db..e3e3923 100644 --- a/Cacao.xcodeproj/joubert.perspectivev3 +++ b/Cacao.xcodeproj/joubert.perspectivev3 @@ -285,9 +285,8 @@ PBXSmartGroupTreeModuleOutlineStateSelectionKey - 35 - 17 11 + 1 0 @@ -327,7 +326,7 @@ PBXProjectModuleGUID BE2652C3128DBF470088DC0A PBXProjectModuleLabel - CacaoCore.m + TestDictionaries.m PBXSplitModuleInNavigatorKey Split0 @@ -335,11 +334,11 @@ PBXProjectModuleGUID BE2652C4128DBF470088DC0A PBXProjectModuleLabel - CacaoCore.m + TestDictionaries.m _historyCapacity 0 bookmark - BE2B6D4A12D8FF17000363DB + BE2B6EC212D95F03000363DB history BE2E8750129259F20048AE63 @@ -390,47 +389,49 @@ BEF4555C12D54019007E42FB BEF4573712D57C30007E42FB BEF4577612D58045007E42FB - BEF457BD12D5826B007E42FB BE2B698412D7DC14000363DB BE2B698512D7DC14000363DB BE2B698B12D7DC14000363DB BE2B698C12D7DC14000363DB BE2B6A5D12D7EE78000363DB - BE2B6AA812D7EFFC000363DB - BE2B6BCC12D7FD6E000363DB - BE2B6BCD12D7FD6E000363DB BE2B6BCE12D7FD6E000363DB BE2B6BCF12D7FD6E000363DB - BE2B6BD212D7FD6E000363DB BE2B6BEF12D82BFC000363DB BE2B6BFF12D82C55000363DB - BE2B6C0012D82C55000363DB - BE2B6C1312D82D10000363DB - BE2B6C1412D82D10000363DB - BE2B6C1512D82D10000363DB - BE2B6C2112D82DC8000363DB BE2B6C3712D8DB00000363DB BE2B6C3812D8DB00000363DB BE2B6C3912D8DB00000363DB BE2B6C3A12D8DB00000363DB BE2B6C3B12D8DB00000363DB - BE2B6C3C12D8DB00000363DB - BE2B6C8312D8F1D8000363DB - BE2B6C8912D8F1D8000363DB - BE2B6C8A12D8F1D8000363DB BE2B6CA912D8F5AF000363DB BE2B6CAA12D8F5AF000363DB BE2B6D0F12D8FC02000363DB - BE2B6D3212D8FE6B000363DB BE2B6D4112D8FF17000363DB - BE2B6D4212D8FF17000363DB - BE2B6D4312D8FF17000363DB - BE2B6D4412D8FF17000363DB - BE2B6D4512D8FF17000363DB - BE2B6D4612D8FF17000363DB - BE2B6D4712D8FF17000363DB BE2B6D4812D8FF17000363DB - BE2B6D4912D8FF17000363DB + BE2B6D4F12D910E6000363DB + BE2B6D5012D910E6000363DB + BE2B6D5112D910E6000363DB + BE2B6D5212D910E6000363DB + BE2B6D5312D910E6000363DB + BE2B6D5412D910E6000363DB + BE2B6D5512D910E6000363DB + BE2B6D5612D910E6000363DB + BE2B6DB612D94E37000363DB + BE2B6DDD12D95616000363DB + BE2B6E3612D95824000363DB + BE2B6E3712D95824000363DB + BE2B6E4812D95964000363DB + BE2B6E4912D95964000363DB + BE2B6E4A12D95964000363DB + BE2B6E4B12D95964000363DB + BE2B6E5512D959BE000363DB + BE2B6E8A12D95D9E000363DB + BE2B6EAD12D95ED8000363DB + BE2B6EAE12D95ED8000363DB + BE2B6EAF12D95ED8000363DB + BE2B6EBF12D95F03000363DB + BE2B6EC012D95F03000363DB + BE2B6EC112D95F03000363DB SplitCount diff --git a/Cacao.xcodeproj/project.pbxproj b/Cacao.xcodeproj/project.pbxproj index 61a2d9a..4eb447a 100644 --- a/Cacao.xcodeproj/project.pbxproj +++ b/Cacao.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ BE2B6D2312D8FDFF000363DB /* CacaoComparisonFunctionMakers.m in Sources */ = {isa = PBXBuildFile; fileRef = BE2B6D2212D8FDFF000363DB /* CacaoComparisonFunctionMakers.m */; }; BE2B6D2412D8FDFF000363DB /* CacaoComparisonFunctionMakers.h in Headers */ = {isa = PBXBuildFile; fileRef = BE2B6D2112D8FDFF000363DB /* CacaoComparisonFunctionMakers.h */; }; BE2B6D2512D8FDFF000363DB /* CacaoComparisonFunctionMakers.m in Sources */ = {isa = PBXBuildFile; fileRef = BE2B6D2212D8FDFF000363DB /* CacaoComparisonFunctionMakers.m */; }; + BE2B6DCD12D9556D000363DB /* TestDictionaries.m in Sources */ = {isa = PBXBuildFile; fileRef = BE2B6DCC12D9556D000363DB /* TestDictionaries.m */; }; BE3BC2EA1290A34E00ED6ADB /* NSString+CacaoPrintable.h in Headers */ = {isa = PBXBuildFile; fileRef = BE3BC2E81290A34E00ED6ADB /* NSString+CacaoPrintable.h */; }; BE3BC2EB1290A34E00ED6ADB /* NSString+CacaoPrintable.m in Sources */ = {isa = PBXBuildFile; fileRef = BE3BC2E91290A34E00ED6ADB /* NSString+CacaoPrintable.m */; }; BE3BC2EC1290A34E00ED6ADB /* NSString+CacaoPrintable.m in Sources */ = {isa = PBXBuildFile; fileRef = BE3BC2E91290A34E00ED6ADB /* NSString+CacaoPrintable.m */; }; @@ -149,6 +150,8 @@ BE2B6D1712D8FD66000363DB /* CacaoSequenceFunctionMakers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CacaoSequenceFunctionMakers.m; sourceTree = ""; }; BE2B6D2112D8FDFF000363DB /* CacaoComparisonFunctionMakers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacaoComparisonFunctionMakers.h; sourceTree = ""; }; BE2B6D2212D8FDFF000363DB /* CacaoComparisonFunctionMakers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CacaoComparisonFunctionMakers.m; sourceTree = ""; }; + BE2B6DCB12D9556D000363DB /* TestDictionaries.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestDictionaries.h; sourceTree = ""; }; + BE2B6DCC12D9556D000363DB /* TestDictionaries.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestDictionaries.m; sourceTree = ""; }; BE3BC2E81290A34E00ED6ADB /* NSString+CacaoPrintable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+CacaoPrintable.h"; sourceTree = ""; }; BE3BC2E91290A34E00ED6ADB /* NSString+CacaoPrintable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+CacaoPrintable.m"; sourceTree = ""; }; BE3BC3021290A3D600ED6ADB /* NSNumber+CacaoPrintable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNumber+CacaoPrintable.h"; sourceTree = ""; }; @@ -468,6 +471,8 @@ BE0F24D712A72436005E9444 /* TestCore.m */, BE0F24DA12A72475005E9444 /* TestBase.h */, BE0F24DB12A72475005E9444 /* TestBase.m */, + BE2B6DCB12D9556D000363DB /* TestDictionaries.h */, + BE2B6DCC12D9556D000363DB /* TestDictionaries.m */, ); name = Tests; sourceTree = ""; @@ -691,6 +696,7 @@ BE0F240B12A6A8CD005E9444 /* TestPlatformIntegration.m in Sources */, BE0F24D812A72436005E9444 /* TestCore.m in Sources */, BE0F24DC12A72475005E9444 /* TestBase.m in Sources */, + BE2B6DCD12D9556D000363DB /* TestDictionaries.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/CacaoKeyword.m b/CacaoKeyword.m index bb9fba9..4f4f37a 100644 --- a/CacaoKeyword.m +++ b/CacaoKeyword.m @@ -57,7 +57,11 @@ + (CacaoKeyword *)keywordInternedFromSymbol:(CacaoSymbol *)sym CacaoKeyword * existingKeywordInTable = nil; existingKeywordInTable = [table objectForKey:sym]; if (existingKeywordInTable == nil) - return [CacaoKeyword keywordFromSymbol:sym]; + { + CacaoKeyword * newKeyword = [CacaoKeyword keywordFromSymbol:sym]; + [table setObject:newKeyword forKey:newKeyword.symbol]; + return newKeyword; + } else return existingKeywordInTable; } diff --git a/TestDictionaries.h b/TestDictionaries.h new file mode 100644 index 0000000..cf4b62e --- /dev/null +++ b/TestDictionaries.h @@ -0,0 +1,38 @@ +// +// TestDictionaries.h +// Cacao +// +// Copyright 2011, Joubert Nel. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY JOUBERT NEL "AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOUBERT NEL OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Joubert Nel. + +#import +#import "TestBase.h" + +@interface TestDictionaries : TestBase { + +} + +@end diff --git a/TestDictionaries.m b/TestDictionaries.m new file mode 100644 index 0000000..a6a658a --- /dev/null +++ b/TestDictionaries.m @@ -0,0 +1,46 @@ +// +// TestDictionaries.m +// Cacao +// +// Copyright 2011, Joubert Nel. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY JOUBERT NEL "AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOUBERT NEL OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Joubert Nel. + +#import "TestDictionaries.h" + + +@implementation TestDictionaries + +- (void)testKeyAsFunction +{ + TEST_TRUE(@"(= \"Frederic\" (:first {:first \"Frederic\" :last \"Chopin\"}))"); +} + +- (void)testAllKeys +{ + TEST_TRUE(@"(= [:first :last] (allKeys dict:{:first \"Frederic\" :last \"Chopin\"}))"); +} + +@end