// Copyright (c) 2014, Matthew Brennan Jones // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) module analysis.helpers; import std.string; import std.traits; import std.stdio; import std.d.ast; import analysis.run; S between(S)(S value, S before, S after) if (isSomeString!S) { return value.after(before).before(after); } S before(S)(S value, S separator) if (isSomeString!S) { auto i = indexOf(value, separator); if (i == -1) return value; return value[0 .. i]; } S after(S)(S value, S separator) if (isSomeString!S) { auto i = indexOf(value, separator); if (i == -1) return ""; size_t start = i + separator.length; return value[start .. $]; } /** * This assert function will analyze the passed in code, get the warnings, * and make sure they match the warnings in the comments. Warnings are * marked like so: // [warn]: Failed to do somethings. */ void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, string file=__FILE__, size_t line=__LINE__) { import analysis.run; // Run the code and get any warnings string[] rawWarnings = analyze("test", cast(ubyte[]) code, analyzers); string[] codeLines = code.split("\n"); // Get the warnings ordered by line string[size_t] warnings; for (size_t i=0; i