]> source.dussan.org Git - jackcess.git/commitdiff
add some unit test for property type inference
authorJames Ahlborn <jtahlborn@yahoo.com>
Tue, 9 Sep 2014 01:23:27 +0000 (01:23 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Tue, 9 Sep 2014 01:23:27 +0000 (01:23 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@871 f203690c-595d-4dc9-a70b-905162fa7fd2

TODO.txt
src/main/java/com/healthmarketscience/jackcess/impl/PropertyMapImpl.java
src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java

index 3c955d587e4e432cde8161f3b81eab6a47840313..10c524c5248668c831cc4fc25f757d60b4ebec88 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -27,8 +27,11 @@ Missing pieces:
   - numeric data has embedded precision/scale, something else?  only last 8
     bytes is data?  implicit precision of 18 for "pure" numeric?  implicit
     precision of 15 for double-ish numeric?
+  - ***add unit tests
+  - ***ability to create calculated columns!
 
 - add properties on table/column creation
+  - add unit tests
 
 - calculated fields in queries? (2003+), w/ aliases?
 
index 3c14be2d16bc1f605d5f6b85660b4fe4cd84f91b..0667ac83cce0e923cacc3838d18b7016934983b2 100644 (file)
@@ -176,10 +176,11 @@ public class PropertyMapImpl implements PropertyMap
                                         Object value) {
     if(type == null) {
       
-      // attempt to figure out the type
-      type = DEFAULT_TYPES.get(type);
+      // attempt to get the default type for this property
+      type = DEFAULT_TYPES.get(name);
 
       if(type == null) {
+        // choose the type based on the value
         if(value instanceof String) {
           type = DataType.TEXT;
         } else if(value instanceof Boolean) {
index 182e6370a6fc144d9a33fa34a7ca3bf2908400cf..f689328eec7f821fd97c83a37b2ccc5c9ab59d5c 100644 (file)
@@ -103,6 +103,24 @@ public class PropertiesTest extends TestCase
                                colMap.get("buzz")), props);
   }
 
+  public void testInferTypes() throws Exception
+  {
+    PropertyMaps maps = new PropertyMaps(10, null, null);
+    PropertyMap defMap = maps.getDefault();
+
+    assertEquals(DataType.TEXT, 
+                 defMap.put(PropertyMap.FORMAT_PROP, null).getType());
+    assertEquals(DataType.BOOLEAN, 
+                 defMap.put(PropertyMap.REQUIRED_PROP, null).getType());
+
+    assertEquals(DataType.TEXT, 
+                 defMap.put("strprop", "this is a string").getType());
+    assertEquals(DataType.BOOLEAN, 
+                 defMap.put("boolprop", true).getType());
+    assertEquals(DataType.LONG, 
+                 defMap.put("intprop", 37).getType());
+  }
+
   public void testReadProperties() throws Exception
   {
     byte[] nameMapBytes = null;