aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/io/match_test.cc
diff options
context:
space:
mode:
authorGravatar Manjunath Kudlur <keveman@gmail.com>2015-11-06 16:27:58 -0800
committerGravatar Manjunath Kudlur <keveman@gmail.com>2015-11-06 16:27:58 -0800
commitf41959ccb2d9d4c722fe8fc3351401d53bcf4900 (patch)
treeef0ca22cb2a5ac4bdec9d080d8e0788a53ed496d /tensorflow/core/lib/io/match_test.cc
TensorFlow: Initial commit of TensorFlow library.
TensorFlow is an open source software library for numerical computation using data flow graphs. Base CL: 107276108
Diffstat (limited to 'tensorflow/core/lib/io/match_test.cc')
-rw-r--r--tensorflow/core/lib/io/match_test.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/tensorflow/core/lib/io/match_test.cc b/tensorflow/core/lib/io/match_test.cc
new file mode 100644
index 0000000000..aaa56e4e7e
--- /dev/null
+++ b/tensorflow/core/lib/io/match_test.cc
@@ -0,0 +1,51 @@
+#include <algorithm>
+#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/io/match.h"
+#include "tensorflow/core/lib/io/path.h"
+#include "tensorflow/core/lib/strings/strcat.h"
+#include "tensorflow/core/platform/test.h"
+#include "tensorflow/core/public/env.h"
+#include <gtest/gtest.h>
+
+namespace tensorflow {
+namespace io {
+
+static string Match(Env* env, const string& suffix_pattern) {
+ std::vector<string> results;
+ Status s = GetMatchingFiles(env, JoinPath(testing::TmpDir(), suffix_pattern),
+ &results);
+ if (!s.ok()) {
+ return s.ToString();
+ } else {
+ string r;
+ std::sort(results.begin(), results.end());
+ for (size_t i = 0; i < results.size(); i++) {
+ strings::StrAppend(&r, (i > 0) ? "," : "", Basename(results[i]));
+ }
+ return r;
+ }
+}
+TEST(GetMatchingFiles, Simple) {
+ Env* env = Env::Default();
+ EXPECT_EQ(Match(env, "thereisnosuchfile"), "");
+ EXPECT_EQ(Match(env, "thereisnosuchfile*"), "");
+
+ // Populate a few files
+ EXPECT_OK(WriteStringToFile(Env::Default(),
+ JoinPath(testing::TmpDir(), "match-00"), ""));
+ EXPECT_OK(WriteStringToFile(Env::Default(),
+ JoinPath(testing::TmpDir(), "match-0a"), ""));
+ EXPECT_OK(WriteStringToFile(Env::Default(),
+ JoinPath(testing::TmpDir(), "match-01"), ""));
+ EXPECT_OK(WriteStringToFile(Env::Default(),
+ JoinPath(testing::TmpDir(), "match-aaa"), ""));
+
+ EXPECT_EQ(Match(env, "match-*"), "match-00,match-01,match-0a,match-aaa");
+ EXPECT_EQ(Match(env, "match-0[0-9]"), "match-00,match-01");
+ EXPECT_EQ(Match(env, "match-?[0-9]"), "match-00,match-01");
+ EXPECT_EQ(Match(env, "match-?a*"), "match-0a,match-aaa");
+ EXPECT_EQ(Match(env, "match-??"), "match-00,match-01,match-0a");
+}
+
+} // namespace io
+} // namespace tensorflow