Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@
*.i*86
*.x86_64
*.hex

# DUB
.dub
inifiled-test-library
test/filenameTmp.ini
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ language: d
sudo: false

d:
- dmd-nightly
- dmd-beta
- dmd
- ldc-beta
- ldc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw Travis crons are highly useful: https://blog.travis-ci.com/2016-12-06-the-crons-are-here

- dmd-2.069.0
- dmd-2.070.2
- dmd-2.071.2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis complains about older platforms:

inifiled 1.0.1+commit.3.gda4fa76: building configuration "inifiled-test-library"...
source/inifiled.d-mixin-253(255,1): Warning: switch case fallthrough - use 'goto default;' if intended
source/inifiled.d-mixin-253(255,1): Warning: switch case fallthrough - use 'goto case;' if intended
source/inifiled.d-mixin-253(256,1): Warning: switch case fallthrough - use 'goto default;' if intended
source/inifiled.d-mixin-253(255,1): Warning: switch case fallthrough - use 'goto default;' if intended
dmd failed with exit code 1.

Looks like a compiler error that has been fixed in 2.072 - is there any legitimate interest in supporting outdated releases? For the build scripts at dlang 2.072.2 is mostly used as "stable" DMD ...

- dmd-2.072.2
- dmd-2.073.2
- dmd-2.074.0
- ldc-1.0.0
- ldc-1.1.1
- dmd-2.074.1

script:
- dub test
Expand Down
54 changes: 47 additions & 7 deletions source/inifiled.d
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ unittest {
string buildSectionParse(T)() @safe {
import std.traits : hasUDA, fullyQualifiedName, isBasicType, isSomeString,
isArray;
import std.array : join;
import std.format : format;
string ret = "switch(getSection(line)) { // " ~ fullyQualifiedName!T ~ "\n";
string[] ret;

foreach(it; __traits(allMembers, T)) {
if(hasUDA!(__traits(getMember, T, it), INI)
Expand All @@ -183,14 +184,20 @@ string buildSectionParse(T)() @safe {
&& !isArray!(typeof(__traits(getMember, T, it))))
{
ret ~= ("case \"%s\": { line = readINIFileImpl" ~
"(t.%s, input, deaph+1); goto repeatL; }\n").
"(t.%s, input, deaph+1); } ").
format(fullyQualifiedName!(typeof(__traits(getMember, T, it))),
it
);
}
}

return ret ~ "default: return line;\n}\n";
// Avoid DMD switch fallthrough warnings
if (ret.length) {
return "switch(getSection(line)) { // " ~ fullyQualifiedName!T ~ "\n" ~
ret.join("goto case; \n") ~ "goto default;\n default: return line;\n}\n";
} else {
return "return line;";
}
}

string buildValueParse(T)() @safe {
Expand Down Expand Up @@ -234,7 +241,6 @@ string readINIFileImpl(T,IRange)(ref T t, ref IRange input, int deaph = 0)
line = input.front().idup;
input.popFront();

repeatL:
if(line.startsWith(";")) {
continue;
}
Expand Down Expand Up @@ -511,12 +517,12 @@ unittest {
p.dog.kg = 3.14;

Person p2;
readINIFile(p2, "filename.ini");
readINIFile(p2, "test/filename.ini");
writefln("\n%s\n", p2);
writeINIFile(p2, "filenameTmp.ini");
writeINIFile(p2, "test/filenameTmp.ini");

Person p3;
readINIFile(p3, "filenameTmp.ini");
readINIFile(p3, "test/filenameTmp.ini");

if(p2 != p3) {
writefln("\n%s\n%s", p2, p3);
Expand All @@ -537,3 +543,37 @@ unittest {
assert(false);
}
}

version(unittest) {
enum Check : string { disabled = "disabled"}

@INI
struct StaticAnalysisConfig {
@INI
string style_check = Check.disabled;

@INI
ModuleFilters filters;
}

private template ModuleFiltersMixin(A) {
const string ModuleFiltersMixin = () {
string s;
foreach (mem; __traits(allMembers, StaticAnalysisConfig))
static if (is(typeof(__traits(getMember, StaticAnalysisConfig, mem)) == string))
s ~= `@INI string[] ` ~ mem ~ ";\n";

return s;
}();
}

@INI
struct ModuleFilters { mixin(ModuleFiltersMixin!int); }
}

unittest {
StaticAnalysisConfig config;
readINIFile(config, "test/dscanner.ini");
assert(config.style_check == "disabled");
assert(config.filters.style_check == ["+std.algorithm"]);
}
4 changes: 4 additions & 0 deletions test/dscanner.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[inifiled.StaticAnalysisConfig]
style_check="disabled"
[inifiled.ModuleFilters]
style_check = "+std.algorithm"
File renamed without changes.