From c82410bfda4111e01e8d31e5139df938814729d8 Mon Sep 17 00:00:00 2001
From: ridiculousfish <corydoras@ridiculousfish.com>
Date: Sun, 5 Feb 2012 22:48:43 -0800
Subject: [PATCH] Fixed history tests

---
 fish_tests.cpp | 26 ++++++++++++++++----------
 history.cpp    |  8 +++++---
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/fish_tests.cpp b/fish_tests.cpp
index 848dff10a..66b6a6432 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -635,13 +635,18 @@ static void test_parser()
 	}	
 }
 
-class test_lru_t : public lru_cache_t<lru_node_t> {
+class lru_node_test_t : public lru_node_t {
     public:
-    test_lru_t() : lru_cache_t<lru_node_t>(16) { }
+    lru_node_test_t(const wcstring &tmp) : lru_node_t(tmp) { }
+};
+
+class test_lru_t : public lru_cache_t<lru_node_test_t> {
+    public:
+    test_lru_t() : lru_cache_t<lru_node_test_t>(16) { }
     
-    std::vector<lru_node_t *> evicted_nodes;
+    std::vector<lru_node_test_t *> evicted_nodes;
     
-    virtual void node_was_evicted(lru_node_t *node) {
+    virtual void node_was_evicted(lru_node_test_t *node) {
         assert(find(evicted_nodes.begin(), evicted_nodes.end(), node) == evicted_nodes.end());
         evicted_nodes.push_back(node);
     }
@@ -651,11 +656,11 @@ static void test_lru(void) {
     say( L"Testing LRU cache" );
     
     test_lru_t cache;
-    std::vector<lru_node_t *> expected_evicted;
+    std::vector<lru_node_test_t *> expected_evicted;
     size_t total_nodes = 20;
     for (size_t i=0; i < total_nodes; i++) {
         assert(cache.size() == std::min(i, (size_t)16));
-        lru_node_t *node = new lru_node_t(format_val(i));
+        lru_node_test_t *node = new lru_node_test_t(format_val(i));
         if (i < 4) expected_evicted.push_back(node);
         // Adding the node the first time should work, and subsequent times should fail
         assert(cache.add_node(node));
@@ -846,19 +851,20 @@ static void test_history(void) {
     say( L"Testing history");
     
     history_t &history = history_t::history_with_name(L"test_history");
-    history.add(L"Alpha");
-    history.add(L"Beta");
     history.add(L"Gamma");
+    history.add(L"Beta");
+    history.add(L"Alpha");
+    
 
     /* All three items match "a" */
     history_search_t search1(history, L"a");
     test_history_matches(search1, 3);
-    assert(search1.current_item().str() == L"Alpha");
+    assert(search1.current_item() == L"Alpha");
     
     /* One item matches "et" */
     history_search_t search2(history, L"et");
     test_history_matches(search2, 1);
-    assert(search2.current_item().str() == L"Beta");
+    assert(search2.current_item() == L"Beta");
 }
 
 
diff --git a/history.cpp b/history.cpp
index 33659996d..e59f24868 100644
--- a/history.cpp
+++ b/history.cpp
@@ -345,10 +345,12 @@ void history_t::load_old_if_needed(void)
 }
 
 bool history_search_t::go_forwards() {
-    /* Pop the top index (if any) and return if we have any left */
-    if (! prev_matches.empty())
+    /* Pop the top index (if more than one) and return if we have any left */
+    if (prev_matches.size() > 1) {
         prev_matches.pop_back();
-    return ! prev_matches.empty();
+        return true;
+    }
+    return false;
 }
 
 bool history_search_t::go_backwards() {