Fix comparison operators for strings

The comparison operators $lt, $lte, $gt, and $gte were incorrectly
using lower bound and upper bound values when comparing text.
For strings, we modify the the lower bound limit to be an empty string,
and the upper bound to be the highest unicode value.

COUCHDB-2808
diff --git a/src/mango_selector_text.erl b/src/mango_selector_text.erl
index 9450dfe..b6e1f09 100644
--- a/src/mango_selector_text.erl
+++ b/src/mango_selector_text.erl
@@ -267,13 +267,26 @@
 
 
 range(lt, Arg) ->
-    [<<"[-Infinity TO ">>, value_str(Arg), <<"}">>];
+    Min = get_range(min, Arg),
+    [<<"[", Min/binary, " TO ">>, value_str(Arg), <<"}">>];
 range(lte, Arg) ->
-    [<<"[-Infinity TO ">>, value_str(Arg), <<"]">>];
+    Min = get_range(min, Arg),
+    [<<"[", Min/binary, " TO ">>, value_str(Arg), <<"]">>];
 range(gte, Arg) ->
-    [<<"[">>, value_str(Arg), <<" TO Infinity]">>];
+    Max = get_range(max, Arg),
+    [<<"[">>, value_str(Arg), <<" TO ", Max/binary, "]">>];
 range(gt, Arg) ->
-    [<<"{">>, value_str(Arg), <<" TO Infinity]">>].
+    Max = get_range(max, Arg),
+    [<<"{">>, value_str(Arg), <<" TO ", Max/binary, "]">>].
+
+get_range(min, Arg) when is_number(Arg) ->
+    <<"-Infinity">>;
+get_range(min, _Arg) ->
+    <<"\"\"">>;
+get_range(max, Arg) when is_number(Arg) ->
+    <<"Infinity">>;
+get_range(max, _Arg) ->
+    <<"\u0x10FFFF">>.
 
 
 field_exists_query(Path) ->
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index c60779e..1e3d5df 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -96,6 +96,10 @@
         for d in docs:
             assert d["user_id"] in (1, 7, 9)
 
+        docs = self.db.find({"company": {"$lt": "Dreamia"}})
+        assert len(docs) == 1
+        assert docs[0]["company"] == "Affluex"
+
     def test_lte(self):
         docs = self.db.find({"age": {"$lte": 21}})
         assert len(docs) == 0
@@ -109,6 +113,11 @@
         for d in docs:
             assert d["user_id"] in (1, 7, 9)
 
+        docs = self.db.find({"company": {"$lte": "Dreamia"}})
+        assert len(docs) == 2
+        for d in docs:
+            assert d["user_id"] in (0, 11)
+
     def test_eq(self):
         docs = self.db.find({"age": 21})
         assert len(docs) == 0
@@ -149,6 +158,9 @@
         docs = self.db.find({"age": {"$gt": 79}})
         assert len(docs) == 0
 
+        docs = self.db.find({"company": {"$gt": "Zialactic"}})
+        assert len(docs) == 0
+
     def test_gte(self):
         docs = self.db.find({"age": {"$gte": 77}})
         assert len(docs) == 2
@@ -167,6 +179,10 @@
         docs = self.db.find({"age": {"$gte": 80}})
         assert len(docs) == 0
 
+        docs = self.db.find({"company": {"$gte": "Zialactic"}})
+        assert len(docs) == 1
+        assert docs[0]["company"] == "Zialactic"
+
     def test_and(self):
         docs = self.db.find({"age": 22, "manager": True})
         assert len(docs) == 1