aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_tests.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-16 00:24:27 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-16 00:24:27 -0800
commita08450bcb6050cc630d87ae6d7d5f203f8eeca62 (patch)
tree1e49e402f2c5e50aadc8e4d2367f1d1abad0626d /fish_tests.cpp
parenta92d9d442b5b4f8b3de0c2eef3a9d7a498a36aa8 (diff)
Changes to make autosuggestion smarter about not suggesting commands that could never succeed.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r--fish_tests.cpp68
1 files changed, 60 insertions, 8 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp
index f206cd83..278b99c1 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -54,7 +54,8 @@
/**
The number of tests to run
*/
-#define ESCAPE_TEST_COUNT 1000000
+//#define ESCAPE_TEST_COUNT 1000000
+#define ESCAPE_TEST_COUNT 10000
/**
The average length of strings to unescape
*/
@@ -764,6 +765,7 @@ static void test_history_matches(history_search_t &search, size_t matches) {
size_t i;
for (i=0; i < matches; i++) {
assert(search.go_backwards());
+ wcstring item = search.current_string();
}
assert(! search.go_backwards());
@@ -773,29 +775,79 @@ static void test_history_matches(history_search_t &search, size_t matches) {
assert(! search.go_forwards());
}
-static void test_history(void) {
+class history_tests_t {
+public:
+ static void test_history(void);
+};
+
+static wcstring random_string(void) {
+ wcstring result;
+ size_t max = 1 + rand() % 32;
+ while (max--) {
+ wchar_t c = 1 + rand()%ESCAPE_TEST_CHAR;
+ result.push_back(c);
+ }
+ return result;
+}
+
+void history_tests_t::test_history(void) {
say( L"Testing history");
history_t &history = history_t::history_with_name(L"test_history");
+ history.clear();
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() == L"Alpha");
+ assert(search1.current_string() == L"Alpha");
/* One item matches "et" */
history_search_t search2(history, L"et");
test_history_matches(search2, 1);
- assert(search2.current_item() == L"Beta");
+ assert(search2.current_string() == L"Beta");
+
+ /* Test history escaping and unescaping, yaml, etc. */
+ std::vector<history_item_t> before, after;
+ history.clear();
+ size_t i, max = 100;
+ for (i=1; i <= max; i++) {
+
+ /* Generate a value */
+ wcstring value = wcstring(L"test item ") + format_val(i);
+
+ /* Generate some paths */
+ path_list_t paths;
+ size_t count = rand() % 6;
+ while (count--) {
+ paths.push_front(random_string());
+ }
+
+ /* Record this item */
+ history_item_t item(value, time(NULL), paths);
+ before.push_back(item);
+ history.add(item);
+ }
+ history.save();
+
+ /* Read items back in reverse order and ensure they're the same */
+ for (i=100; i >= 1; i--) {
+ history_item_t item = history.item_at_index(i);
+ assert(! item.empty());
+ after.push_back(item);
+ }
+ assert(before.size() == after.size());
+ for (size_t i=0; i < before.size(); i++) {
+ const history_item_t &bef = before.at(i), &aft = after.at(i);
+ assert(bef.contents == aft.contents);
+ assert(bef.creation_timestamp == aft.creation_timestamp);
+ assert(bef.required_paths == aft.required_paths);
+ }
}
-
-
/**
Main test
*/
@@ -825,7 +877,7 @@ int main( int argc, char **argv )
test_expand();
test_path();
test_colors();
- test_history();
+ history_tests_t::test_history();
say( L"Encountered %d errors in low-level tests", err_count );