Files
textmate/Frameworks/settings/tests/t_track_paths.cc
Allan Odgaard c2397484b8 Use C++11 for loop
Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
2014-03-03 10:34:13 +07:00

55 lines
1.4 KiB
C++

#include "../src/track_paths.h"
#include <io/path.h>
#include <text/format.h>
#include <test/jail.h>
static bool test_range (track_paths_t& tracker, std::vector<std::string> const& paths, size_t first, size_t last)
{
bool res = true;
for(size_t i = 0; i < first; ++i)
res = res && (tracker.is_changed(paths[i]) == false);
for(size_t i = first; i < last; ++i)
res = res && (tracker.is_changed(paths[i]) == true);
for(size_t i = last; i < paths.size(); ++i)
res = res && (tracker.is_changed(paths[i]) == false);
return res;
}
void test_track_file ()
{
// created → deleted
// created → updated
// created → created
// missing → created
// missing → missing
test::jail_t jail;
std::vector<std::string> paths;
for(size_t i = 0; i < 50; ++i)
paths.push_back(jail.path(text::format("%02zu.txt", i)));
for(size_t i = 0; i < 30; ++i)
path::set_content(paths[i], "");
track_paths_t tracker;
for(auto const& path : paths)
tracker.add(path);
usleep(100000);
OAK_ASSERT(test_range(tracker, paths, 50, 50));
for(size_t i = 0; i < 10; ++i)
unlink(paths[i].c_str());
usleep(100000);
OAK_ASSERT(test_range(tracker, paths, 0, 10));
for(size_t i = 10; i < 20; ++i)
path::set_content(paths[i], "");
usleep(100000);
OAK_ASSERT(test_range(tracker, paths, 10, 20));
for(size_t i = 30; i < 40; ++i)
path::set_content(paths[i], "");
usleep(100000);
OAK_ASSERT(test_range(tracker, paths, 30, 40));
}