Permalink
Browse files

Add Retrieve functionality while we're at it

  • Loading branch information...
rtyler committed Nov 11, 2012
1 parent 038790b commit 8dc74b12491660be9003b6dbc95b96444a128d4e
Showing with 43 additions and 15 deletions.
  1. +10 −7 src/sting-store.adb
  2. +13 −8 src/sting-store.ads
  3. +20 −0 test/cases/sting-tests-store.adb
View
@@ -6,17 +6,20 @@ package body Sting.Store is
(Natural (E.Backend.Length));
- procedure Insert (E : in out Engine;
- Key : in SString;
- Value : in SString) is
+ procedure Insert (E : in out Engine;
+ Key : in SString;
+ Value : in SString) is
begin
E.Backend.Insert (Key, Value);
end Insert;
- function Hersh (Key : SString) return Ada.Containers.Hash_Type is
- begin
- return Ada.Strings.Hash (Key.all);
- end Hersh;
+ function Retrieve (E : in Engine;
+ Key : in SString) return SString is
+ (E.Backend.Element (Key));
+
+
+ function Hash (Key : SString) return Ada.Containers.Hash_Type is
+ (Ada.Strings.Hash (Key.all));
end Sting.Store;
View
@@ -5,18 +5,23 @@ package Sting.Store is
type SString is access String;
function Count (E : in Engine) return Natural;
- procedure Insert (E : in out Engine;
- Key : in SString;
- Value : in SString);
- function Hersh (Key : SString) return Ada.Containers.Hash_Type;
+ function Hash (Key : SString) return Ada.Containers.Hash_Type;
+
+ procedure Insert (E : in out Engine;
+ Key : in SString;
+ Value : in SString);
+
+ function Retrieve (E : in Engine;
+ Key : in SString) return SString;
+
+private
package StingContainer is new Ada.Containers.Hashed_Maps
- (Key_Type => SString,
- Element_Type => SString,
- Hash => Hersh,
+ (Key_Type => SString,
+ Element_Type => SString,
+ Hash => Hash,
Equivalent_Keys => "=");
-private
type Engine is tagged record
Backend : StingContainer.Map;
@@ -25,12 +25,32 @@ package body Sting.Tests.Store is
end Test_Insert_Simple_Key_Value;
+ procedure Test_Read_Simple_Key_Value (T : in out Test_Case'Class) is
+ use Sting.Store;
+ pragma Unreferenced (T);
+ S : Sting.Store.Engine;
+
+ Key : constant SString := new String'("a-key");
+ Value : constant SString := new String'("lol value");
+ begin
+ -- Insert our stupid value first
+ S.Insert (Key, Value);
+ --
+
+ Assert ((S.Retrieve (Key) = Value), "Retrieved value doesn't look like: " & Value.all);
+
+ Assert ((S.Count > 0), "Not enough items stored");
+ end Test_Read_Simple_Key_Value;
+
+
procedure Register_Tests (T : in out Test) is
use AUnit.Test_Cases.Registration;
begin
Register_Routine (T, Test_Count_Empty'Access, "Check the count on an empty Sting Store");
Register_Routine (T, Test_Insert_Simple_Key_Value'Access,
"Perform a simple insertion into the storage engine");
+ Register_Routine (T, Test_Read_Simple_Key_Value'Access,
+ "Retrieve a simple value from the storage engine");
end Register_Tests;

0 comments on commit 8dc74b1

Please sign in to comment.